diff --git a/addons/l10n_dk_oioubl/models/account_move.py b/addons/l10n_dk_oioubl/models/account_move.py new file mode 100644 index 00000000000..3f6476a8914 --- /dev/null +++ b/addons/l10n_dk_oioubl/models/account_move.py @@ -0,0 +1,12 @@ +from odoo import api, models + + +class AccountMove(models.Model): + _inherit = 'account.move' + + @api.model + def _get_ubl_cii_builder_from_xml_tree(self, tree): + customization_id = tree.find('{*}CustomizationID') + if customization_id is not None and 'OIOUBL-2' in customization_id.text: + return self.env['account.edi.xml.oioubl_201'] + return super()._get_ubl_cii_builder_from_xml_tree(tree) diff --git a/addons/l10n_dk_oioubl/tests/test_files/external/ADVORD_01_01_00_Invoice_v2p1.xml b/addons/l10n_dk_oioubl/tests/test_files/external/ADVORD_01_01_00_Invoice_v2p1.xml new file mode 100644 index 00000000000..9ed7c43cf00 --- /dev/null +++ b/addons/l10n_dk_oioubl/tests/test_files/external/ADVORD_01_01_00_Invoice_v2p1.xml @@ -0,0 +1,198 @@ + + + + + + + + 2.0 + OIOUBL-2.01 + Procurement-OrdSel-BilSim-1.0 + A00095678 + false + 6E09886B-DC6E-439F-82D1-7CCAC7F4E3B3 + 2006-04-10 + 380 + DKK + 5250124502 + + 5002701 + 2006-04-01 + + + + DK16356706 + + DK16356706 + + + Krea Toys + + + StructuredDK + Leverandørvej + 11 + Dyssegård + 2870 + + DK + + + + DK16356706 + + 63 + Moms + + + + Krea Toys + DK16356706 + + + 9876 + Hugo Jensen + 26532147 + Hugo@kt.dk + + + + + + 5798000416604 + + 5798000417777 + + + Myretuen + + + StructuredDK + Fredericiavej + 10 + Helsingør + 3000 + + DK + + + + DK16356709 + + 63 + Moms + + + + Myretuen + DK16356709 + + + 1413 + Lise Hansen + 2653214 + Lise@mt.dk + + + + + 2006-04-15 + + + 1 + 42 + 2006-04-25 + DK:BANK + + 0005704966 + A00095678 + + 9544 + + + + + 1 + 1 + 6250.00 + + + 1250.00 + + 5000.00 + 1250.00 + + StandardRated + 25 + + 63 + Moms + + + + + + 5000.00 + 1250.00 + 6250.00 + 6250.00 + + + 1 + 1.00 + 5000.00 + + 1 + + + 1250.00 + + 5000.00 + 1250.00 + + StandardRated + 25 + + 63 + Moms + + + + + + Fine toy + Fine toy + + 5712345780121 + + + + 5000.00 + 1 + 1 + + + diff --git a/addons/l10n_dk_oioubl/tests/test_files/external/ADVORD_02_02_00_Invoice_v2p1.xml b/addons/l10n_dk_oioubl/tests/test_files/external/ADVORD_02_02_00_Invoice_v2p1.xml new file mode 100644 index 00000000000..108cd05c4e9 --- /dev/null +++ b/addons/l10n_dk_oioubl/tests/test_files/external/ADVORD_02_02_00_Invoice_v2p1.xml @@ -0,0 +1,200 @@ + + + + + + + + 2.0 + OIOUBL-2.01 + Procurement-OrdSel-BilSim-1.0 + A00095680 + false + 6E09886B-DC6E-439F-82D1-7CCAC7F4E3B4 + 2006-04-10 + 380 + DKK + 5250124502 + + 5002701 + 6E09886B-DC6E-43EE-82D1-7CCAC7F4E3B1 + 2006-04-01 + + + + DK16356706 + + DK16356706 + + + Super Soft A/S + + + StructuredDK + Leverandørvej + 11 + Dyssegård + 2870 + + DK + + + + DK16356706 + + 63 + Moms + + + + Super Soft A/S + DK16356706 + + + 5567 + Hugo Jensen + 26532147 + Hugo@ss.dk + + + + + + 5798000416604 + + 5798000417777 + + + Myretuen + + + StructuredDK + Fredericiavej + 10 + Helsingør + 3000 + + DK + + + + DK16356709 + + 63 + Moms + + + + Myretuen + DK16356709 + + + 1413 + Lise Hansen + 2653214 + Lise@mt.dk + + + + + 2006-04-15 + + + 1 + 42 + 2006-04-25 + DK:BANK + + 0005704966 + A00095680 + + 9544 + + + + + 1 + 1 + 5000.00 + + + 1000.00 + + 4000.00 + 1000.00 + + StandardRated + 25 + + 63 + Moms + + + + + + 4000.00 + 1000.00 + 5000.00 + 5000.00 + + + 1 + 800.00 + 4000.00 + + 1 + + + 1000.00 + + 4000.00 + 1000.00 + + StandardRated + 25 + + 63 + Moms + + + + + + Superble + Superble + + 5712345780121 + + + + 5.00 + 1 + 1 + + + diff --git a/addons/l10n_dk_oioubl/tests/test_files/external/ADVORD_03_03_00_Invoice_v2p1.xml b/addons/l10n_dk_oioubl/tests/test_files/external/ADVORD_03_03_00_Invoice_v2p1.xml new file mode 100644 index 00000000000..e5ae677a779 --- /dev/null +++ b/addons/l10n_dk_oioubl/tests/test_files/external/ADVORD_03_03_00_Invoice_v2p1.xml @@ -0,0 +1,200 @@ + + + + + + + + 2.0 + OIOUBL-2.01 + Procurement-OrdAdvR-BilSim-1.0 + A00095678 + false + 6E09886B-DC6E-439F-82D1-7CCAC7F4E3B3 + 2006-04-10 + 380 + DKK + 5250124502 + + 5002701 + 6E09886B-DC6E-439F-82D1-7CCAC7F4E3B1 + 2006-04-01 + + + + DK16356706 + + DK16356706 + + + PricewaterhouseCoopers + + + StructuredDK + Strandvejen + 44 + Hellerup + 2900 + + DK + + + + DK16356706 + + 63 + Moms + + + + PricewaterhouseCoopers + DK16356706 + + + 8149 + Peter Skovborg + 26532147 + Peter@pwc.dk + + + + + + 5798000416604 + + 5798000416642 + + + IT- og Telestyrelsen + + + StructuredDK + Holsteinsgade + 300 + København Ø + 2100 + + DK + + + + DK16356709 + + 63 + Moms + + + + IT- og Telestyrelsen + DK16356709 + + + 90015 + Lasse Jensen + 2653214 + Lasse@itst.dk + + + + + 2006-04-15 + + + 1 + 42 + 2006-04-25 + DK:BANK + + 0005704966 + A00095678 + + 9544 + + + + + 1 + 1 + 6250.00 + + + 1250.00 + + 5000.00 + 1250.00 + + StandardRated + 25 + + 63 + Moms + + + + + + 5000.00 + 1250.00 + 6250.00 + 6250.00 + + + 1 + 1.00 + 5000.00 + + 1 + + + 1250.00 + + 5000.00 + 1250.00 + + StandardRated + 25 + + 63 + Moms + + + + + + Konsulentrapport + Konsulentrapport + + n/a + + + + 5000.00 + 1 + 1 + + + diff --git a/addons/l10n_dk_oioubl/tests/test_files/external/BASPRO_01_01_00_Invoice_v2p1.xml b/addons/l10n_dk_oioubl/tests/test_files/external/BASPRO_01_01_00_Invoice_v2p1.xml new file mode 100644 index 00000000000..4b72f40b439 --- /dev/null +++ b/addons/l10n_dk_oioubl/tests/test_files/external/BASPRO_01_01_00_Invoice_v2p1.xml @@ -0,0 +1,228 @@ + + + + + + + + 2.0 + OIOUBL-2.01 + Procurement-OrdSimR-BilSim-1.0 + A00095678 + false + 9756b4d0-8815-1029-857a-e388fe63f399 + 2005-11-20 + 380 + DKK + 5250124502 + + 5002701 + 9756b468-8815-1029-857a-e388fe63f399 + 2005-11-01 + + + + DK16356706 + + DK16356706 + + + Tavleverandøren + + + StructuredDK + Leverandørvej + 11 + Dyssegård + 2870 + + DK + + + + DK16356706 + + 63 + Moms + + + + Tavleleverandøren + DK16356706 + + + 23456 + Hugo Jensen + 15812337 + Hugo@tavl.dk + + + + + + 5798000416604 + + 5798000416604 + + + Den Lille Skole + + + StructuredDK + Fredericiavej + 10 + Helsingør + 3000 + + DK + + + + Den Lille Skole + DK16356709 + + + 7778 + Hans Hansen + 26532147 + Hans@dls.dk + + + + + 2005-11-15 + + + 1 + 42 + 2005-11-25 + DK:BANK + + 1234567890 + A00095678 + + 1234 + + + + + 1 + 1 + 6312.50 + + + 1262.50 + + 5050.00 + 1262.50 + + StandardRated + 25 + + 63 + Moms + + + + + + 5050.00 + 1262.50 + 6312.50 + 6312.50 + + + 1 + 1.00 + 5000.00 + + 1 + + + 1250.00 + + 5000.00 + 1250.00 + + StandardRated + 25 + + 63 + Moms + + + + + + Hejsetavle + Hejsetavle + + 5712345780121 + + + + 5000.00 + 1 + 1 + + + + 2 + 2.00 + 50.00 + + 2 + + + 12.50 + + 50.00 + 12.50 + + StandardRated + 25 + + 63 + Moms + + + + + + Beslag + Beslag + + 5712345780111 + + + + 25.00 + 1 + 1 + + + diff --git a/addons/l10n_dk_oioubl/tests/test_xml_oioubl_dk.py b/addons/l10n_dk_oioubl/tests/test_xml_oioubl_dk.py index 2503255f14b..9f2629fabc5 100644 --- a/addons/l10n_dk_oioubl/tests/test_xml_oioubl_dk.py +++ b/addons/l10n_dk_oioubl/tests/test_xml_oioubl_dk.py @@ -1,10 +1,12 @@ from freezegun import freeze_time -from odoo import Command +from odoo import Command, fields from odoo.addons.l10n_account_edi_ubl_cii_tests.tests.common import TestUBLCommon from odoo.addons.account.tests.test_account_move_send import TestAccountMoveSendCommon from odoo.exceptions import UserError +from odoo.modules.module import get_resource_path from odoo.tests import tagged +from odoo.tools import file_open @tagged('post_install_l10n', 'post_install', '-at_install') @@ -60,10 +62,11 @@ class TestUBLDK(TestUBLCommon, TestAccountMoveSendCommon): 'company_registry': '123 568 941 00056', 'ubl_cii_format': 'oioubl_201', }) - cls.dk_local_tax_1 = cls.env["account.chart.template"].ref('tax120') - cls.dk_local_tax_2 = cls.env["account.chart.template"].ref('tax110') - cls.dk_foreign_tax_1 = cls.env["account.chart.template"].ref('tax210') - cls.dk_foreign_tax_2 = cls.env["account.chart.template"].ref('tax220') + cls.dk_local_sale_tax_1 = cls.env["account.chart.template"].ref('tax120') + cls.dk_local_sale_tax_2 = cls.env["account.chart.template"].ref('tax110') + cls.dk_foreign_sale_tax_1 = cls.env["account.chart.template"].ref('tax210') + cls.dk_foreign_sale_tax_2 = cls.env["account.chart.template"].ref('tax220') + cls.dk_local_purchase_tax_goods = cls.env["account.chart.template"].ref('tax400') def create_post_and_send_invoice(self, partner=None, move_type='out_invoice'): if not partner: @@ -71,10 +74,10 @@ class TestUBLDK(TestUBLCommon, TestAccountMoveSendCommon): if partner == self.partner_a: # local dk taxes - tax_1, tax_2 = self.dk_local_tax_1, self.dk_local_tax_2 + tax_1, tax_2 = self.dk_local_sale_tax_1, self.dk_local_sale_tax_2 else: # dk taxes for foreigners - tax_1, tax_2 = self.dk_foreign_tax_1, self.dk_foreign_tax_2 + tax_1, tax_2 = self.dk_foreign_sale_tax_1, self.dk_foreign_sale_tax_2 invoice = self.env["account.move"].create({ 'move_type': move_type, @@ -104,6 +107,10 @@ class TestUBLDK(TestUBLCommon, TestAccountMoveSendCommon): invoice._generate_pdf_and_send_invoice(self.move_template, from_cron=False, allow_fallback_pdf=False) return invoice + ######### + # EXPORT + ######### + @freeze_time('2017-01-01') def test_export_invoice_two_line_partner_dk(self): invoice = self.create_post_and_send_invoice() @@ -166,3 +173,99 @@ class TestUBLDK(TestUBLCommon, TestAccountMoveSendCommon): self.partner_c.company_registry = False with self.assertRaisesRegex(UserError, "The company registry is required for french partner:"): self.create_post_and_send_invoice(partner=self.partner_c) + + ######### + # IMPORT + ######### + + def import_bill_xml_file_in_purchase_journal(self, file_path): + full_file_path = get_resource_path(self.test_module, 'tests/test_files', file_path) + self.assertTrue(full_file_path, f'File not found: {file_path}') + with file_open(full_file_path, 'rb') as file: + xml_attachment = self.env['ir.attachment'].create({ + 'mimetype': 'application/xml', + 'name': 'test_invoice.xml', + 'raw': file.read(), + }) + purchase_journal = self.company_data["default_journal_purchase"] + invoice = purchase_journal._create_document_from_attachment(xml_attachment.id) + return invoice + + @freeze_time('2017-01-01') + def test_oioubl_import_exemple_file_1(self): + file_name = 'external/ADVORD_01_01_00_Invoice_v2p1.xml' + bill = self.import_bill_xml_file_in_purchase_journal(file_name) + self.assertRecordValues(bill, ({ + 'ref': 'A00095678', + 'invoice_date': fields.Date.from_string('2006-04-10'), + 'amount_total': 6_250.00, + },)) + self.assertRecordValues(bill.invoice_line_ids, ({ + 'name': 'Fine toy', + 'quantity': 1, + 'price_unit': 5_000.00, + 'price_subtotal': 5_000.00, + 'price_total': 6_250.00, + 'tax_ids': self.dk_local_purchase_tax_goods.ids, + },)) + + @freeze_time('2017-01-01') + def test_oioubl_import_exemple_file_2(self): + file_name = 'external/ADVORD_02_02_00_Invoice_v2p1.xml' + bill = self.import_bill_xml_file_in_purchase_journal(file_name) + self.assertRecordValues(bill, ({ + 'ref': 'A00095680', + 'invoice_date': fields.Date.from_string('2006-04-10'), + 'amount_total': 5_000.00, + },)) + self.assertRecordValues(bill.invoice_line_ids, ({ + 'name': 'Superble', + 'quantity': 800, + 'price_unit': 5.00, + 'price_subtotal': 4_000.00, + 'price_total': 5_000.00, + 'tax_ids': self.dk_local_purchase_tax_goods.ids, + },)) + + @freeze_time('2017-01-01') + def test_oioubl_import_exemple_file_3(self): + file_name = 'external/ADVORD_03_03_00_Invoice_v2p1.xml' + bill = self.import_bill_xml_file_in_purchase_journal(file_name) + self.assertRecordValues(bill, ({ + 'ref': 'A00095678', + 'invoice_date': fields.Date.from_string('2006-04-10'), + 'amount_total': 6_250.00, + },)) + self.assertRecordValues(bill.invoice_line_ids, ({ + 'name': 'Konsulentrapport', + 'quantity': 1, + 'price_unit': 5_000.00, + 'price_subtotal': 5_000.00, + 'price_total': 6_250.00, + 'tax_ids': self.dk_local_purchase_tax_goods.ids, + },)) + + @freeze_time('2017-01-01') + def test_oioubl_import_exemple_file_4(self): + file_name = 'external/BASPRO_01_01_00_Invoice_v2p1.xml' + bill = self.import_bill_xml_file_in_purchase_journal(file_name) + self.assertRecordValues(bill, ({ + 'ref': 'A00095678', + 'invoice_date': fields.Date.from_string('2005-11-20'), + 'amount_total': 6_312.50, + },)) + self.assertRecordValues(bill.invoice_line_ids, ({ + 'name': 'Hejsetavle', + 'quantity': 1, + 'price_unit': 5_000.00, + 'price_subtotal': 5_000.00, + 'price_total': 6_250.00, + 'tax_ids': self.dk_local_purchase_tax_goods.ids, + }, { + 'name': 'Beslag', + 'quantity': 2, + 'price_unit': 25.00, + 'price_subtotal': 50.00, + 'price_total': 62.50, + 'tax_ids': self.dk_local_purchase_tax_goods.ids, + }))