[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 <jco@odoo.com>
This commit is contained in:
Renilkumar Kajavadra
2023-12-06 19:30:05 +00:00
committed by reka-odoo
parent fcc698c8ed
commit b389016cd3
+2 -1
View File
@@ -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: