def invoice2(): invoice = Invoice() seller = Entity(name="Acme Inc.", tax_scheme="VAT", tax_scheme_id="ES34626691F", country="ES", party_legal_entity_id="ES34626691F", registration_name="Acme INc.", mail="*****@*****.**", endpoint="ES76281415Y", endpoint_scheme="ES:VAT", address="easy street", postalzone="08080", city="Barcelona") buyer = Entity(name="Corp Inc.", tax_scheme="VAT", tax_scheme_id="ES76281415Y", country="ES", party_legal_entity_id="ES76281415Y", registration_name="Corp INc.", mail="*****@*****.**", endpoint="ES76281415Y", endpoint_scheme="ES:VAT", address="busy street", postalzone="08080", city="Barcelona") invoice.buyer_party = buyer invoice.seller_party = seller invoice.due_date = "2018-09-11" invoice.issue_date = "2018-06-11" # lines il1 = InvoiceLine(quantity=5, unit_code="EA", price=2, item_name='test 1', currency="EUR", tax_percent=0.21, tax_category="S") il2 = InvoiceLine(quantity=2, unit_code="EA", price=25, item_name='test 2', currency="EUR", tax_percent=0.21, tax_category="S") invoice.add_lines_from([il1, il2]) # discount and charge invoice.charge = 10 invoice.discount = 20 return invoice
def test_wrong_buyer_entity(self): with pytest.raises(TypeError): i = Invoice() i.buyer_party = 123 with pytest.raises(ValueError): i = Invoice() i.buyer_party = Entity()
def get_entity(root, kind='seller'): """Gets an Entity of an Invoice """ if kind == 'seller': keys = { 'party_legal_entity_id': 'seller_party_legal_entity_id', 'name': 'seller_name', 'registration_name': 'seller_registration_name', 'tax_scheme_id': 'seller_taxcode', 'tax_scheme': 'seller_tax_scheme', 'endpoint_scheme': 'seller_endpoint_scheme', 'endpoint': 'seller_endpoint', 'country': 'seller_countrycode', 'address': 'seller_address', 'city': 'seller_city', 'postalzone': 'seller_postalzone', 'mail': 'seller_email', } else: keys = { 'party_legal_entity_id': 'buyer_party_legal_entity_id', 'name': 'buyer_name', 'registration_name': 'buyer_registration_name', 'tax_scheme_id': 'buyer_taxcode', 'tax_scheme': 'buyer_tax_scheme', 'endpoint_scheme': 'buyer_endpoint_scheme', 'endpoint': 'buyer_endpoint_scheme', 'country': 'buyer_countrycode', 'address': 'buyer_address', 'city': 'buyer_city', 'postalzone': 'buyer_postalzone', 'mail': 'buyer_email', } args = {key: get_from_xpath(root, value) for key, value in keys.items()} return Entity(**args)
def test_initialization(self): e = Entity(name="Acme Inc.", tax_scheme="VAT", tax_scheme_id="ES34626691F", country="ES", party_legal_entity_id="ES34626691F", registration_name="Acme INc.", mail="*****@*****.**", endpoint="ES76281415Y", endpoint_scheme="ES:VAT", address="easy street", postalzone="08080", city="Barcelona") assert e.is_valid() assert e.tax_scheme == "VAT" assert e.tax_scheme_id == "ES34626691F" assert e.endpoint == "ES76281415Y" assert e.registration_name == "Acme INc."
def test_bank_info(self): seller = Entity(name="Acme Inc.", tax_scheme="VAT", tax_scheme_id="ES34626691F", country="ES", party_legal_entity_id="ES34626691F", registration_name="Acme INc.", mail="*****@*****.**", endpoint="ES76281415Y", endpoint_scheme="ES:VAT", address="easy street", postalzone="08080", city="Barcelona") bank_info_seller = BankInfo(iban="ES661234563156", bic="AAAABBCCDDD") seller.bank_info = bank_info_seller assert seller.is_valid() assert seller.bank_info.iban == "ES661234563156" assert seller.bank_info.bic == "AAAABBCCDDD"
def invoice3(): invoice = Invoice() seller = Entity(name="Acme Inc.", tax_scheme="VAT", tax_scheme_id="ES34626691F", country="ES", party_legal_entity_id="ES34626691F", registration_name="Acme INc.", mail="*****@*****.**", endpoint="ES76281415Y", endpoint_scheme="ES:VAT", address="easy street", postalzone="08080", city="Barcelona") bank_info_seller = BankInfo(iban="ES661234563156", bic="AAAABBCCDDD") seller.bank_info = bank_info_seller buyer = Entity(name="Corp Inc.", tax_scheme="VAT", tax_scheme_id="ES76281415Y", country="ES", party_legal_entity_id="ES76281415Y", registration_name="Corp INc.", mail="*****@*****.**", endpoint="ES76281415Y", endpoint_scheme="ES:VAT", address="busy street", postalzone="08080", city="Barcelona") bank_info_buyer = BankInfo(iban="ES661234567321", bic="AAAABBCCDDD", mandate_reference_identifier="123") buyer.bank_info = bank_info_buyer invoice.buyer_party = buyer invoice.seller_party = seller invoice.due_date = "2018-09-11" invoice.issue_date = "2018-06-11" invoice.payment_means_code = "31" # lines il1 = InvoiceLine(quantity=11, unit_code="EA", price=2, item_name='test 1', currency="EUR", tax_percent=0.21, tax_category="S") il2 = InvoiceLine(quantity=2, unit_code="EA", price=25, item_name='test 2', currency="EUR", tax_percent=0.21, tax_category="S") il3 = InvoiceLine(quantity=5, unit_code="EA", price=3, item_name='test 3', currency="EUR", tax_percent=0.1, tax_category="S") invoice.add_lines_from([il1, il2, il3]) return invoice
def test_wrong_bank_info(self): e = Entity() with pytest.raises(TypeError): e.bank_info = "asdf"
def test_invalid_bank_info(self): e = Entity() with pytest.raises(ValueError): e.bank_info = BankInfo()
def test_valid_entity(self): e = Entity() e.name = "Acme Inc." e.tax_scheme = "VAT" e.tax_scheme_id = "ES34626691F" e.country = "ES" e.party_legal_entity_id = "ES34626691F" e.registration_name = "Acme INc." e.endpoint = "ES76281415Y" e.endpoint_scheme = "ES:VAT" p = PostalAddress(address="easy street", city_name="Barcelona", postal_zone="08080", country="ES") e.postal_address = p assert e.is_valid() assert e.tax_scheme == "VAT" assert e.tax_scheme_id == "ES34626691F" assert e.endpoint == "ES76281415Y" assert e.registration_name == "Acme INc."
def test_invalid_entity(self): e = Entity(name="Asdf Inc.") assert not e.is_valid()
def test_not_apostal_address(self): e = Entity() with pytest.raises(TypeError): e.postal_address = "some address"
def test_unsuported_tax_scheme(self): e = Entity() with pytest.raises(ValueError): e.tax_scheme = "ASF"