Skip to main content

A Python 3 package to parse, generate and manage the EN16931 Invoice format

Project description

https://travis-ci.org/invinet/python-en16931.svg?branch=master https://codecov.io/gh/invinet/python-en16931/branch/master/graph/badge.svg

Python 3 package to read, write and manage the new EN16931 Invoice format.

This European Standard establishes a semantic data model of the core elements of an electronic invoice. The semantic model includes only the essential information elements that an electronic invoice needs to ensure legal (including fiscal) compliance and to enable interoperability for cross-border, cross sector and for domestic trade.

Features

This library allows you to:

  1. De-serialize an XML in EN16931 format to a python Invoice object.

  2. Serialize a python Invoice object to a valid XML representation.

  3. Validate an Invoice using validex.

  4. Import an Invoice to B2BRouter.

Installation

You can use pip to install this package:

$ pip install en16931

Usage

You can import an invoice from an XML file:

>>> from en16931 import Invoice
>>> invoice = Invoice.from_xml('en16931/tests/files/invoice.xml')

And use the API to access its internal values and entities:

>>> invoice.issue_date
datetime.datetime(2018, 6, 11, 0, 0)
>>> invoice.seller_party
<en16931.entity.Entity at 0x7f2b7c12b860>
>>> invoice.buyer_party
<en16931.entity.Entity at 0x7f2b7c0fd160>
>>> invoice.unique_taxes
{ Tax S: 0.21  , Tax S: 0.1  }
>>> invoice.lines
[<en16931.invoice_line.InvoiceLine at 0x7f2b7c0fd400>,
 <en16931.invoice_line.InvoiceLine at 0x7f2b7c0fd518>,
 <en16931.invoice_line.InvoiceLine at 0x7f2b7c0fd748>]
>>> invoice.tax_exclusive_amount
87.00
>>> invoice.tax_amount()
16.62
>>> invoice.tax_inclusive_amount
103.62
>>> invoice.payable_amount
103.62

If you import an XML file, all relevant quantities are not computed; we use the ones defined on the XML. You can check that the computed and imported quantities match by calling the relevant methods:

>>> assert invoice.tax_exclusive_amount == invoice.subtotal()
True
>>> assert invoice.tax_inclusive_amount == invoice.total()
True
>>> assert invoice.payable_amount == invoice.total()
True

Or you can also build, step by step, an invoice:

>>> from en16931 import Invoice
>>> invoice = Invoice(invoice_id="2018-01", currency="EUR")
>>> seller = Entity(name="Acme Inc.", tax_scheme="VAT",
...                 tax_scheme_id="ES34626691F", country="ES",
...                 party_legal_entity_id="ES34626691F",
...                 registration_name="Acme INc.", mail="acme@acme.io",
...                 endpoint="ES76281415Y", endpoint_scheme="ES:VAT",
...                 address="easy street", postalzone="08080",
...                 city="Barcelona", province="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="corp@corp.io",
...                endpoint="ES76281415Y", endpoint_scheme="ES:VAT",
...                address="busy street", postalzone="08080",
...                city="Barcelona", province="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=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])

And serialize it to XML:

>>> # As a string
>>> xml = invoice.to_xml()
>>> # Or save it directly to a file
>>> invoice.save('example_invoice.xml')

Limitations

This is a proof of concept implementation and not all features defined in the EN16931 standard are implemented. But it is easy, in some cases trivial, to implement them. The main not implemented features are:

  • CreditNotes are not supported.

  • File attachments are not supported.

  • Delivery information is not supported.

  • Only global charges and discounts are supported. Line discounts and charges are not supported.

  • Other potentially useful attributes (such as InvoicePeriod, BuyerReference, OrderReference, BillingReference, ContractDocumentReference, among others) are not implemented.

If you need a particular feature implemented, see the following section for feature requests.

Bugs and Feature Requests

Please report any bugs that you find here. Or, even better, fork the repository on GitHub and create a pull request (PR). We welcome all changes, big or small.

License

Released under the Apache License Version 2.0 (see LICENSE.txt):

Copyright (C) 2018 Invinet Sistemes

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

en16931-0.1.1.tar.gz (26.5 kB view details)

Uploaded Source

Built Distribution

en16931-0.1.1-py3-none-any.whl (31.2 kB view details)

Uploaded Python 3

File details

Details for the file en16931-0.1.1.tar.gz.

File metadata

  • Download URL: en16931-0.1.1.tar.gz
  • Upload date:
  • Size: 26.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.12

File hashes

Hashes for en16931-0.1.1.tar.gz
Algorithm Hash digest
SHA256 8fa2699c49daef5f77fa75e01b7caf991b0f90d98d76cf509622a84458a6e166
MD5 f57af0043fb65ff89d9174c43b59fab9
BLAKE2b-256 1e817dc096305ab5c85814cb01cb6ef2552311b20762bf9443a55b170075a65c

See more details on using hashes here.

File details

Details for the file en16931-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: en16931-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 31.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.12

File hashes

Hashes for en16931-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4a7ee2a9592f8d225c1c503707e6b59ada999b4ccb8379ba3a922afa7910a9b8
MD5 008f22b60a85cfdaff67779c9fb074bd
BLAKE2b-256 b001c6722410aae31ddd0eb6b6661460e247fc54e88272a2ed86e147aacebff2

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page