diff --git a/tests/document.py b/tests/document.py index 98a4791..81917f0 100644 --- a/tests/document.py +++ b/tests/document.py @@ -4,6 +4,7 @@ # this repository contains the full copyright notices and license terms. import os.path +import copy from decimal import Decimal from datetime import date from trytond.tests.test_tryton import with_transaction @@ -13,6 +14,148 @@ from trytond.modules.company.tests import create_company, set_company from trytond.modules.account.tests import create_chart, get_fiscalyear +parsed_data_facturx = { + 'invoice_number': 'RE2024.01234', + 'invoice_date': date(2024, 6, 17), + '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'}], + 'seller_party': { + 'name': 'Name of the Supplier', + 'postal_code': '12345', + 'street': 'Street of Supplier No 1', + 'city': 'Berlin'}, + 'buyer_party': { + 'name': 'Our Company', + 'postal_code': '23456', + 'street': 'Address Line 1\nAddress Line 2', + 'city': 'Potsdam'}, + 'lines_data': [{ + 'line_no': '1', + 'name': 'Name of Product 1', + 'description': 'Description of Product 1', + 'unit_net_price': {'amount': Decimal('1350.00')}, + 'quantity': {'billed': Decimal('1.0')}, + 'taxes': [{ + 'type': 'VAT', + 'category_code': 'S', + 'percent': Decimal('19.00')}], + 'total': {'amount': Decimal('1350.00')}, + }, { + 'convert_note': [ + 'skip: /rsm:CrossIndustryInvoice/' + + 'rsm:SupplyChainTradeTransaction/' + + 'ram:IncludedSupplyChainTradeLineItem[2]/' + + 'ram:SpecifiedLineTradeDelivery/' + + 'ram:ActualDeliverySupplyChainEvent'], + 'line_no': '2', + 'line_note': 'Description of Line 2\n' + + 'Description of Line 2, line 2', + 'prod_id': '2', + 'glob_id': '3', + 'seller_id': '4', + 'buyer_id': '5', + 'industy_id': '6', + 'model_id': '7', + 'name': 'Name of Product 2', + 'description': 'Description of Product 2', + 'lot': 'batch23', + 'brand_name': 'Brand-Name', + 'model_name': 'Model-Name', + 'trade_country': 'DE', + 'attributes': [{ + 'code': '123', + 'description': 'Kilogram', + 'uom': 'kg', + 'value': '23'}], + 'classification': [{ + 'code': '3c', 'name': 'product-class 1'}], + 'serialno': [{'lot': '22', 'serial': '1234'}], + 'refprod': [{ + 'id': '1', + 'global_id': '2', + 'seller_id': '3', + 'buyer_id': '4', + 'name': 'ref-prod-1', + 'description': 'description of ref-prod-1', + 'quantity': Decimal('1.0')}], + 'unit_net_price': { + 'amount': Decimal('800.00'), + 'basequantity': Decimal('1.0')}, + 'unit_gross_price': { + 'amount': Decimal('950.00'), + 'basequantity': Decimal('1.0')}, + 'quantity': { + 'billed': Decimal('1.5'), + 'package': Decimal('1.5')}, + 'taxes': [{ + 'type': 'VAT', + 'category_code': 'S', + 'percent': Decimal('19.00')}], + 'total': {'amount': Decimal('1200.00')}, + }, { + 'line_no': '3', + 'name': 'Name of Product 3', + 'description': 'Description of Product 3', + 'unit_net_price': {'amount': Decimal('150.00')}, + 'quantity': {'billed': Decimal('2.0')}, + 'taxes': [{ + 'type': 'VAT', + 'category_code': 'S', + 'percent': Decimal('7.00')}], + 'total': {'amount': Decimal('300.00')}, + }], + 'payment': { + 'reference': 'RE2024.01234', + 'currency': 'EUR', + 'bank': [{ + 'info': 'Wire transfer', + 'type': '30', + 'debitor_iban': 'DE02300209000106531065', + 'creditor_iban': 'DE02300209000106531065', + 'creditor_name': 'mbs', + 'card_id': 'DE02300209000106531065', + 'card_holder_name': 'Card Holder', + 'institution': 'WELADED1PMB'}], + 'taxes': [{ + 'amount': Decimal('484.5'), + 'type': 'VAT', + 'base': Decimal('2550.0'), + 'category_code': 'S', + 'percent': Decimal('19.00'), + }, { + 'amount': Decimal('21.0'), + 'type': 'VAT', + 'base': Decimal('300.0'), + 'category_code': 'S', + 'percent': Decimal('7.00')}], + 'terms': [{ + 'description': 'Payment description', + 'duedate': date(2024, 7, 1), + 'mandat_id': 'mandat id', + 'amount': Decimal('3355.50'), + 'discount_date': date(2024, 7, 2), + 'discount_measure': Decimal('10.0'), + 'discount_base': Decimal('3355.0'), + 'discount_perc': Decimal('2.0'), + 'discount_amount': Decimal('70.0')}]}, + 'total': { + 'amount': Decimal('1350.00'), + 'taxbase': Decimal('2850.00'), + 'taxtotal': Decimal('505.5'), + 'grand': Decimal('3355.50'), + 'duepayable': Decimal('3355.50')}} + + def set_invoice_sequences(fiscalyear): pool = Pool() Sequence = pool.get('ir.sequence.strict') @@ -147,146 +290,7 @@ class DocumentTestCase(object): self.assertEqual(funcname, 'facturx_extended') incoming._readxml_facturx_extended(xml_data) - self.assertEqual(incoming.parsed_data, { - 'invoice_number': 'RE2024.01234', - 'invoice_date': date(2024, 6, 17), - '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'}], - 'seller_party': { - 'name': 'Name of the Supplier', - 'postal_code': '12345', - 'street': 'Street of Supplier No 1', - 'city': 'Berlin'}, - 'buyer_party': { - 'name': 'Our Company', - 'postal_code': '23456', - 'street': 'Address Line 1\nAddress Line 2', - 'city': 'Potsdam'}, - 'lines_data': [{ - 'line_no': '1', - 'name': 'Name of Product 1', - 'description': 'Description of Product 1', - 'unit_net_price': {'amount': Decimal('1350.00')}, - 'quantity': {'billed': Decimal('1.0')}, - 'taxes': [{ - 'type': 'VAT', - 'category_code': 'S', - 'percent': Decimal('19.00')}], - 'total': {'amount': Decimal('1350.00')}, - }, { - 'convert_note': [ - 'skip: /rsm:CrossIndustryInvoice/' + - 'rsm:SupplyChainTradeTransaction/' + - 'ram:IncludedSupplyChainTradeLineItem[2]/' + - 'ram:SpecifiedLineTradeDelivery/' + - 'ram:ActualDeliverySupplyChainEvent'], - 'line_no': '2', - 'line_note': 'Description of Line 2\n' + - 'Description of Line 2, line 2', - 'prod_id': '2', - 'glob_id': '3', - 'seller_id': '4', - 'buyer_id': '5', - 'industy_id': '6', - 'model_id': '7', - 'name': 'Name of Product 2', - 'description': 'Description of Product 2', - 'lot': 'batch23', - 'brand_name': 'Brand-Name', - 'model_name': 'Model-Name', - 'trade_country': 'DE', - 'attributes': [{ - 'code': '123', - 'description': 'Kilogram', - 'uom': 'kg', - 'value': '23'}], - 'classification': [{ - 'code': '3c', 'name': 'product-class 1'}], - 'serialno': [{'lot': '22', 'serial': '1234'}], - 'refprod': [{ - 'id': '1', - 'global_id': '2', - 'seller_id': '3', - 'buyer_id': '4', - 'name': 'ref-prod-1', - 'description': 'description of ref-prod-1', - 'quantity': Decimal('1.0')}], - 'unit_net_price': { - 'amount': Decimal('800.00'), - 'basequantity': Decimal('1.0')}, - 'unit_gross_price': { - 'amount': Decimal('950.00'), - 'basequantity': Decimal('1.0')}, - 'quantity': { - 'billed': Decimal('1.5'), - 'package': Decimal('1.5')}, - 'taxes': [{ - 'type': 'VAT', - 'category_code': 'S', - 'percent': Decimal('19.00')}], - 'total': {'amount': Decimal('1200.00')}, - }, { - 'line_no': '3', - 'name': 'Name of Product 3', - 'description': 'Description of Product 3', - 'unit_net_price': {'amount': Decimal('150.00')}, - 'quantity': {'billed': Decimal('2.0')}, - 'taxes': [{ - 'type': 'VAT', - 'category_code': 'S', - 'percent': Decimal('7.00')}], - 'total': {'amount': Decimal('300.00')}, - }], - 'payment': { - 'reference': 'RE2024.01234', - 'currency': 'EUR', - 'bank': [{ - 'info': 'Wire transfer', - 'type': '30', - 'debitor_iban': 'DE02300209000106531065', - 'creditor_iban': 'DE02300209000106531065', - 'creditor_name': 'mbs', - 'card_id': 'DE02300209000106531065', - 'card_holder_name': 'Card Holder', - 'institution': 'WELADED1PMB'}], - 'taxes': [{ - 'amount': Decimal('484.5'), - 'type': 'VAT', - 'base': Decimal('2550.0'), - 'category_code': 'S', - 'percent': Decimal('19.00'), - }, { - 'amount': Decimal('21.0'), - 'type': 'VAT', - 'base': Decimal('300.0'), - 'category_code': 'S', - 'percent': Decimal('7.00')}], - 'terms': [{ - 'description': 'Payment description', - 'duedate': date(2024, 7, 1), - 'mandat_id': 'mandat id', - 'amount': Decimal('3355.50'), - 'discount_date': date(2024, 7, 2), - 'discount_measure': Decimal('10.0'), - 'discount_base': Decimal('3355.0'), - 'discount_perc': Decimal('2.0'), - 'discount_amount': Decimal('70.0')}]}, - 'total': { - 'amount': Decimal('1350.00'), - 'taxbase': Decimal('2850.00'), - 'taxtotal': Decimal('505.5'), - 'grand': Decimal('3355.50'), - 'duepayable': Decimal('3355.50')}}) + self.assertEqual(incoming.parsed_data, parsed_data_facturx) @with_transaction() def test_xmldoc_import_facturx(self): @@ -296,6 +300,7 @@ class DocumentTestCase(object): IncDocument = pool.get('document.incoming') Configuration = pool.get('document.incoming.configuration') Party = pool.get('party.party') + IrAttachment = pool.get('ir.attachment') company = create_company('m-ds') with set_company(company): @@ -397,4 +402,19 @@ class DocumentTestCase(object): # run the usual call: process workers self.prep_incomingdoc_run_worker() + self.assertEqual(document.result.__name__, 'account.invoice') + self.assertEqual(document.result.reference, 'RE2024.01234') + # seller-party was already created by 'invoice.save()' + # a few lines above, + # the party-id in 'seller_party' means: dont create this party + parsed_ori = copy.deepcopy(parsed_data_facturx) + parsed_ori['seller_party']['party'] = invoice.party.id + self.assertEqual(document.parsed_data, parsed_ori) + + attachment, = IrAttachment.search([ + ('resource.party', '=', invoice.party, 'account.invoice'), + ('type', '=', 'data')]) + self.assertEqual(attachment.data, document.data) + self.assertEqual(attachment.name, 'facturx-extended.xml') + # end DocumentTestCase