Esempio n. 1
0
    def input_bill(self, bill_type):
        bill = None
        if bill_type == FiscalBill:
            bill = FiscalBill()
        if bill_type == Invoice:
            bill = Invoice()

        bill.set_customer(self.choose_customer(self.choose_customer_type()))
        company = Company()
        bill.set_issuer(self.choose_customer(company))
        bill.set_currency(self.choose_currency())
        bill.set_issue_date(input("Give issue date: "))
        bill.set_due_date(input("Give due date: "))
        bill.set_notes(input("Notes:"))
        return bill
Esempio n. 2
0
 def __load_from_file(self):
     index = "current_index"
     list_type = None
     if self._repo_type == Individual:
         index = "current_individual_id"
         list_type = "individual_list"
     if self._repo_type == Company:
         index = "current_company_id"
         list_type = "company_list"
     file = open(self.__file_name, "r")
     json_file = json.loads(file.read())
     if index in json_file:
         self._id = json_file[index]
     if list_type in json_file:
         for customer in json_file[list_type]:
             index = customer["id"]
             first_name = customer["first_name"]
             last_name = customer["last_name"]
             phone_number = customer["phone_number"]
             email_address = customer["email_address"]
             if self._repo_type == Individual:
                 cnp = customer["cnp"]
                 customer_to_add = Individual()
                 customer_to_add.set_cnp(cnp)
                 customer_to_add.set_id(index)
                 customer_to_add.set_first_name(first_name)
                 customer_to_add.set_last_name(last_name)
                 customer_to_add.set_phone_number(phone_number)
                 customer_to_add.set_email_address(email_address)
             if self._repo_type == Company:
                 company_name = customer["company_name"]
                 fiscal_no = customer["fiscal_no"]
                 registration_number = customer["registration_number"]
                 customer_to_add = Company()
                 customer_to_add.set_id(index)
                 customer_to_add.set_first_name(first_name)
                 customer_to_add.set_last_name(last_name)
                 customer_to_add.set_phone_number(phone_number)
                 customer_to_add.set_email_address(email_address)
                 customer_to_add.set_company_name(company_name)
                 customer_to_add.set_fiscal_no(fiscal_no)
                 customer_to_add.set_registration_number(registration_number)
             self._list.append(customer_to_add)
     file.close()
Esempio n. 3
0
    def test_validator(self):
        validator = Validator.get_instance()
        customer = Individual()
        customer.set_cnp("198121203415")
        customer.set_last_name("Dan")
        customer.set_first_name("Popescu")
        customer.set_phone_number("0756234876")
        customer.set_email_address("*****@*****.**")
        item = Item()
        currency = Currency("$", "dollar", "USD")
        item.set_name("Apple")
        item.set_price(2)
        item.set_discount(0)
        item.set_currency(currency)
        company = Company()
        company.set_company_name("La Gigi")
        company.set_fiscal_no("RO0123")
        company.set_registration_number("123456")
        company.set_email_address("*****@*****.**")
        company.set_first_name("Ion")
        company.set_last_name("Bogdan")
        company.set_phone_number("0752314567")
        company.set_fiscal_no("0000012345678")
        company.set_registration_number("RO01923")
        bill = Bill()
        bill.set_currency(currency)
        bill.set_customer(customer)
        bill.set_issuer(company)
        bill.set_issue_date("21.12.2020")
        bill.set_due_date("21.02.2021")
        bill.add_items(item)

        validator.validate_bill(bill)
Esempio n. 4
0
 def test_json_company(self):
     company_repo = JsonCustomerRepo("json_test.json", Company)
     company = Company()
     company.set_id(1)
     company.set_first_name("Ion")
     company.set_last_name("Radu")
     company.set_email_address("*****@*****.**")
     company.set_phone_number("0756456452")
     company.set_fiscal_no("0000123456789")
     company.set_company_name('MDFK')
     company.set_registration_number("RO01234")
     company_repo.store(company)
     self.assertEqual(company, company_repo.get(1))
     company.set_company_name("La 3 pasi")
     company_repo.update(1, company)
     company_repo2 = JsonCustomerRepo("json_test.json", Company)
     self.assertEqual(company_repo.get(1), company_repo2.get(1))
     company_repo.reset_id()
     company_repo.delete(1)
Esempio n. 5
0
 def test_invoice_bill(self):
     service = BillService(BillRepo(Invoice), BillRepo(FiscalBill))
     company = Company()
     company.set_company_name("La Geani")
     company.set_registration_number("RO0123")
     company.set_fiscal_no("0000231523647")
     company.set_email_address("*****@*****.**")
     company.set_first_name("Ion")
     company.set_last_name("Bogdan")
     company.set_phone_number("0752314567")
     company.set_fiscal_no("0000012345678")
     company.set_registration_number("RO01923")
     individual = Individual()
     individual.set_cnp("1971209075425")
     individual.set_id(1)
     individual.set_first_name("Petre")
     individual.set_last_name("Vasile")
     individual.set_phone_number("0745321784")
     individual.set_email_address("*****@*****.**")
     item = BillItem()
     currency = Currency("$", "Dollar", "USD")
     item.set_id(1)
     item.set_currency(currency)
     item.set_name("McChicken")
     item.set_description("Chicken hamburger")
     item.set_price(2)
     item.set_discount(0)
     item.set_quantity(1)
     invoice = Invoice()
     invoice.set_customer(individual)
     invoice.set_currency(currency)
     invoice.set_items([item])
     invoice.set_id(1)
     invoice.set_issuer(company)
     invoice.set_issue_date("24.01.2021")
     invoice.set_due_date("10.02.2021")
     invoice.set_notes("Platiti la Banca Transilvania")
     service.create_bill(invoice)
     invoice.add_items(item)
     service.update_bill(1, invoice)
     self.assertEqual(service.get_invoice(1), invoice)
     bill2 = service.invoice_to_fiscal(1)
     bill2.set_id(1)
     self.assertEqual(service.get_fiscal(1), bill2)
     service.delete_bill(invoice)
Esempio n. 6
0
 def test_company_customer(self):
     service = CustomerService(CustomerRepo(Individual),
                               CustomerRepo(Company))
     company = Company()
     company.set_company_name("La Geani")
     company.set_registration_number("RO0123")
     company.set_fiscal_no("0000231523647")
     company.set_first_name("Petre")
     company.set_last_name("Vasile")
     company.set_phone_number("0745321784")
     company.set_email_address("*****@*****.**")
     service.create_customer(company)
     self.assertEqual(service.get_company_customer(1), company)
     company.set_id(2)
     company.set_last_name("Miron")
     service.update_customer(1, company)
     self.assertEqual(service.get_company_customer(1), company)
     service.delete_customer(company)
     self.assertEqual(service.view_all_company(), [])
Esempio n. 7
0
 def test_service(self):
     service = Service("json_test.json", "json_test.json", "json_test.json",
                       "json_test.json")
     # Customer Options
     company = Company()
     address = Address()
     address.set_address("Strada Academiei nr. 7")
     address.set_county("Bucuresti")
     address.set_country("Romania")
     address.set_postal_code("010011")
     company.set_id(1)
     company.set_address(address)
     company.set_company_name("La Geani")
     company.set_registration_number("RO0123")
     company.set_fiscal_no("0000231523647")
     company.set_email_address("*****@*****.**")
     company.set_first_name("Ion")
     company.set_last_name("Bogdan")
     company.set_phone_number("0752314567")
     company.set_fiscal_no("0000012345678")
     company.set_registration_number("RO01923")
     service.create_customer(company)
     self.assertEqual(service.get_company_customer(1), company)
     company.set_company_name("Marketplex")
     service.modify_customer(1, company)
     self.assertEqual(service.get_company_customer(1), company)
     service.delete_customer(company)
     self.assertEqual(service.view_all_company_customer(), [])
     individual = Individual()
     individual.set_cnp("1971209075425")
     individual.set_id(1)
     individual.set_first_name("Petre")
     individual.set_last_name("Vasile")
     individual.set_phone_number("0745321784")
     individual.set_email_address("*****@*****.**")
     service.create_customer(individual)
     self.assertEqual(service.get_individual_customer(1), individual)
     individual.set_last_name("Gigel")
     service.modify_customer(1, individual)
     self.assertEqual(service.get_individual_customer(1), individual)
     service.delete_customer(individual)
     self.assertEqual(service.view_all_individual_customer(), [])
     individual.set_address(address)
     # Currency Options
     currency = Currency("$", "Dollar", "USD")
     currency.set_id(1)
     currency.set_exchange_rate(4.5)
     service.create_currency(currency)
     self.assertEqual(currency, service.get_currency(1))
     currency.set_exchange_rate(4.2)
     service.modify_currency(1, currency)
     self.assertEqual(currency, service.get_currency(1))
     service.delete_currency(1)
     self.assertEqual(service.view_currency(), [])
     # Item Options
     item = Item()
     item.set_id(1)
     item.set_currency(currency)
     item.set_name("McChicken")
     item.set_description("Chicken hamburger")
     item.set_price(2)
     item.set_discount(0)
     service.create_item(item)
     self.assertEqual(item, service.choose_item(1))
     item.set_price(3)
     service.modify_item(1, item)
     self.assertEqual(item, service.choose_item(1))
     service.delete_item(1)
     self.assertEqual(service.view_items(), [])
     # Bill Options
     bill_item = BillItem()
     bill_item.set_id(1)
     bill_item.set_currency(currency)
     bill_item.set_name("McChicken")
     bill_item.set_description("Chicken hamburger")
     bill_item.set_price(3)
     bill_item.set_discount(0)
     bill = Invoice()
     bill.set_customer(individual)
     bill.set_currency(currency)
     bill.set_items([bill_item])
     bill.set_id(1)
     bill.set_issuer(company)
     bill.set_issue_date("24.01.2021")
     bill.set_due_date("10.02.2021")
     bill.set_notes("Platiti la Banca Transilvania")
     service.create_item(item)
     service.create_bill(bill)
     self.assertEqual(service.get_invoice(1), bill)
     bill.set_notes("asdfge")
     service.modify_bill(1, bill)
     self.assertEqual(service.get_invoice(1), bill)
     service.add_item_to_bill(1, bill)
     bill.add_items(bill_item)
     self.assertEqual(service.get_invoice(1), bill)
     service.invoice_to_fiscal(1)
     fiscal_bill = FiscalBill()
     fiscal_bill.set_customer(individual)
     fiscal_bill.set_currency(currency)
     bill_item.set_quantity(2)
     fiscal_bill.set_total(3.0)
     fiscal_bill.set_items([bill_item])
     fiscal_bill.set_id(1)
     fiscal_bill.set_issuer(company)
     fiscal_bill.set_issue_date("24.01.2021")
     fiscal_bill.set_due_date("10.02.2021")
     fiscal_bill.set_notes("asdfge")
     self.assertEqual(fiscal_bill, service.get_fiscal(1))
     service.delete_bill(bill)
     file = open("json_test.json", "w")
     file.truncate(0)
     file.write("{}")
     file.close()
Esempio n. 8
0
 def test_add(self):
     c = Company()
     assert c.add(1,2) == c.add(2,1)
Esempio n. 9
0
    def __create_company(self, name, last_name, first_name, email_address,
                         phone_number, fiscal_no, registration_number):
        customer = Company()
        customer.set_company_name(name)
        customer.set_last_name(last_name)
        customer.set_first_name(first_name)
        customer.set_email_address(email_address)
        customer.set_phone_number(phone_number)
        customer.set_fiscal_no(fiscal_no)
        customer.set_registration_number(registration_number)

        return customer
 def test_company_repo(self):
     company = Company()
     company.set_company_name("La Gigi")
     company.set_fiscal_no("RO0123")
     company.set_registration_number("123456")
     company.set_id(1)
     company.set_first_name("Gigi")
     company.set_last_name("Petre")
     company.set_phone_number("0756234123")
     company.set_email_address("*****@*****.**")
     company_repo = CustomerRepo(Company)
     company_repo.store(company)
     self.assertEqual(company_repo.get(1), company)
     company.set_company_name("La Gigi Acasa")
     company_repo.update(1, company)
     self.assertEqual(company_repo.get(1), company)
     company_repo.delete(company.get_id())
     self.assertEqual(company_repo.get_all(), [])
Esempio n. 11
0
    def test_bill_repo(self):
        invoice_repo = BillRepo(Invoice)

        invoice = Invoice()
        address = Address()
        address.set_address("Strada Academiei nr. 7")
        address.set_county("Bucuresti")
        address.set_country("Romania")
        address.set_postal_code("010011")
        customer = Customer("Ion", "Radu", "*****@*****.**",
                            "0758245170", address)
        company = Company()
        company.set_address(address)
        company.set_first_name("Plesoiu")
        company.set_last_name("Alexandru")
        company.set_fiscal_no("RO0123")
        company.set_registration_number("123456")
        company.set_company_name("Pleso Academy")
        company.set_fiscal_no("RO2345")
        company.set_registration_number("0000123456789")
        item = BillItem()
        currency = Currency("LEU", "Leu", "RON")
        item.set_name("Water")
        item.set_currency(currency)
        item.set_price(2)
        item.set_discount(0)
        item.set_description("Drinkabale liquid")
        item.set_id(1)
        customer.set_id(1)
        invoice.set_currency(currency)
        invoice.set_items([item])
        invoice.set_total(2)
        invoice.set_issuer(company)
        invoice.set_id(1)
        invoice.set_issue_date("12.12.2020")
        invoice.set_due_date("16.12.2020")
        invoice.set_customer(customer)
        invoice_repo.store(invoice)
        self.assertEqual(invoice_repo.get(1), invoice)
        item.set_quantity(2)
        invoice.set_items([item])
        invoice.set_total(4)
        invoice_repo.update(1, invoice)
        self.assertEqual(invoice_repo.get(1), invoice)
        invoice_repo.delete(1)
        self.assertEqual(invoice_repo.get_all(), [])
        self.assertEqual(invoice_repo.get(69), None)
        try:
            repo = BillRepo("asdas")
            self.assertFalse(True)
        except Exception as exp:
            self.assertFalse(False)

        with self.assertRaises(TypeError):
            invoice_repo.update(1, 1)

        with self.assertRaises(TypeError):
            invoice_repo.store(1)
Esempio n. 12
0
 def test_company_getters(self):
     company = Company()
     company.set_company_name("La Rica")
     company.set_fiscal_no("RO0123")
     company.set_registration_number("123456")
     self.assertEqual(company.get_company_name(), "La Rica")
     self.assertEqual(company.get_registration_number(), "123456")
     self.assertEqual(company.get_fiscal_no(), "RO0123")
Esempio n. 13
0
 def test_company_setters(self):
     company = Company()
     company.set_company_name("La Rica")
     company.set_fiscal_no("RO0123")
     company.set_registration_number("123456")
     company.set_company_name("Pleso Academy")
     company.set_fiscal_no("RO2345")
     company.set_registration_number("0000123456789")
     self.assertEqual(company.get_company_name(), "Pleso Academy")
     self.assertEqual(company.get_registration_number(), "0000123456789")
     self.assertEqual(company.get_fiscal_no(), "RO2345")
Esempio n. 14
0
 def test_equal(self):
     company = Company()
     company.set_company_name("La Geani")
     company.set_registration_number("RO0123")
     company.set_fiscal_no("0000231523647")
     company.set_email_address("*****@*****.**")
     company.set_first_name("Ion")
     company.set_last_name("Bogdan")
     company.set_phone_number("0752314567")
     company.set_fiscal_no("0000012345678")
     company.set_registration_number("RO01923")
     individual = Individual()
     individual.set_cnp("1971209075425")
     individual.set_id(1)
     individual.set_first_name("Petre")
     individual.set_last_name("Vasile")
     individual.set_phone_number("0745321784")
     individual.set_email_address("*****@*****.**")
     item = BillItem()
     currency = Currency("$", "Dollar", "USD")
     item.set_id(1)
     item.set_currency(currency)
     item.set_name("McChicken")
     item.set_description("Chicken hamburger")
     item.set_price(2)
     item.set_discount(0)
     bill = Bill()
     bill.set_customer(individual)
     bill.set_currency(currency)
     bill.set_items([item])
     bill.set_id(1)
     bill.set_total(item.get_price())
     bill.set_issuer(company)
     bill.set_issue_date("24.01.2021")
     bill.set_due_date("10.02.2021")
     bill.set_notes("Platiti la Banca Transilvania")
     bill2 = copy.deepcopy(bill)
     bill2.set_id(2)
     self.assertNotEqual(bill, bill2)
     bill2.set_id(bill.get_id())
     currency2 = copy.deepcopy(currency)
     currency2.set_name("dollar")
     bill2.set_currency(currency2)
     self.assertNotEqual(bill, bill2)
     bill2.set_currency(bill.get_currency())
     bill2.set_total(12.0)
     self.assertNotEqual(bill, bill2)
     bill2.set_total(bill.get_total())
     bill2.set_notes("asdfg")
     self.assertNotEqual(bill, bill2)
     bill2.set_notes(bill.get_notes())
     bill2.set_items([item, item])
     self.assertNotEqual(bill, bill2)
     bill2.set_items(bill.get_items())
     individual2 = copy.deepcopy(individual)
     individual2.set_cnp("1991212123456")
     bill2.set_customer(individual2)
     self.assertNotEqual(bill, bill2)
     bill2.set_customer(bill.get_customer())
     company2 = copy.deepcopy(company)
     company2.set_last_name("Marcel")
     bill2.set_issuer(company2)
     self.assertNotEqual(bill, bill2)
     bill2.set_issuer(bill.get_issuer())
     bill2.set_due_date("adsf")
     self.assertNotEqual(bill, bill2)
     bill2.set_due_date(bill.get_due_date())
     bill2.set_issue_date("asdf")
     self.assertNotEqual(bill, bill2)
Esempio n. 15
0
 def test_bill_getters_and_setters(self):
     company = Company()
     company.set_company_name("La Geani")
     company.set_registration_number("RO0123")
     company.set_fiscal_no("0000231523647")
     company.set_email_address("*****@*****.**")
     company.set_first_name("Ion")
     company.set_last_name("Bogdan")
     company.set_phone_number("0752314567")
     company.set_fiscal_no("0000012345678")
     company.set_registration_number("RO01923")
     individual = Individual()
     individual.set_cnp("1971209075425")
     individual.set_id(1)
     individual.set_first_name("Petre")
     individual.set_last_name("Vasile")
     individual.set_phone_number("0745321784")
     individual.set_email_address("*****@*****.**")
     item = BillItem()
     currency = Currency("$", "Dollar", "USD")
     item.set_id(1)
     item.set_currency(currency)
     item.set_name("McChicken")
     item.set_description("Chicken hamburger")
     item.set_price(2)
     item.set_discount(0)
     bill = Bill()
     bill.set_customer(individual)
     bill.set_currency(currency)
     bill.set_items([item])
     bill.set_id(1)
     bill.set_total(item.get_price())
     bill.set_issuer(company)
     bill.set_issue_date("24.01.2021")
     bill.set_due_date("10.02.2021")
     bill.set_notes("Platiti la Banca Transilvania")
     self.assertEqual(bill.get_currency(), currency)
     self.assertEqual(bill.get_total(), 2)
     self.assertEqual(bill.get_issuer(), company)
     self.assertEqual(bill.get_items(), [item])
     self.assertEqual(bill.get_notes(), "Platiti la Banca Transilvania")
     self.assertEqual(bill.get_issue_date(), "24.01.2021")
     self.assertEqual(bill.get_due_date(), "10.02.2021")
     self.assertEqual(bill.get_customer(), individual)
     bill.add_items(item)
     self.assertEqual(bill.get_items(), [item])
Esempio n. 16
0
 def create_company(self):
     company = Company()
     company.set_first_name(input("First Name: "))
     company.set_last_name(input("Last Name: "))
     company.set_phone_number(input("Phone Number: "))
     company.set_email_address(input("Email Address: "))
     company.set_company_name(input("Company Name: "))
     company.set_fiscal_no(input("Fiscal Number: "))
     company.set_registration_number(input("Registration Number: "))
     address = input("Give address: ")
     county = input("Give county: ")
     postal_code = input("Give postal code: ")
     country = input("Give country: ")
     customer_address = Address()
     customer_address.set_address(address)
     customer_address.set_county(county)
     customer_address.set_country(country)
     customer_address.set_postal_code(postal_code)
     company.set_address(customer_address)
     return company