From dd7df8122f1854d47aef5114f20e4ba0ac4fe991 Mon Sep 17 00:00:00 2001 From: aliya Date: Tue, 23 May 2023 11:15:31 +0000 Subject: [PATCH] [FIX] account_edi_ubl_cii: fix partner creation during import If a partner in the imported invoice does not exist, we create one on the fly. However, the partner is created without a country and `_run_vat_test` doesn't check it properly in 15.0, and fails in later versions, where we try to get the country code from the country we pass from `_import_retrieve_and_fill_partner`, which is `False`. This commit retrieves the country from the imported invoice to create the partner and passes the object instead of the `country_code` string to `_run_vat_test` closes odoo/odoo#122410 X-original-commit: fc1f9b15e54794b1029daffa3719b2f30873ee0a Signed-off-by: Laurent Smet Signed-off-by: Aliya Tastemirova (alta) --- .../account_edi_ubl_cii/models/account_edi_common.py | 11 +++++++---- .../models/account_edi_xml_ubl_20.py | 3 ++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/addons/account_edi_ubl_cii/models/account_edi_common.py b/addons/account_edi_ubl_cii/models/account_edi_common.py index 97fdb1ee2e7..30a007296ea 100644 --- a/addons/account_edi_ubl_cii/models/account_edi_common.py +++ b/addons/account_edi_ubl_cii/models/account_edi_common.py @@ -347,14 +347,17 @@ class AccountEdiCommon(models.AbstractModel): return True - def _import_retrieve_and_fill_partner(self, invoice, name, phone, mail, vat): + def _import_retrieve_and_fill_partner(self, invoice, name, phone, mail, vat, country_code=False): """ Retrieve the partner, if no matching partner is found, create it (only if he has a vat and a name) """ invoice.partner_id = self.env['res.partner']._retrieve_partner(name=name, phone=phone, mail=mail, vat=vat) if not invoice.partner_id and name and vat: - invoice.partner_id = self.env['res.partner'].create({'name': name, 'email': mail, 'phone': phone}) - country_code = invoice.partner_id.commercial_partner_id.country_code - if vat and self.env['res.partner']._run_vat_test(vat, country_code, invoice.partner_id.is_company): + partner_vals = {'name': name, 'email': mail, 'phone': phone} + country = self.env.ref(f'base.{country_code.lower()}', raise_if_not_found=False) if country_code else False + if country: + partner_vals['country_id'] = country.id + invoice.partner_id = self.env['res.partner'].create(partner_vals) + if vat and self.env['res.partner']._run_vat_test(vat, country, invoice.partner_id.is_company): invoice.partner_id.vat = vat def _import_fill_invoice_allowance_charge(self, tree, invoice, qty_factor): 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 30cece99da2..7a528c5efc5 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 @@ -485,7 +485,8 @@ class AccountEdiXmlUBL20(models.AbstractModel): phone = _find_value(f'//cac:Accounting{role}Party/cac:Party//cbc:Telephone') mail = _find_value(f'//cac:Accounting{role}Party/cac:Party//cbc:ElectronicMail') name = _find_value(f'//cac:Accounting{role}Party/cac:Party//cbc:Name') - self._import_retrieve_and_fill_partner(invoice, name=name, phone=phone, mail=mail, vat=vat) + country_code = _find_value(f'//cac:Accounting{role}Party/cac:Party//cac:Country//cbc:IdentificationCode') + self._import_retrieve_and_fill_partner(invoice, name=name, phone=phone, mail=mail, vat=vat, country_code=country_code) # ==== currency_id ====