Skip to content

Commit

Permalink
[IMP] l10n_it_fiscalcode: add codicefiscale.isvalid()
Browse files Browse the repository at this point in the history
  • Loading branch information
odooNextev committed Mar 4, 2024
1 parent ac94d16 commit 04226ba
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion l10n_it_fatturapa_in/tests/test_import_fatturapa_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,7 @@ def test_56_xml_import_vat_group(self):
)
existing_partners.update({
'vat': 'IT12345670017',
'fiscalcode': '1234567890123456',
'fiscalcode': 'TSTCOA80R07I829X',
})

# Act: Import the XMLs,
Expand Down
12 changes: 10 additions & 2 deletions l10n_it_fiscalcode/model/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

from codicefiscale import isvalid

from odoo import models, fields, api
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError


class ResPartner(models.Model):
Expand All @@ -21,7 +22,14 @@ def check_fiscalcode(self):
# the user might insert VAT in fiscalcode field.
# Perform the same check as Company case
continue
return isvalid(partner.fiscalcode)
if len(partner.fiscalcode) != 16:
# Check fiscalcode length of a person
msg = _("The fiscal code must have 16 characters.")
raise ValidationError(msg)
if not isvalid(partner.fiscalcode):
# Check fiscalcode validity
msg = _("The fiscal code isn't valid.")
raise ValidationError(msg)
return True

fiscalcode = fields.Char(
Expand Down

0 comments on commit 04226ba

Please sign in to comment.