Beispiel #1
0
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
Beispiel #2
0
 def test_set_due_date(self):
     dts = {
         "2018-09-11": "%Y-%m-%d",
         "20180911": "%Y%m%d",
         "21-06-2018": "%d-%m-%Y",
         "2018/12/12": "%Y/%m/%d",
         "12/12/2018": "%d/%m/%Y",
     }
     i = Invoice()
     for date, fmt in dts.items():
         i.due_date = date
         assert i.due_date.strftime(fmt) == date
 def test_imports_invoice2_xml(self, xml_path_invoice2):
     invoice = Invoice.from_xml(xml_path_invoice2)
     assert invoice.invoice_id == '1'
     assert invoice.issue_date.strftime("%Y-%m-%d") == "2018-06-11"
     assert invoice.due_date.strftime("%Y-%m-%d") == "2018-09-11"
     # Seller and buyer
     assert invoice.seller_party.is_valid()
     assert invoice.buyer_party.is_valid()
     # totals
     assert str(invoice.line_extension_amount) == '60.00'
     assert str(invoice.tax_exclusive_amount) == '50.00'
     assert str(invoice.tax_inclusive_amount) == '60.50'
     assert str(invoice.payable_amount) == '60.50'
     # discount and charge
     assert str(invoice.charge_amount) == '10.00'
     assert str(invoice.discount_amount) == '20.00'
     # Check imported lines by computing the values of
     # totals from lines and charges and discounts and
     # comparing them to those from the XML.
     assert invoice.tax_exclusive_amount == invoice.subtotal()
     assert invoice.tax_inclusive_amount == invoice.total()
     assert invoice.payable_amount == invoice.total()
     # Check that we stored the original xml
     with open(xml_path_invoice2, 'rb') as fh:
         assert invoice.to_xml().encode('utf8') == fh.read()
Beispiel #4
0
 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()
Beispiel #5
0
 def test_wrong_due_date(self):
     with pytest.raises(ValueError):
         i = Invoice()
         i.due_date = "asdef"
     with pytest.raises(ValueError):
         i = Invoice()
         i.due_date = 123
Beispiel #6
0
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
Beispiel #7
0
 def test_invalid_payment_code(self):
     with pytest.raises(ValueError):
         i = Invoice()
         i.payment_means_code = "asdef"
Beispiel #8
0
 def test_invalid_currency(self):
     with pytest.raises(KeyError):
         i = Invoice()
         i.currency = "asdef"
Beispiel #9
0
 def test_set_dates_datetime(self):
     i = Invoice()
     i.issue_date = datetime(2018, 7, 10)
     assert i.issue_date == datetime(2018, 7, 10)
     i.due_date = datetime(2018, 9, 10)
     assert i.due_date == datetime(2018, 9, 10)
Beispiel #10
0
 def test_set_dates_none(self):
     i = Invoice()
     i.issue_date = None
     assert i.issue_date is None
     i.due_date = None
     assert i.due_date is None
Beispiel #11
0
 def test_id_number(self):
     i = Invoice(invoice_id="1-2018")
     assert i.invoice_id == "1-2018"
Beispiel #12
0
 def test_default_id_number(self):
     i = Invoice()
     assert i.invoice_id == '1'
Beispiel #13
0
 def test_payment_code(self):
     i = Invoice()
     i.payment_means_code = "10"
     assert i.payment_means_code == "10"