用于解析、生成和管理EN16931发票格式的Python3包
en16931的Python项目详细描述
python 3包,用于读取、写入和管理新的EN16931 Invoice format。
这个European Standard建立了电子发票核心元素的语义数据模型。语义模型仅包括电子发票所需的基本信息元素,以确保法律(包括财政)合规性,并实现跨境、跨部门和国内贸易的互操作性。
用法
您可以从XML文件导入发票:
>>>fromen16931importInvoice>>>invoice=Invoice.from_xml('en16931/tests/files/invoice.xml')
并使用api访问其内部值和实体:
>>>invoice.issue_datedatetime.datetime(2018,6,11,0,0)>>>invoice.seller_party<en16931.entity.Entityat0x7f2b7c12b860>>>>invoice.buyer_party<en16931.entity.Entityat0x7f2b7c0fd160>>>>invoice.unique_taxes{TaxS:0.21,TaxS:0.1}>>>invoice.lines[<en16931.invoice_line.InvoiceLineat0x7f2b7c0fd400>,<en16931.invoice_line.InvoiceLineat0x7f2b7c0fd518>,<en16931.invoice_line.InvoiceLineat0x7f2b7c0fd748>]>>>invoice.tax_exclusive_amount87.00>>>invoice.tax_amount()16.62>>>invoice.tax_inclusive_amount103.62>>>invoice.payable_amount103.62
如果导入XML文件,则不计算所有相关数量;我们 使用xml上定义的那些。你可以检查 通过调用相关方法来匹配导入的数量:
>>>assertinvoice.tax_exclusive_amount==invoice.subtotal()True>>>assertinvoice.tax_inclusive_amount==invoice.total()True>>>assertinvoice.payable_amount==invoice.total()True
或者您也可以一步一步地创建发票:
>>>fromen16931importInvoice>>>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")>>>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")>>>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])
并将其序列化为xml:
>>># As a string>>>xml=invoice.to_xml()>>># Or save it directly to a file>>>invoice.save('example_invoice.xml')
限制
这是概念实现的证明,并不是所有定义的特性 执行EN16931标准。但这很容易,在某些情况下 琐碎,实现它们。未实现的主要功能有:
- 不支持CreditNotes。
- 不支持文件附件。
- 不支持传递信息。
- 仅支持全球收费和折扣。行折扣和 不支持收费。
- 其他可能有用的属性(例如invoiceperiod、buyerreference, orderreference、billingreference、contractdocumentreference等) 未实现。
如果需要实现特定功能,请参见以下部分 对于功能请求。
许可证
在apache许可证2.0版下发布(请参见license.txt)。
Copyright (C) 2018 Invinet Sistemes