Exemple #1
0
    def add_transaction(self, transaction_id, car_id, card_id, pieces_cost,
                        sum_man, date, hour, reduced_sum):
        """

        :param transaction_id:
        :param car_id:
        :param card_id:
        :param pieces_cost:
        :param sum_man:
        :param date:
        :param hour:
        :param reduced_sum:
        :return:
        """
        if car_id not in self.get_cars_id():
            raise InvalidIdException("There is no such car with that id")
        for card in self.__customer_card_repository.read():
            if card.id_entity() == card_id:
                reduced_sum += sum_man * 10 / 100
                sum_man = sum_man * 90 / 100
                break
        for cars in self.__car_repository.read():
            if cars.id_entity() == car_id and cars.get_guarantee():
                reduced_sum += pieces_cost
                pieces_cost = 0.0

        transaction = Transaction(transaction_id, car_id, card_id, pieces_cost,
                                  sum_man, date, hour, reduced_sum)
        self.__transaction_validator.validate_transaction(transaction)
        self.__transaction_repository.create(transaction)
Exemple #2
0
    def update_transaction(self, new_transaction_id, new_car_transacted_id,
                           new_customer_card_transaction_id, new_pieces_cost,
                           new_workmanship_cost, new_date, new_time,
                           reduced_sum):
        """

        :param new_transaction_id:
        :param new_car_transacted_id:
        :param new_customer_card_transaction_id:
        :param new_pieces_cost:
        :param new_workmanship_cost:
        :param new_date:
        :param new_time:
        :param reduced_sum:
        :return:
        """
        new_time = float(new_time)
        if new_car_transacted_id not in self.get_cars_id():
            raise InvalidIdException("There is no such car with that id")
        for card in self.__customer_card_repository.read():
            if card.id_entity() == new_customer_card_transaction_id:
                reduced_sum += new_workmanship_cost * 10 / 100
                new_workmanship_cost = new_workmanship_cost * 90 / 100
                break
        for cars in self.__car_repository.read():
            if cars.id_entity(
            ) == new_car_transacted_id and cars.get_guarantee():
                reduced_sum += new_pieces_cost
                new_pieces_cost = 0.0
        transaction = Transaction(new_transaction_id, new_car_transacted_id,
                                  new_customer_card_transaction_id,
                                  new_pieces_cost, new_workmanship_cost,
                                  new_date, new_time, reduced_sum)
        self.__transaction_validator.validate_transaction(transaction)
        self.__transaction_repository.update(transaction)
 def validate_transaction(transaction: Transaction):
     """
     Function verify if an object respects some conditions and if it finds an irregularity raise an exception
     :param transaction: an Transaction object
     :return: exceptions
     """
     if not isinstance(transaction.id_entity(), int):
         raise InvalidIdException("Transaction id = {} is not int".format(
             transaction.id_entity()))
     if not isinstance(transaction.get_id_car(), int):
         raise InvalidIdException("Car id = {} is not "
                                  "int".format(transaction.get_id_car()))
     if transaction.get_id_car() != '':
         if not isinstance(transaction.get_id_car(), int):
             raise InvalidIdException("Customer id = {} is not "
                                      "int".format(
                                          transaction.get_id_card()))
     if not isinstance(transaction.get_cost_parts(), float):
         raise InvalidTransactionException(
             "Pieces cost of car = {} is not"
             " int".format(transaction.get_cost_parts()))
     if not isinstance(transaction.get_cost_labor(), float):
         raise InvalidTransactionException(
             "Workmanship cost of car = {} is not"
             " int".format(transaction.get_cost_labor()))
     if not isinstance(transaction.get_time(), float):
         raise InvalidTransactionException("Time = {} is not float".format(
             transaction.get_time()))
     if "/" not in transaction.get_date():
         raise InvalidTransactionException("Please use / for writing date")
     if len("{}".format(transaction.get_date())) < 5:
         raise InvalidTransactionException("This is not a valid date")
     date = transaction.get_date().split(sep="/")
     if len(date) != 3:
         raise InvalidTransactionException("Use only 2 /")
     if int(date[0]) < 1 or int(date[0]) > 31:
         raise InvalidTransactionException(
             "Day {} must be between 1 and 31".format(int(date[0])))
     if int(date[1]) < 1 or int(date[1]) > 12:
         raise InvalidTransactionException(
             "Month {} must be between 1 and 12".format(int(date[1])))
     if int(date[2]) > 2019:
         raise InvalidTransactionException(
             "Year {} cannot be in the future".format(int(date[2])))
Exemple #4
0
 def delete(self, id_entity):
     """
     Deletes a entity.
     :param id_entity: the entity id to delete.
     :return: -
     :raises InvalidIdException: if no entity with id_entity
     """
     self.__load_from_file()
     if id_entity not in self.__storage:
         raise InvalidIdException('There is no entity with that id!')
     del self.__storage[id_entity]
     self.__save_to_file()
Exemple #5
0
 def update(self, entity):
     """
     Updates an entity.
     :param entity: the entity to update
     :return: -
     :raises: InvalidIdException if the id does not exist
     """
     self.__load_from_file()
     id_entity = entity.id_entity()
     if id_entity not in self.__storage:
         raise InvalidIdException('There is no entity with that id!')
     self.__storage[id_entity] = entity
     self.__save_to_file()
Exemple #6
0
 def create(self, entity):
     """
     Adds a new entity.
     :param entity: the given entity
     :return: -
     :raises: InvalidIdException if the id already exists
     """
     self.__load_from_file()
     id_entity = entity.id_entity()
     if id_entity in self.__storage:
         raise InvalidIdException('The entity id already exists!')
     self.__storage[id_entity] = entity
     self.__save_to_file()
Exemple #7
0
 def ensure_unique_cnp(self, customer_card):
     for card_key in self.__storage:
         if self.__storage[card_key].get_customer_cnp(
         ) == customer_card.get_customer_cnp():
             raise InvalidIdException("CNP already exist!")