From 1e12160f12f75a6b856e82914e1bbfcca247bca3 Mon Sep 17 00:00:00 2001 From: Antoine Boonen Date: Thu, 4 Apr 2024 08:33:06 +0000 Subject: [PATCH] [FIX] account_edi_ubl_cii : Fix constraints Problem --------- Because of this PR: 155896, the customer default value for the UBL export values has been modified from commercial partner to partner. However, in 16.0, some constraints have been added to verify that some fields were properly set up before generating the XML. Those restrictions clash with the said changes. Indeed: 1 - Create NO company 2 - Set up UBL on invoice journal 3 - Create a new NO customer and set up UBL in the same way 4 - Create an invoicing address for that customer 5 - Create an invoice for with the customer set as the invoice address set up in step 3. 6 - Send & Print with UBL selected >> An error is added to the export errors while it should not. Solution --------- Use the commercial partner when checking constrains of all fields other than addresses. OPW-3848367 closes odoo/odoo#162591 X-original-commit: cb1ed8d37ee276b806e6fe874c348a2a434fd1e9 Signed-off-by: Julien Van Roy (juvr) Signed-off-by: Antoine Boonen (aboo) --- addons/account_edi_ubl_cii/i18n/account_edi_ubl_cii.pot | 7 +++++++ .../account_edi_ubl_cii/models/account_edi_xml_ubl_20.py | 3 +-- .../models/account_edi_xml_ubl_bis3.py | 8 ++++++-- .../l10n_dk_oioubl/models/account_edi_xml_oioubl_201.py | 8 ++++---- addons/l10n_ro_edi/models/account_edi_xml_ubl_ciusro.py | 6 +++--- 5 files changed, 21 insertions(+), 11 deletions(-) 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 3301079d921..ff8f521509d 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 @@ -816,6 +816,13 @@ msgstr "" msgid "The VAT of the %s should be prefixed with its country code." msgstr "" +#. module: account_edi_ubl_cii +#. odoo-python +#: code:addons/account_edi_ubl_cii/models/account_edi_xml_ubl_bis3.py:0 +#, python-format +msgid "The country is required for the %s." +msgstr "" + #. module: account_edi_ubl_cii #. odoo-python #: code:addons/account_edi_ubl_cii/models/account_edi_xml_cii_facturx.py:0 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 6b563c2299a..868adda38e3 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 @@ -578,8 +578,7 @@ class AccountEdiXmlUBL20(models.AbstractModel): constraints = self._invoice_constraints_common(invoice) constraints.update({ 'ubl20_supplier_name_required': self._check_required_fields(vals['supplier'], 'name'), - 'ubl20_customer_name_required': self._check_required_fields(vals['customer'], 'name'), - 'ubl20_commercial_customer_name_required': self._check_required_fields(vals['customer'].commercial_partner_id, 'name'), + 'ubl20_customer_name_required': self._check_required_fields(vals['customer'].commercial_partner_id, 'name'), 'ubl20_invoice_name_required': self._check_required_fields(invoice, 'name'), 'ubl20_invoice_date_required': self._check_required_fields(invoice, 'invoice_date'), }) diff --git a/addons/account_edi_ubl_cii/models/account_edi_xml_ubl_bis3.py b/addons/account_edi_ubl_cii/models/account_edi_xml_ubl_bis3.py index ff8de671ef8..b0bc82cd5da 100644 --- a/addons/account_edi_ubl_cii/models/account_edi_xml_ubl_bis3.py +++ b/addons/account_edi_ubl_cii/models/account_edi_xml_ubl_bis3.py @@ -335,7 +335,11 @@ class AccountEdiXmlUBLBIS3(models.AbstractModel): constraints.update({'cen_en16931_tax_line': _("Each invoice line shall have one and only one tax.")}) for role in ('supplier', 'customer'): - constraints[f'cen_en16931_{role}_country'] = self._check_required_fields(vals[role], 'country_id') + constraints[f'cen_en16931_{role}_country'] = self._check_required_fields( + vals['vals'][f'accounting_{role}_party_vals']['party_vals']['postal_address_vals']['country_vals'], + 'identification_code', + _("The country is required for the %s.", role) + ) scheme_vals = vals['vals'][f'accounting_{role}_party_vals']['party_vals']['party_tax_scheme_vals'][-1:] if ( not (scheme_vals and scheme_vals[0]['company_id'] and scheme_vals[0]['company_id'][:2].isalpha()) @@ -405,7 +409,7 @@ class AccountEdiXmlUBLBIS3(models.AbstractModel): 'nl_r_005': _( "%s should have a KVK or OIN number: the Peppol e-address (EAS) should be '0106' or '0190'.", vals['customer'].display_name - ) if vals['customer'].peppol_eas not in ('0106', '0190') else '', + ) if vals['customer'].commercial_partner_id.peppol_eas not in ('0106', '0190') else '', }) if vals['supplier'].country_id.code == 'NO': diff --git a/addons/l10n_dk_oioubl/models/account_edi_xml_oioubl_201.py b/addons/l10n_dk_oioubl/models/account_edi_xml_oioubl_201.py index 60571916ce9..7d9bfd70f97 100644 --- a/addons/l10n_dk_oioubl/models/account_edi_xml_oioubl_201.py +++ b/addons/l10n_dk_oioubl/models/account_edi_xml_oioubl_201.py @@ -271,11 +271,11 @@ class AccountEdiXmlOIOUBL201(models.AbstractModel): building_number = tools.street_split(partner.street).get('street_number') if not building_number: constraints[f"oioubl201_{partner_type}_building_number_required"] = \ - _("The following partner's street number is missing: %s", partner.name) - if partner.country_code == "FR" and not partner.company_registry: + _("The following partner's street number is missing: %s", partner.display_name) + if partner.country_code == "FR" and not partner.commercial_partner_id.company_registry: constraints["oioubl201_company_registry_required_for_french_partner"] = \ - _("The company registry is required for french partner: %s", partner.name) - constraints[f'oioubl201_{partner_type}_vat_required'] = self._check_required_fields(vals[partner_type], 'vat') + _("The company registry is required for french partner: %s", partner.display_name) + constraints[f'oioubl201_{partner_type}_vat_required'] = self._check_required_fields(partner.commercial_partner_id, 'vat') return constraints diff --git a/addons/l10n_ro_edi/models/account_edi_xml_ubl_ciusro.py b/addons/l10n_ro_edi/models/account_edi_xml_ubl_ciusro.py index e3d94cb2c64..ec4f4b0c992 100644 --- a/addons/l10n_ro_edi/models/account_edi_xml_ubl_ciusro.py +++ b/addons/l10n_ro_edi/models/account_edi_xml_ubl_ciusro.py @@ -97,11 +97,11 @@ class AccountEdiXmlUBLRO(models.AbstractModel): f"ciusro_{partner_type}_state_id_required": self._check_required_fields(partner, 'state_id'), }) - if not partner.vat and not partner.company_registry: + if not partner.commercial_partner_id.vat and not partner.commercial_partner_id.company_registry: constraints[f"ciusro_{partner_type}_tax_identifier_required"] = _( "The following partner doesn't have a VAT nor Company ID: %s. " "At least one of them is required. ", - partner.name) + partner.display_name) if (partner.country_code == 'RO' and partner.state_id @@ -111,6 +111,6 @@ class AccountEdiXmlUBLRO(models.AbstractModel): "The following partner's city name is invalid: %s. " "If partner's state is București, the city name must be 'SECTORX', " "where X is a number between 1-6.", - partner.name) + partner.display_name) return constraints