diff --git a/addons/account_edi_ubl_cii/i18n/account_edi_ubl_cii.pot b/addons/account_edi_ubl_cii/i18n/account_edi_ubl_cii.pot index b28f6f360f2d1c5e306372e8dfca19e0df545caf..20381c45438e56dcde68a1f8acca734c8f7d9c74 100644 --- a/addons/account_edi_ubl_cii/i18n/account_edi_ubl_cii.pot +++ b/addons/account_edi_ubl_cii/i18n/account_edi_ubl_cii.pot @@ -81,27 +81,23 @@ msgid "" msgstr "" #. module: account_edi_ubl_cii -#: code:addons/account_edi_ubl_cii/models/account_edi_common.py:0 #: code:addons/account_edi_ubl_cii/models/account_edi_xml_cii_facturx.py:0 #: code:addons/account_edi_ubl_cii/models/account_edi_xml_ubl_20.py:0 #, python-format -msgid "Could not retrieve the tax: %s %% for line '%s'." +msgid "Could not retrieve the %s." msgstr "" #. module: account_edi_ubl_cii -#: code:addons/account_edi_ubl_cii/models/account_edi_xml_cii_facturx.py:0 -#: code:addons/account_edi_ubl_cii/models/account_edi_xml_ubl_20.py:0 +#: code:addons/account_edi_ubl_cii/models/account_edi_common.py:0 +#: code:addons/account_edi_ubl_cii/models/account_edi_common.py:0 #, python-format -msgid "" -"Could not retrieve the unit of measure for line with label '%s'. Did you " -"install the inventory app and enabled the 'Units of Measure' option ?" +msgid "Could not retrieve the tax: %s %% for line '%s'." msgstr "" #. module: account_edi_ubl_cii -#: code:addons/account_edi_ubl_cii/models/account_edi_xml_cii_facturx.py:0 -#: code:addons/account_edi_ubl_cii/models/account_edi_xml_ubl_20.py:0 +#: code:addons/account_edi_ubl_cii/models/account_edi_common.py:0 #, python-format -msgid "Could not retrieve the vendor." +msgid "Could not retrieve the unit of measure for line with label '%s'." msgstr "" #. module: account_edi_ubl_cii @@ -382,6 +378,13 @@ msgid "" " code (BT-151)." msgstr "" +#. module: account_edi_ubl_cii +#: code:addons/account_edi_ubl_cii/models/account_edi_xml_cii_facturx.py:0 +#: code:addons/account_edi_ubl_cii/models/account_edi_xml_ubl_20.py:0 +#, python-format +msgid "customer" +msgstr "" + #. module: account_edi_ubl_cii #: model_terms:ir.ui.view,arch_db:account_edi_ubl_cii.account_invoice_pdfa_3_facturx_metadata msgid "external" @@ -411,3 +414,10 @@ msgstr "" #: model_terms:ir.ui.view,arch_db:account_edi_ubl_cii.account_invoice_pdfa_3_facturx_metadata msgid "urn:factur-x:pdfa:CrossIndustryDocument:invoice:1p0#" msgstr "" + +#. module: account_edi_ubl_cii +#: code:addons/account_edi_ubl_cii/models/account_edi_xml_cii_facturx.py:0 +#: code:addons/account_edi_ubl_cii/models/account_edi_xml_ubl_20.py:0 +#, python-format +msgid "vendor" +msgstr "" diff --git a/addons/account_edi_ubl_cii/models/account_edi_xml_cii_facturx.py b/addons/account_edi_ubl_cii/models/account_edi_xml_cii_facturx.py index 7b8e4dc372dc38c090a57ca96ab2bb5aed8671f6..47534c2e819e0c715761d6eb8be6b1939e2eeb2b 100644 --- a/addons/account_edi_ubl_cii/models/account_edi_xml_cii_facturx.py +++ b/addons/account_edi_ubl_cii/models/account_edi_xml_cii_facturx.py @@ -216,14 +216,14 @@ class AccountEdiXmlCII(models.AbstractModel): # ==== partner_id ==== - partner_type = invoice_form.journal_id.type == journal.type and 'SellerTradeParty' or 'BuyerTradeParty' + partner_type = invoice_form.journal_id.type == 'purchase' and 'SellerTradeParty' or 'BuyerTradeParty' invoice_form.partner_id = self.env['account.edi.format']._retrieve_partner( name=_find_value(f"//ram:{partner_type}/ram:Name"), mail=_find_value(f"//ram:{partner_type}//ram:URIID[@schemeID='SMTP']"), vat=_find_value(f"//ram:{partner_type}/ram:SpecifiedTaxRegistration/ram:ID"), ) if not invoice_form.partner_id: - logs.append(_("Could not retrieve the vendor.")) + logs.append(_("Could not retrieve the %s.", _("customer") if invoice_form.move_type in ('out_invoice', 'out_refund') else _("vendor"))) # ==== currency_id ==== diff --git a/addons/account_edi_ubl_cii/models/account_edi_xml_ubl_20.py b/addons/account_edi_ubl_cii/models/account_edi_xml_ubl_20.py index 9f91397b78ec5e2d1213ba0d3d98b9d5788942cb..509ce5910484826bcb30c72152e4d4251b7a4a06 100644 --- a/addons/account_edi_ubl_cii/models/account_edi_xml_ubl_20.py +++ b/addons/account_edi_ubl_cii/models/account_edi_xml_ubl_20.py @@ -466,12 +466,12 @@ class AccountEdiXmlUBL20(models.AbstractModel): partner = self._import_retrieve_info_from_map( tree, - self._import_retrieve_partner_map(journal), + self._import_retrieve_partner_map(self.env.company, journal.type), ) if partner: invoice_form.partner_id = partner else: - logs.append(_("Could not retrieve the vendor.")) + logs.append(_("Could not retrieve the %s.", _("customer") if invoice_form.move_type in ('out_invoice', 'out_refund') else _("vendor"))) # ==== currency_id ==== @@ -614,23 +614,24 @@ class AccountEdiXmlUBL20(models.AbstractModel): return ('in_refund', 'out_refund'), 1 return None, None - def _import_retrieve_partner_map(self, company): + def _import_retrieve_partner_map(self, company, move_type='purchase'): + role = "Customer" if move_type == 'sale' else "Supplier" def with_vat(tree, extra_domain): - vat_node = tree.find('.//{*}AccountingSupplierParty/{*}Party//{*}CompanyID') + vat_node = tree.find(f'.//{{*}}Accounting{role}Party/{{*}}Party//{{*}}CompanyID') vat = None if vat_node is None else vat_node.text return self.env['account.edi.format']._retrieve_partner_with_vat(vat, extra_domain) def with_phone_mail(tree, extra_domain): - phone_node = tree.find('.//{*}AccountingSupplierParty/{*}Party//{*}Telephone') - mail_node = tree.find('.//{*}AccountingSupplierParty/{*}Party//{*}ElectronicMail') + phone_node = tree.find(f'.//{{*}}Accounting{role}Party/{{*}}Party//{{*}}Telephone') + mail_node = tree.find(f'.//{{*}}Accounting{role}Party/{{*}}Party//{{*}}ElectronicMail') phone = None if phone_node is None else phone_node.text mail = None if mail_node is None else mail_node.text return self.env['account.edi.format']._retrieve_partner_with_phone_mail(phone, mail, extra_domain) def with_name(tree, extra_domain): - name_node = tree.find('.//{*}AccountingSupplierParty/{*}Party//{*}Name') + name_node = tree.find(f'.//{{*}}Accounting{role}Party/{{*}}Party//{{*}}Name') name = None if name_node is None else name_node.text return self.env['account.edi.format']._retrieve_partner_with_name(name, extra_domain) diff --git a/addons/l10n_account_edi_ubl_cii_tests/tests/common.py b/addons/l10n_account_edi_ubl_cii_tests/tests/common.py index 8b583bec96049c3a9cde14d07d0997516e94577e..74b572c6697c98a523e22c8ec8d13b10feba8c4e 100644 --- a/addons/l10n_account_edi_ubl_cii_tests/tests/common.py +++ b/addons/l10n_account_edi_ubl_cii_tests/tests/common.py @@ -41,7 +41,7 @@ class TestUBLCommon(AccountEdiTestCommon): def assert_same_invoice(self, invoice1, invoice2, **invoice_kwargs): self.assertEqual(len(invoice1.invoice_line_ids), len(invoice2.invoice_line_ids)) self.assertRecordValues(invoice2, [{ - 'partner_id': invoice1.company_id.partner_id.id, + 'partner_id': invoice1.partner_id.id, 'invoice_date': fields.Date.from_string(invoice1.date), 'currency_id': invoice1.currency_id.id, 'amount_untaxed': invoice1.amount_untaxed, @@ -74,7 +74,8 @@ class TestUBLCommon(AccountEdiTestCommon): new_invoice = self.edi_format._create_invoice_from_xml_tree( xml_filename, xml_etree, - invoice.journal_id + # /!\ use the same journal as the invoice's one to import the xml ! + invoice.journal_id, ) self.assertTrue(new_invoice) @@ -187,3 +188,38 @@ class TestUBLCommon(AccountEdiTestCommon): ) return xml_etree, xml_filename + + def _test_import_partner(self, edi_code, filename): + """ + Given an invoice where partner_1 is the vendor and partner_2 is the customer with an EDI attachment. + * Uploading the attachment as an invoice should create an invoice with the buyer = partner_2. + * Uploading the attachment as a vendor bill should create a bill with the vendor = partner_1. + """ + invoice = self._generate_move( + seller=self.partner_1, + buyer=self.partner_2, + move_type='out_invoice', + invoice_line_ids=[{'product_id': self.product_a.id}], + ) + edi_attachment = invoice.edi_document_ids.filtered( + lambda doc: doc.edi_format_id.code == edi_code).attachment_id + self.assertEqual(edi_attachment.name, filename) + edi_etree = self.get_xml_tree_from_string(edi_attachment.raw) + + # Import attachment as an invoice + new_invoice = self.edi_format._create_invoice_from_xml_tree( + filename='test_filename', + tree=edi_etree, + journal=self.env['account.journal'].search( + [('type', '=', 'sale'), ('company_id', '=', self.env.company.id)], limit=1) + ) + self.assertEqual(self.partner_2, new_invoice.partner_id) + + # Import attachment as a vendor bill + new_invoice = self.edi_format._create_invoice_from_xml_tree( + filename='test_filename', + tree=edi_etree, + journal=self.env['account.journal'].search( + [('type', '=', 'purchase'), ('company_id', '=', self.env.company.id)], limit=1) + ) + self.assertEqual(self.partner_1, new_invoice.partner_id) diff --git a/addons/l10n_account_edi_ubl_cii_tests/tests/test_xml_cii_fr.py b/addons/l10n_account_edi_ubl_cii_tests/tests/test_xml_cii_fr.py index 560531dbe0a9c5f6c72320aa6146b1dc2384a634..1c46b951e47b6197db8234af4934d22854734a0d 100644 --- a/addons/l10n_account_edi_ubl_cii_tests/tests/test_xml_cii_fr.py +++ b/addons/l10n_account_edi_ubl_cii_tests/tests/test_xml_cii_fr.py @@ -283,6 +283,9 @@ class TestCIIFR(TestUBLCommon): # Test import #################################################### + def test_import_partner_facturx(self): + self._test_import_partner('facturx_1_0_05', 'factur-x.xml') + def test_import_tax_included(self): """ Tests whether the tax included / tax excluded are correctly decoded when diff --git a/addons/l10n_account_edi_ubl_cii_tests/tests/test_xml_ubl_be.py b/addons/l10n_account_edi_ubl_cii_tests/tests/test_xml_ubl_be.py index f983d40a8164122a2bd030bd7458526111e13e8c..4f458c1bb3900be4770326309c4b7448dab949da 100644 --- a/addons/l10n_account_edi_ubl_cii_tests/tests/test_xml_ubl_be.py +++ b/addons/l10n_account_edi_ubl_cii_tests/tests/test_xml_ubl_be.py @@ -213,6 +213,9 @@ class TestUBLBE(TestUBLCommon): # Test import #################################################### + def test_import_partner_ubl(self): + self._test_import_partner('ubl_bis3', 'INV_2017_01_0002_ubl_bis3.xml') + def test_import_export_invoice_xml(self): """ Test whether the elements only specific to ubl_be are correctly exported