[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) <juvr@odoo.com>
Signed-off-by: Antoine Boonen (aboo) <aboo@odoo.com>
This commit is contained in:
Antoine Boonen
2024-04-24 07:55:44 +00:00
parent f95cff0836
commit 1e12160f12
5 changed files with 21 additions and 11 deletions
@@ -816,6 +816,13 @@ msgstr ""
msgid "The VAT of the %s should be prefixed with its country code." msgid "The VAT of the %s should be prefixed with its country code."
msgstr "" 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 #. module: account_edi_ubl_cii
#. odoo-python #. odoo-python
#: code:addons/account_edi_ubl_cii/models/account_edi_xml_cii_facturx.py:0 #: code:addons/account_edi_ubl_cii/models/account_edi_xml_cii_facturx.py:0
@@ -578,8 +578,7 @@ class AccountEdiXmlUBL20(models.AbstractModel):
constraints = self._invoice_constraints_common(invoice) constraints = self._invoice_constraints_common(invoice)
constraints.update({ constraints.update({
'ubl20_supplier_name_required': self._check_required_fields(vals['supplier'], 'name'), 'ubl20_supplier_name_required': self._check_required_fields(vals['supplier'], 'name'),
'ubl20_customer_name_required': self._check_required_fields(vals['customer'], 'name'), 'ubl20_customer_name_required': self._check_required_fields(vals['customer'].commercial_partner_id, 'name'),
'ubl20_commercial_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_name_required': self._check_required_fields(invoice, 'name'),
'ubl20_invoice_date_required': self._check_required_fields(invoice, 'invoice_date'), 'ubl20_invoice_date_required': self._check_required_fields(invoice, 'invoice_date'),
}) })
@@ -335,7 +335,11 @@ class AccountEdiXmlUBLBIS3(models.AbstractModel):
constraints.update({'cen_en16931_tax_line': _("Each invoice line shall have one and only one tax.")}) constraints.update({'cen_en16931_tax_line': _("Each invoice line shall have one and only one tax.")})
for role in ('supplier', 'customer'): 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:] scheme_vals = vals['vals'][f'accounting_{role}_party_vals']['party_vals']['party_tax_scheme_vals'][-1:]
if ( if (
not (scheme_vals and scheme_vals[0]['company_id'] and scheme_vals[0]['company_id'][:2].isalpha()) 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': _( 'nl_r_005': _(
"%s should have a KVK or OIN number: the Peppol e-address (EAS) should be '0106' or '0190'.", "%s should have a KVK or OIN number: the Peppol e-address (EAS) should be '0106' or '0190'.",
vals['customer'].display_name 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': if vals['supplier'].country_id.code == 'NO':
@@ -271,11 +271,11 @@ class AccountEdiXmlOIOUBL201(models.AbstractModel):
building_number = tools.street_split(partner.street).get('street_number') building_number = tools.street_split(partner.street).get('street_number')
if not building_number: if not building_number:
constraints[f"oioubl201_{partner_type}_building_number_required"] = \ constraints[f"oioubl201_{partner_type}_building_number_required"] = \
_("The following partner's street number is missing: %s", partner.name) _("The following partner's street number is missing: %s", partner.display_name)
if partner.country_code == "FR" and not partner.company_registry: if partner.country_code == "FR" and not partner.commercial_partner_id.company_registry:
constraints["oioubl201_company_registry_required_for_french_partner"] = \ constraints["oioubl201_company_registry_required_for_french_partner"] = \
_("The company registry is required for french partner: %s", partner.name) _("The company registry is required for french partner: %s", partner.display_name)
constraints[f'oioubl201_{partner_type}_vat_required'] = self._check_required_fields(vals[partner_type], 'vat') constraints[f'oioubl201_{partner_type}_vat_required'] = self._check_required_fields(partner.commercial_partner_id, 'vat')
return constraints return constraints
@@ -97,11 +97,11 @@ class AccountEdiXmlUBLRO(models.AbstractModel):
f"ciusro_{partner_type}_state_id_required": self._check_required_fields(partner, 'state_id'), 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"] = _( constraints[f"ciusro_{partner_type}_tax_identifier_required"] = _(
"The following partner doesn't have a VAT nor Company ID: %s. " "The following partner doesn't have a VAT nor Company ID: %s. "
"At least one of them is required. ", "At least one of them is required. ",
partner.name) partner.display_name)
if (partner.country_code == 'RO' if (partner.country_code == 'RO'
and partner.state_id and partner.state_id
@@ -111,6 +111,6 @@ class AccountEdiXmlUBLRO(models.AbstractModel):
"The following partner's city name is invalid: %s. " "The following partner's city name is invalid: %s. "
"If partner's state is București, the city name must be 'SECTORX', " "If partner's state is București, the city name must be 'SECTORX', "
"where X is a number between 1-6.", "where X is a number between 1-6.",
partner.name) partner.display_name)
return constraints return constraints