Ejemplo n.º 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
Ejemplo n.º 2
0
 def test_initialization(self):
     il = InvoiceLine(quantity=11,
                      unit_code="EA",
                      price=2,
                      item_name='test',
                      currency="EUR",
                      tax_percent=0.21,
                      tax_category="S")
     assert il.is_valid()
     assert il.currency == "EUR"
Ejemplo n.º 3
0
 def test_creation(self):
     il = InvoiceLine()
     il.quantity = 11
     il.price = 2
     il.item_name = 'test'
     il.tax_percent = 0.21
     il.tax_category = "S"
     assert il.is_valid()
Ejemplo n.º 4
0
 def test_line_extension_amount(self):
     il = InvoiceLine(quantity=11,
                      unit_code="EA",
                      price=2,
                      item_name='test',
                      currency="EUR",
                      tax_percent=0.21,
                      tax_category="S")
     assert str(il.line_extension_amount) == '22.00'
Ejemplo n.º 5
0
def get_invoice_lines(root, namespaces=None):
    """Generator of InvoiceLines of an Invoice
    """
    if namespaces is None:
        namespaces = get_namespaces()
    keys = {
        'quantity': 'line_quantity',
        'unit_code': 'line_unit',
        'line_extension_amount': 'line_extension_amount',
        'item_name': 'line_item_name',
        'price': 'line_price',
        'currency': 'line_currency',
        'tax_percent': 'line_tax_percent',
        'tax_category': 'line_tax_category',
    }
    lines = root.findall('cac:InvoiceLine', namespaces=namespaces)
    for line in lines:
        args = {
            key: get_from_xpath(line, value)
            for key, value in keys.items()
        }
        yield InvoiceLine(**args)
Ejemplo n.º 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
Ejemplo n.º 7
0
 def test_invalid_quantity(self):
     il = InvoiceLine()
     with pytest.raises(ValueError):
         il.quantity = "dasdas"
Ejemplo n.º 8
0
 def test_invalid_line_extension_amount(self):
     il = InvoiceLine()
     with pytest.raises(ValueError):
         il.line_extension_amount = "expensive"
Ejemplo n.º 9
0
 def test_invalid_price(self):
     il = InvoiceLine()
     with pytest.raises(ValueError):
         il.price = "dasdas"
Ejemplo n.º 10
0
 def test_invalid_unit_code(self):
     il = InvoiceLine()
     with pytest.raises(ValueError):
         il.unit_code = "ASF"
Ejemplo n.º 11
0
 def test_no_taxes(self):
     il = InvoiceLine()
     assert il.tax is None
Ejemplo n.º 12
0
 def test_invalid_currency(self):
     il = InvoiceLine()
     with pytest.raises(KeyError):
         il.currency = "blah"