From 3751379f1e9a4c215fb6eb898b4ccc67659b9ace Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 10 May 2022 21:51:50 +0700 Subject: initial commit 2 --- addons/account_edi_facturx/tests/__init__.py | 3 + addons/account_edi_facturx/tests/test_facturx.py | 246 +++++++++++++++++++++++ 2 files changed, 249 insertions(+) create mode 100644 addons/account_edi_facturx/tests/__init__.py create mode 100644 addons/account_edi_facturx/tests/test_facturx.py (limited to 'addons/account_edi_facturx/tests') diff --git a/addons/account_edi_facturx/tests/__init__.py b/addons/account_edi_facturx/tests/__init__.py new file mode 100644 index 00000000..2f0994cf --- /dev/null +++ b/addons/account_edi_facturx/tests/__init__.py @@ -0,0 +1,3 @@ +# -*- encoding: utf-8 -*- + +from . import test_facturx diff --git a/addons/account_edi_facturx/tests/test_facturx.py b/addons/account_edi_facturx/tests/test_facturx.py new file mode 100644 index 00000000..46729101 --- /dev/null +++ b/addons/account_edi_facturx/tests/test_facturx.py @@ -0,0 +1,246 @@ +# -*- coding: utf-8 -*- +from freezegun import freeze_time +from odoo.addons.account_edi.tests.common import AccountEdiTestCommon +from odoo.tests import tagged + + +@tagged('post_install', '-at_install') +class TestAccountEdiFacturx(AccountEdiTestCommon): + + @classmethod + def setUpClass(cls, chart_template_ref=None, edi_format_ref='account_edi_facturx.edi_facturx_1_0_05'): + super().setUpClass(chart_template_ref=chart_template_ref, edi_format_ref=edi_format_ref) + + # ==== Init ==== + + cls.tax_10_include = cls.env['account.tax'].create({ + 'name': 'tax_10_include', + 'amount_type': 'percent', + 'amount': 10, + 'type_tax_use': 'sale', + 'price_include': True, + 'include_base_amount': True, + 'sequence': 10, + }) + + cls.tax_20 = cls.env['account.tax'].create({ + 'name': 'tax_20', + 'amount_type': 'percent', + 'amount': 20, + 'type_tax_use': 'sale', + 'sequence': 20, + }) + + cls.tax_group = cls.env['account.tax'].create({ + 'name': 'tax_group', + 'amount_type': 'group', + 'amount': 0.0, + 'type_tax_use': 'sale', + 'children_tax_ids': [(6, 0, (cls.tax_10_include + cls.tax_20).ids)], + }) + + # ==== Invoice ==== + + cls.invoice = cls.env['account.move'].create({ + 'move_type': 'out_invoice', + 'journal_id': cls.journal.id, + 'partner_id': cls.partner_b.id, + 'invoice_date': '2017-01-01', + 'date': '2017-01-01', + 'currency_id': cls.currency_data['currency'].id, + 'invoice_line_ids': [(0, 0, { + 'product_id': cls.product_a.id, + 'product_uom_id': cls.env.ref('uom.product_uom_dozen').id, + 'price_unit': 275.0, + 'quantity': 5, + 'discount': 20.0, + 'tax_ids': [(6, 0, cls.tax_20.ids)], + })], + }) + + cls.expected_invoice_facturx_values = ''' + + + + urn:cen.eu:en16931:2017 + + + + INV/2017/01/0001 + 380 + + 20170101 + + + + + + 1 + + + product_a + + + + 275.000 + + + true + + 20.0 + + + + + 5.0 + + + + 20.0 + + + 1100.000 + + + + + + company_1_data + + company_1_data + + + + + partner_b + + partner_b + + + + + INV/2017/01/0001: INV/2017/01/0001 + + + + + + 220.000 + 1100.000 + 20.0 + + + + 20170101 + + + + 1100.000 + 1100.000 + 220.000 + 1320.000 + 0.000 + 1320.000 + + + + + ''' + + #################################################### + # Test export + #################################################### + + def test_facturx(self): + ''' Test the generated Facturx Edi attachment without any modification of the invoice. ''' + self.assert_generated_file_equal(self.invoice, self.expected_invoice_facturx_values) + + @freeze_time('2017-02-01') + def test_facturx_group_of_taxes(self): + ''' Same as above with a group of taxes. ''' + self.invoice.write({ + 'invoice_line_ids': [(1, self.invoice.invoice_line_ids.id, {'tax_ids': [(6, 0, self.tax_group.ids)]})], + }) + + applied_xpath = ''' + + 275.000 + + + + + 10.0 + + + 20.0 + + + 1000.000 + + + + + + + 220.000 + 1100.000 + 20.0 + + + 100.000 + 1000.000 + 10.0 + + + + 20170101 + + + + 1000.000 + 1000.000 + 320.000 + 1320.000 + 0.000 + 1320.000 + + + + ''' + + self.assert_generated_file_equal(self.invoice, self.expected_invoice_facturx_values, applied_xpath) + + def test_export_pdf(self): + self.invoice.action_post() + pdf_values = self.edi_format._get_embedding_to_invoice_pdf_values(self.invoice) + self.assertEqual(pdf_values['name'], 'factur-x.xml') + + #################################################### + # Test import + #################################################### + + def test_invoice_edi_pdf(self): + invoice = self._create_empty_vendor_bill() + invoice_count = len(self.env['account.move'].search([])) + self.update_invoice_from_file('account_edi_facturx', 'test_file', 'test_facturx.pdf', invoice) + + self.assertEqual(len(self.env['account.move'].search([])), invoice_count) + self.assertEqual(invoice.amount_total, 525) + + self.create_invoice_from_file('account_edi_facturx', 'test_file', 'test_facturx.pdf') + + self.assertEqual(invoice.amount_total, 525) + self.assertEqual(len(self.env['account.move'].search([])), invoice_count + 1) + + def test_invoice_edi_xml(self): + invoice = self._create_empty_vendor_bill() + invoice_count = len(self.env['account.move'].search([])) + self.update_invoice_from_file('account_edi_facturx', 'test_file', 'test_facturx.xml', invoice) + + self.assertEqual(len(self.env['account.move'].search([])), invoice_count) + self.assertEqual(invoice.amount_total, 4610) + + self.create_invoice_from_file('account_edi_facturx', 'test_file', 'test_facturx.xml') + + self.assertEqual(invoice.amount_total, 4610) + self.assertEqual(len(self.env['account.move'].search([])), invoice_count + 1) -- cgit v1.2.3