From 95e56d75ad25cef4c78dc7e64fd32f22da8bd673 Mon Sep 17 00:00:00 2001 From: "Touati Djamel (otd)" Date: Wed, 25 Aug 2021 12:27:18 +0000 Subject: [PATCH] [FIX] l10n_cl: correct Chilean VAT formatting Problem 1 steps to reproduce the bug: - Install `l10n_cl` - Create a new company - Choose for example Algeria in country. - Enter this VAT number: CL220604497 - Save - edit - Change the country to Chile problem: VAT number is not formatted according to the Chilean VAT formatting, Because in the write function we do not trigger the VAT formatting when the country changes Bug introduced in this commit: https://github.com/odoo/odoo/commit/11ec94df926db98265d26af1072a0c8bf1843083 Problem 2, steps to reproduce the bug: When you install `l10n_cl`, a Chilean company is created with these demo data: https://github.com/odoo/odoo/blob/7cc252908b33b7d77d45d0630464e203b25b09dc/addons/l10n_cl/demo/demo_company.x15ml#L - The VAT is formatted according to the standard formatting instead of the Chilean vat formatting, Because the field `" l10n_latam_identification_type_id "` is not defined: https://github.com/odoo/odoo/blob/f3a66dd65d041ffc7367d85d5603e9627efb9f2b/addons/l10n_cl/models/res_partner.py#L33-L34 so we will have this result: CL220604497 instead of 22060449-7 - create a vendor bill with this company - try to print it - a traceback is triggered, because we call the `_format_dotted_vat_cl` function which divides the vat in two parts based on the dash and then processes the result without checking that there are two elements in the result. As in our case here. The vat has no dash in the middle, so we will only have one part an error is triggered when the function tries to access the 2nd element https://github.com/odoo/odoo/blob/2b500c12c2540e593f3a243bf80de28bd335b7be/addons/l10n_cl/views/report_invoice.xml#L53 opw-2630877 closes odoo/odoo#75936 X-original-commit: d1369dbcc6c40297e7616b990aefa87a2eb4d5c3 Signed-off-by: Josse Colpaert Signed-off-by: Djamel Touati --- addons/l10n_cl/demo/demo_company.xml | 1 + addons/l10n_cl/models/res_partner.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/l10n_cl/demo/demo_company.xml b/addons/l10n_cl/demo/demo_company.xml index 3af9b3852cc..c8012e9b2b6 100644 --- a/addons/l10n_cl/demo/demo_company.xml +++ b/addons/l10n_cl/demo/demo_company.xml @@ -3,6 +3,7 @@ CL Company CL22060449-7 + 1 1 Santiago diff --git a/addons/l10n_cl/models/res_partner.py b/addons/l10n_cl/models/res_partner.py index 40ed3aab962..abb6f70d756 100644 --- a/addons/l10n_cl/models/res_partner.py +++ b/addons/l10n_cl/models/res_partner.py @@ -54,7 +54,7 @@ class ResPartner(models.Model): return super().create(values) def write(self, values): - if 'vat' in values or 'l10n_latam_identification_type_id' in values: + if any(field in values for field in ['vat', 'l10n_latam_identification_type_id', 'country_id']): for record in self: vat_values = { 'vat': values.get('vat', record.vat),