Skip to content
Snippets Groups Projects
Commit 8a098afa authored by Andrea Grazioso (agr-odoo)'s avatar Andrea Grazioso (agr-odoo) Committed by fw-bot
Browse files

[FIX] l10n_co: crash when adding contact


Install l10n_co,contacts. Open contacts.

Several crash messages will popup because the override in l10n_co of
res_partner is not computing the 'l10n_co_verification_code' field for
every record. Changing the implementation to be sure to store some value
for every record fix the issue.

opw-2082583

closes odoo/odoo#38473

X-original-commit: 2489c405
Signed-off-by: default avatarNicolas Martinelli (nim) <nim@odoo.com>
parent 3fa123d6
No related branches found
No related tags found
No related merge requests found
......@@ -24,26 +24,28 @@ class ResPartner(models.Model):
def _compute_verification_code(self):
multiplication_factors = [71, 67, 59, 53, 47, 43, 41, 37, 29, 23, 19, 17, 13, 7, 3]
for partner in self.filtered(lambda partner: partner.vat and partner.country_id == self.env.ref('base.co') and
len(partner.vat) <= len(multiplication_factors)):
number = 0
padded_vat = partner.vat
while len(padded_vat) < len(multiplication_factors):
padded_vat = '0' + padded_vat
# if there is a single non-integer in vat the verification code should be False
try:
for index, vat_number in enumerate(padded_vat):
number += int(vat_number) * multiplication_factors[index]
number %= 11
if number < 2:
partner.l10n_co_verification_code = number
else:
partner.l10n_co_verification_code = 11 - number
except ValueError:
for partner in self:
if partner.vat and partner.country_id == self.env.ref('base.co') and len(partner.vat) <= len(multiplication_factors):
number = 0
padded_vat = partner.vat
while len(padded_vat) < len(multiplication_factors):
padded_vat = '0' + padded_vat
# if there is a single non-integer in vat the verification code should be False
try:
for index, vat_number in enumerate(padded_vat):
number += int(vat_number) * multiplication_factors[index]
number %= 11
if number < 2:
partner.l10n_co_verification_code = number
else:
partner.l10n_co_verification_code = 11 - number
except ValueError:
partner.l10n_co_verification_code = False
else:
partner.l10n_co_verification_code = False
@api.constrains('vat', 'country_id', 'l10n_co_document_type')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment