Skip to content

Commit

Permalink
FIX l10n_it_fiscalcode check when e-commerce user sets 'company_name'
Browse files Browse the repository at this point in the history
  • Loading branch information
eLBati authored and TheMule71 committed Nov 11, 2022
1 parent ca82ce8 commit 89cc2c5
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 9 deletions.
2 changes: 1 addition & 1 deletion l10n_it_fiscalcode/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

{
'name': 'Italian Localization - Fiscal Code',
'version': '12.0.1.1.0',
'version': '12.0.1.1.1',
'development_status': 'Production/Stable',
'category': 'Localisation/Italy',
'author': "Link IT s.r.l., "
Expand Down
21 changes: 13 additions & 8 deletions l10n_it_fiscalcode/model/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,19 @@ class ResPartner(models.Model):
def check_fiscalcode(self):
for partner in self:
if not partner.fiscalcode:
return True
elif (
len(partner.fiscalcode) != 16 and
partner.company_type == 'person'
):
return False
else:
return True
# Because it is not mandatory
continue
elif partner.company_type == 'person':
# Person case
if partner.company_name:
# In E-commerce, if there is company_name,
# 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 True

fiscalcode = fields.Char(
'Fiscal Code', size=16, help="Italian Fiscal Code")
Expand Down
27 changes: 27 additions & 0 deletions l10n_it_fiscalcode/tests/test_fiscalcode.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo.tests.common import TransactionCase
from odoo.exceptions import ValidationError


class TestFiscalCode(TransactionCase):
Expand All @@ -24,3 +25,29 @@ def test_fiscalcode_compute(self):
# ---- Compute FiscalCode
wizard.compute_fc()
self.assertEqual(self.partner.fiscalcode, 'RSSMRA84H04H501X')

def test_fiscalcode_check(self):
# Wrong FC
with self.assertRaises(ValidationError):
self.env['res.partner'].create({
'name': 'Person',
'is_company': False,
'fiscalcode': '123',
})
# Correct FC
self.env['res.partner'].create({
'name': 'Person',
'is_company': False,
'fiscalcode': 'RSSMRA84H04H501X',
})
# Empty FC
self.env['res.partner'].create({
'name': 'Person',
})
# FC is VAT number
self.env['res.partner'].create({
'name': 'Person',
'company_name': 'Company',
'is_company': False,
'fiscalcode': '123456789',
})

0 comments on commit 89cc2c5

Please sign in to comment.