def test_transaction1():
    tran = Transaction(1, 1, 1, 1200, 700, "12.12.2009", 13.30)
    assert tran.getTId() == 1
    assert tran.getIdCar() == 1
    assert tran.getIdCard() == 1
    assert tran.getSumaP() == 1200
    assert tran.getSumaM() == 700
    assert tran.getDate() == "12.12.2009"
    assert tran.getHour() == 13.30
Example #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)
Example #3
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)
Example #4
0
def add_transaction_test():
    repoTran = RepositoryTransaction("tranzactiiTests.txt")
    repoCar = RepositoryCar("masiniTests.txt")
    car_service = CarService(repoCar, "")
    tran_service = TransactionService(repoTran, car_service)
    assert len(repoTran.getAll()) == 0
    tran = Transaction(1, 1, 1, 1200, 700, "12.12.2010", 13.30)
    tran_service.add_transaction(tran.getTId(), tran.getIdCar(),
                                 tran.getIdCard(), tran.getSumaP(),
                                 tran.getSumaM(), tran.getDate(),
                                 tran.getHour())
    assert len(repoTran.getAll()) == 1
    repoTran.eraseFile()
Example #5
0
 def add(self, id_transaction, id_drug, id_card, no_pieces, date, time):
     drug = self.__repo_drug.read(int(id_drug))
     price = drug.get_price() * float(no_pieces)
     discount = 0
     if id_card != '':
         if not drug.get_prescription():
             discount = 10
         else:
             discount = 15
         price -= price / 100 * discount
     entity = Transaction(id_transaction, id_drug, id_card, no_pieces, date,
                          time, price)
     self.__repo.add(entity)
     return discount, price
Example #6
0
 def __readFileTransactions(self):
     transactionsList = []
     f = open(self.__fileTransactions, "r")
     lines = f.readlines()
     for line in lines:
         transactionString = line[:-1]  # deletes the last char from the string
         components = transactionString.split("|")
         ID = int(components[0])
         medID = components[1]
         cardID = components[2]
         amount = int(components[3])
         date = components[4]
         clock = components[5]
         deleteStatus = components[6]
         clientCard = Transaction(ID, medID, cardID, amount, date, clock, deleteStatus)
         transactionsList.append(clientCard)
     f.close()
     return transactionsList
    def __readFile(self):
        '''
        Citeste o lista de tranzactii dintr-un fisier.
        :return: lista de tranzactii
        '''
        f = open(self.__fileName, 'r')
        try:
            lines = f.readlines()
            for line in lines:
                str = line[:-1]
                comp = str.split("/")
                id = int(comp[0])
                idCar= int(comp[1])
                idCard= int(comp[2])
                sumaP= float(comp[3])
                sumaM= float(comp[4])
                date=comp[5]
                hour=float(comp[6])
                c = Transaction(id,idCar,idCard,sumaP,sumaM,date,hour)
                self.__tranList.append(c)
        except Exception as e:
            print("fisierul este gol")

        f.close()
Example #8
0
def test_show_transactions_data():
    repoTran = RepositoryTransaction("tranzactiiTests.txt")
    repoCar = RepositoryCar("masiniTests.txt")
    car_service = CarService(repoCar, "")
    tran_service = TransactionService(repoTran, car_service)
    tran1 = Transaction(1, 1, 1, 1200, 700, "09.03.2011", 13.30)
    tran_service.add_transaction(tran1.getTId(), tran1.getIdCar(),
                                 tran1.getIdCard(), tran1.getSumaP(),
                                 tran1.getSumaM(), tran1.getDate(),
                                 tran1.getHour())
    tran2 = Transaction(2, 2, 2, 2000, 1300, "12.12.2012", 13.30)
    tran_service.add_transaction(tran2.getTId(), tran2.getIdCar(),
                                 tran2.getIdCard(), tran2.getSumaP(),
                                 tran2.getSumaM(), tran2.getDate(),
                                 tran2.getHour())
    tran3 = Transaction(3, 3, 3, 800, 450, "12.12.2003", 13.30)
    tran_service.add_transaction(tran3.getTId(), tran3.getIdCar(),
                                 tran3.getIdCard(), tran3.getSumaP(),
                                 tran3.getSumaM(), tran3.getDate(),
                                 tran3.getHour())
    assert len(repoTran.getAll()) == 3
    l = tran_service.show_transaction_data("03.07.2010", "12.12.2013")

    assert len(repoTran.getAll()) == 1
    repoTran.eraseFile()
Example #9
0
def test_show_transactions():
    repoTran = RepositoryTransaction("tranzactiiTests.txt")
    repoCar = RepositoryCar("masiniTests.txt")
    car_service = CarService(repoCar, "")
    tran_service = TransactionService(repoTran, car_service)
    tran1 = Transaction(1, 1, 1, 1200, 700, "12.12.2010", 13.30)
    tran_service.add_transaction(tran1.getTId(), tran1.getIdCar(),
                                 tran1.getIdCard(), tran1.getSumaP(),
                                 tran1.getSumaM(), tran1.getDate(),
                                 tran1.getHour())
    tran2 = Transaction(2, 2, 2, 2000, 1300, "12.12.2010", 13.30)
    tran_service.add_transaction(tran2.getTId(), tran2.getIdCar(),
                                 tran2.getIdCard(), tran2.getSumaP(),
                                 tran2.getSumaM(), tran2.getDate(),
                                 tran2.getHour())
    tran3 = Transaction(3, 3, 3, 800, 450, "12.12.2010", 13.30)
    tran_service.add_transaction(tran3.getTId(), tran3.getIdCar(),
                                 tran3.getIdCard(), tran3.getSumaP(),
                                 tran3.getSumaM(), tran3.getDate(),
                                 tran3.getHour())
    assert len(repoTran.getAll()) == 3
    l = tran_service.show_tranzactions("sumaP", 600, 900)
    l1 = []
    l1.append(str(tran3))
    assert l[0] == str(l1)
    repoTran.eraseFile()
Example #10
0
def test_guarantee():
    repoTran = RepositoryTransaction("tranzactiiTests.txt")
    repoCar = RepositoryCar("masiniTests.txt")
    car_service = CarService(repoCar, "")
    tran_service = TransactionService(repoTran, car_service)
    tran1 = Transaction(1, 1, 1, 1200, 700, "12.12.2010", 13.30)
    tran_service.add_transaction(tran1.getTId(), tran1.getIdCar(),
                                 tran1.getIdCard(), tran1.getSumaP(),
                                 tran1.getSumaM(), tran1.getDate(),
                                 tran1.getHour())
    tran2 = Transaction(2, 2, 2, 2000, 1300, "12.12.2010", 13.30)
    tran_service.add_transaction(tran2.getTId(), tran2.getIdCar(),
                                 tran2.getIdCard(), tran2.getSumaP(),
                                 tran2.getSumaM(), tran2.getDate(),
                                 tran2.getHour())
    tran3 = Transaction(3, 3, 3, 800, 450, "12.12.2010", 13.30)
    tran_service.add_transaction(tran3.getTId(), tran3.getIdCar(),
                                 tran3.getIdCard(), tran3.getSumaP(),
                                 tran3.getSumaM(), tran3.getDate(),
                                 tran3.getHour())
    assert len(repoTran.getAll()) == 3
    car1 = Car(1, "Mercedes", 2019, 0, "da")
    car_service.add_car(car1.getCarId(), car1.getModel(), car1.getYear(),
                        car1.getNoKm(), car1.getGuarantee())
    car2 = Car(2, "Ford", 2008, 120000, "nu")
    car_service.add_car(car2.getCarId(), car2.getModel(), car2.getYear(),
                        car2.getNoKm(), car2.getGuarantee())
    car3 = Car(3, "bmw", 2018, 100000, "nu")
    car_service.add_car(car3.getCarId(), car3.getModel(), car3.getYear(),
                        car3.getNoKm(), car3.getGuarantee())
    assert len(repoCar.getAll()) == 3
    dict1 = tran_service.guarantee()
    dict = {}
    dict[1200] = 0
    assert dict1 == dict
    repoTran.eraseFile()
    repoCar.eraseFile()
Example #11
0
def test_reducere():
    repoTran = RepositoryTransaction("tranzactiiTests.txt")
    repoCar = RepositoryCar("masiniTests.txt")
    car_service = CarService(repoCar, "")
    tran_service = TransactionService(repoTran, car_service)
    tran1 = Transaction(1, 1, 1, 1200, 700, "12.12.2010", 13.30)
    tran_service.add_transaction(tran1.getTId(), tran1.getIdCar(),
                                 tran1.getIdCard(), tran1.getSumaP(),
                                 tran1.getSumaM(), tran1.getDate(),
                                 tran1.getHour())
    tran2 = Transaction(2, 2, 2, 2000, 1300, "12.12.2010", 13.30)
    tran_service.add_transaction(tran2.getTId(), tran2.getIdCar(),
                                 tran2.getIdCard(), tran2.getSumaP(),
                                 tran2.getSumaM(), tran2.getDate(),
                                 tran2.getHour())
    tran3 = Transaction(3, 3, 3, 800, 450, "12.12.2010", 13.30)
    tran_service.add_transaction(tran3.getTId(), tran3.getIdCar(),
                                 tran3.getIdCard(), tran3.getSumaP(),
                                 tran3.getSumaM(), tran3.getDate(),
                                 tran3.getHour())
    assert len(repoTran.getAll()) == 3
    dict1 = tran_service.reducere()

    dict = {}
    dict[700] = '70.0'
    dict[1300] = '130.0'
    dict[450] = '45.0'
    assert dict1 == dict
    repoTran.eraseFile()
Example #12
0
def test_order_car_desc():
    repoTran = RepositoryTransaction("tranzactiiTests.txt")
    repoCar = RepositoryCar("masiniTests.txt")
    car_service = CarService(repoCar, "")
    tran_service = TransactionService(repoTran, car_service)
    tran1 = Transaction(1, 1, 1, 1200, 700, "12.12.2010", 13.30)
    tran_service.add_transaction(tran1.getTId(), tran1.getIdCar(),
                                 tran1.getIdCard(), tran1.getSumaP(),
                                 tran1.getSumaM(), tran1.getDate(),
                                 tran1.getHour())
    tran2 = Transaction(2, 2, 2, 2000, 1300, "12.12.2010", 13.30)
    tran_service.add_transaction(tran2.getTId(), tran2.getIdCar(),
                                 tran2.getIdCard(), tran2.getSumaP(),
                                 tran2.getSumaM(), tran2.getDate(),
                                 tran2.getHour())
    tran3 = Transaction(3, 3, 3, 800, 450, "12.12.2010", 13.30)
    tran_service.add_transaction(tran3.getTId(), tran3.getIdCar(),
                                 tran3.getIdCard(), tran3.getSumaP(),
                                 tran3.getSumaM(), tran3.getDate(),
                                 tran3.getHour())
    assert len(repoTran.getAll()) == 3
    car1 = Car(1, "Mercedes", 2019, 0, "da")
    car_service.add_car(car1.getCarId(), car1.getModel(), car1.getYear(),
                        car1.getNoKm(), car1.getGuarantee())
    car2 = Car(2, "Ford", 2007, 120000, "da")
    car_service.add_car(car2.getCarId(), car2.getModel(), car2.getYear(),
                        car2.getNoKm(), car2.getGuarantee())
    car3 = Car(3, "bmw", 2001, 100000, "nu")
    car_service.add_car(car3.getCarId(), car3.getModel(), car3.getYear(),
                        car3.getNoKm(), car3.getGuarantee())
    assert len(repoCar.getAll()) == 3
    l = car_service.order_car_desc()
    l1 = [car1, car2, car3]
    string = str(l1[:])
    comp = string.split(",")
    assert l == l1
    print(l)
    repoTran.eraseFile()
    repoCar.eraseFile()
def test_transaction2():
    tran = Transaction(1, 1, 1, 1200, 700, "12.12.2009", 13.30)
    tran.setTId(2)
    assert tran.getTId() == 2
    tran.setIdCar(2)
    assert tran.getIdCar() == 2
    tran.setIdCard(2)
    assert tran.getIdCard() == 2
    tran.setSumaP(1300)
    assert tran.getSumaP() == 1300
    tran.setSumaM(800)
    assert tran.getSumaM() == 800
    tran.setDate("13.12.2009")
    assert tran.getDate() == "13.12.2009"
    tran.setHour(13.00)
    assert tran.getHour() == 13.00
 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])))
Example #15
0
def test_Transaction():
    t = Transaction(1, 2, 0, 2, "13.11.2019", "11:34", "True")
    assert t.getID() == 1
    assert t.getMedID() == 2
    assert t.getCardID() == 0
    assert t.getAmount() == 2
    assert t.getDate() == "13.11.2019"
    assert t.getClock() == "11:34"
    t1 = Transaction(1, 2, 0, 2, "13.11.2019", "11:34", "True")
    assert t1 == t
    t1.setMedID(3)
    assert t1 != t