From b389016cd30d20beaeaf76edb22206f1a3c5d581 Mon Sep 17 00:00:00 2001 From: Renilkumar Kajavadra Date: Thu, 2 Nov 2023 16:28:59 +0530 Subject: [PATCH] [FIX] l10n_cl: prevent IndexError when creating customer When the user creates a new customer and enters "." in Identification Number, a traceback will appear. Steps to reproduce the error: - Install "l10n_cl" module - Switch to Chile Company - Go to Invoicing > Customers > Create New Customer > Enter Name > Select 'Chile' in Country > Enter "." in Identification Number > Save Error: A traceback appears: "IndexError: string index out of range" code reference: https://github.com/odoo/odoo/blob/276972f96d2eb1a65686e7319f601ed435b57b88/addons/l10n_cl/models/res_partner.py#L40 Here, when user enters "." in Identification Number then values['vat'] will be ".", So when it will try to .format(), It will lead to above traceback. sentry-4593791704 closes odoo/odoo#145262 X-original-commit: 1ca7ad1489154754a23086e1b0d47386bfb7c7e4 Signed-off-by: Josse Colpaert --- addons/l10n_cl/models/res_partner.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/l10n_cl/models/res_partner.py b/addons/l10n_cl/models/res_partner.py index 695b24d261c..3c048c959d1 100644 --- a/addons/l10n_cl/models/res_partner.py +++ b/addons/l10n_cl/models/res_partner.py @@ -37,7 +37,8 @@ class ResPartner(models.Model): ) partner_country_is_chile = country.code == "CL" or identification_type.country_id.code == "CL" if partner_country_is_chile and \ - values.get('l10n_latam_identification_type_id') in identification_types and values.get('vat'): + values.get('l10n_latam_identification_type_id') in identification_types and values.get('vat') and\ + stdnum.util.get_cc_module('cl', 'vat').is_valid(values['vat']): return stdnum.util.get_cc_module('cl', 'vat').format(values['vat']).replace('.', '').replace( 'CL', '').upper() else: