From 48385f9250f45d2a8b8927ded9bf1f964dcb23f6 Mon Sep 17 00:00:00 2001 From: Frederik Jaeckel Date: Thu, 23 Jan 2025 11:43:11 +0100 Subject: [PATCH] import cross-industry-invoice-d22 --- document.py | 20 ++-- tests/crossindustryinvoice-d22.xml | 168 +++++++++++++++++++++++++++++ tests/parsed_data.py | 80 ++++++++++++++ 3 files changed, 261 insertions(+), 7 deletions(-) create mode 100644 tests/crossindustryinvoice-d22.xml diff --git a/document.py b/document.py index cd3b854..fdac302 100644 --- a/document.py +++ b/document.py @@ -34,7 +34,7 @@ xml_types = [ (['xsd', 'Factur-X_1.07.2_EXTENDED', 'Factur-X_1.07.2_EXTENDED.xsd'], 'Factur-X extended', 'facturx_extended'), (['xsd', 'CII D22B XSD', 'CrossIndustryInvoice_100pD22B.xsd'], - 'CrossIndustryInvoice D22', ''), + 'CrossIndustryInvoice D22', 'crossindustryinvoice_d22'), (['xsd', 'os-UBL-2.1', 'xsd/maindoc', 'UBL-Invoice-2.1.xsd'], 'XRechnung - Invoice', ''), (['xsd', 'os-UBL-2.1', 'xsd', 'maindoc', 'UBL-CreditNote-2.1.xsd'], @@ -409,6 +409,11 @@ class Incoming(metaclass=PoolMeta): invoice.on_change_lines() return invoice + def _readxml_crossindustryinvoice_d22(self, xmltree): + """ read cross industry invoice d22 + """ + self._readxml_facturx_extended(xmltree, xmode='ciid22') + def _readxml_facturx_minimal(self, xmltree): """ add missing values to conversion-result @@ -436,7 +441,7 @@ class Incoming(metaclass=PoolMeta): """ self._readxml_facturx_extended(xmltree) - def _readxml_facturx_extended(self, xmltree): + def _readxml_facturx_extended(self, xmltree, xmode=None): """ read factur-x extended """ Configuration = Pool().get('document.incoming.configuration') @@ -470,11 +475,12 @@ class Incoming(metaclass=PoolMeta): date_path = xpath_exchg_doc + [ 'ram:IssueDateTime', 'udt:DateTimeString'] date_format = self._readxml_getattrib(xmltree, date_path, 'format') - if date_format != '102': - raise UserError(gettext( - 'document_incoming_invoice_xml.msg_convert_error', - msg='invalid date-format: %(code)s (expect: 102)' % { - 'code': str(date_format)})) + if xmode not in ['ciid22']: + if date_format != '102': + raise UserError(gettext( + 'document_incoming_invoice_xml.msg_convert_error', + msg='invalid date-format: %(code)s (expect: 102)' % { + 'code': str(date_format)})) p_data['invoice_date'] = self._readxml_convertdate( self._readxml_getvalue(xmltree, date_path)) diff --git a/tests/crossindustryinvoice-d22.xml b/tests/crossindustryinvoice-d22.xml new file mode 100644 index 0000000..1f8374c --- /dev/null +++ b/tests/crossindustryinvoice-d22.xml @@ -0,0 +1,168 @@ + + + + + + RE2024.01234 + 380 + + 20240617 + + + Description of invoice + + + 1 + Some notes to the customer. + + + 22 + Goes to field comment. + 42 + + + + + + 1 + + + + 1350.00 + + + + 1.0 + + + + VAT + S + 19.00 + + + 1350.00 + + + + + + 2 + + + + 800.00 + + + + 1.5 + + + + VAT + S + 19.00 + + + 1200.00 + + + + + + 3 + + + + 150.00 + + + + 2.0 + + + + 7.00 + + + 300.00 + + + + + + Name of the Supplier + + + + 12345 + Street of Supplier No 1 + Berlin + DE + Germany + DE-BE + Berlin + + + + Our Company + + + + 23456 + Address Line 1 + Address Line 2 + Potsdam + DE + Germany + DE-RR + Brandenburg + + + + + + + + + + RE2024.01234 + EUR + + 20240617 + + + 1 + + + 484.50 + VAT + 2550.00 + S + 19.00 + + + 21.00 + 300.00 + 7.00 + + + + 20240701 + + 3355.50 + + + 2850.00 + 2850.00 + 505.50 + 3355.50 + 3355.50 + + + + \ No newline at end of file diff --git a/tests/parsed_data.py b/tests/parsed_data.py index e2ff41e..0e5315f 100644 --- a/tests/parsed_data.py +++ b/tests/parsed_data.py @@ -7,6 +7,86 @@ from decimal import Decimal from datetime import date +parsed_data_ci_invoice = { + 'buyer_party': { + 'city': 'Potsdam', + 'name': 'Our Company', + 'postal_code': '23456', + 'street': 'Address Line 1\nAddress Line 2'}, + 'invoice_date': date(2024, 6, 17), + 'invoice_number': 'RE2024.01234', + 'lines_data': [{ + 'taxes': [{ + 'type': 'VAT', + 'percent': Decimal('19.00'), + 'category_code': 'S'}], + 'total': {'amount': Decimal('1350.00')}, + 'line_no': '1', + 'quantity': { + 'billed': Decimal('1.0'), + 'unit_code': 'KGM'}, + 'unit_net_price': {'amount': Decimal('1350.00')}, + }, { + 'taxes': [{ + 'type': 'VAT', + 'percent': Decimal('19.00'), + 'category_code': 'S'}], + 'total': {'amount': Decimal('1200.00')}, + 'line_no': '2', + 'quantity': { + 'billed': Decimal('1.5'), + 'unit_code': 'KGM'}, + 'unit_net_price': {'amount': Decimal('800.00')}, + }, { + 'taxes': [{'percent': Decimal('7.00')}], + 'total': {'amount': Decimal('300.00')}, + 'line_no': '3', + 'quantity': { + 'billed': Decimal('2.0'), + 'unit_code': 'MTR'}, + 'unit_net_price': {'amount': Decimal('150.00')}}], + 'note_list': [{ + 'Content': 'Description of invoice', + 'ContentCode': None, + 'SubjectCode': None, + }, { + 'Content': 'Some notes to the customer.', + 'ContentCode': '1', + 'SubjectCode': None, + }, { + 'Content': 'Goes to field comment.', + 'ContentCode': '22', + 'SubjectCode': '42'}], + 'payment': { + 'bank': [{'type': '1'}], + 'currency': 'EUR', + 'reference': 'RE2024.01234', + 'taxes': [{ + 'base': Decimal('2550.00'), + 'type': 'VAT', + 'amount': Decimal('484.50'), + 'percent': Decimal('19.00'), + 'category_code': 'S', + }, { + 'base': Decimal('300.00'), + 'amount': Decimal('21.00'), + 'percent': Decimal('7.00')}], + 'terms': [{ + 'amount': Decimal('3355.50'), + 'duedate': date(2024, 7, 1)}]}, + 'seller_party': { + 'city': 'Berlin', + 'name': 'Name of the Supplier', + 'postal_code': '12345', + 'street': 'Street of Supplier No 1'}, + 'total': { + 'amount': Decimal('2850.00'), + 'duepayable': Decimal('3355.50'), + 'grand': Decimal('3355.50'), + 'taxbase': Decimal('2850.00'), + 'taxtotal': Decimal('505.50')}} + + parsed_data_facturx_en16931 = { 'buyer_party': { 'city': 'Potsdam',