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 authored and OCA-git-bot committed Jan 25, 2024
1 parent de1b89c commit f8c56f9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
6 changes: 3 additions & 3 deletions l10n_it_fiscalcode/model/res_partner.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from codicefiscale import isvalid

from odoo import models, fields, api


Expand All @@ -19,9 +21,7 @@ def check_fiscalcode(self):
# the user might insert VAT in fiscalcode field.
# Perform the same check as Company case
continue
if len(partner.fiscalcode) != 16:
# Check fiscalcode of a person
return False
return isvalid(partner.fiscalcode)
return True

fiscalcode = fields.Char(
Expand Down
11 changes: 10 additions & 1 deletion l10n_it_fiscalcode/tests/test_fiscalcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_fiscalcode_compute(self):
self.assertEqual(self.partner.fiscalcode, 'RSSMRA84H04H501X')

def test_fiscalcode_check(self):
# Wrong FC
# Wrong FC length
with self.assertRaises(ValidationError):
self.env['res.partner'].create({
'name': 'Person',
Expand All @@ -51,3 +51,12 @@ def test_fiscalcode_check(self):
'is_company': False,
'fiscalcode': '123456789',
})
# Invalid FC
with self.assertRaises(ValidationError):
self.env["res.partner"].create(
{
"name": "Person",
"is_company": False,
"fiscalcode": "AAAMRA00H04H5010",
}
)

0 comments on commit f8c56f9

Please sign in to comment.