Maintainers
This module is maintained by the OCA.
- + + +OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.
diff --git a/l10n_it_fiscalcode/tests/test_fiscalcode.py b/l10n_it_fiscalcode/tests/test_fiscalcode.py index dbbcbd4713a2..e6a206f8682f 100644 --- a/l10n_it_fiscalcode/tests/test_fiscalcode.py +++ b/l10n_it_fiscalcode/tests/test_fiscalcode.py @@ -1,7 +1,7 @@ # Copyright 2024 Simone Rubino - Aion Tech # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -from codicefiscale import isvalid +from codicefiscale import codicefiscale from odoo.exceptions import ValidationError from odoo.tests.common import TransactionCase @@ -75,6 +75,16 @@ def test_fiscalcode_check(self): "fiscalcode": "AAAMRA00H04H5010", } ) + # Omocode FC - Test if an omocode fiscalcode is considered valid + # Fiscalcode in this test is get from + # https://pypi.org/project/python-codicefiscale/ examples + self.env["res.partner"].create( + { + "name": "Person", + "is_company": False, + "fiscalcode": "CCCFBA85D03L21VE", + } + ) def test_fiscal_code_check_change_to_person(self): """ @@ -91,7 +101,7 @@ def test_fiscal_code_check_change_to_person(self): ) partner.fiscalcode = wrong_person_fiscalcode # pre-condition - self.assertFalse(isvalid(partner.fiscalcode)) + self.assertFalse(codicefiscale.is_valid(partner.fiscalcode)) # Act with self.assertRaises(ValidationError) as ve: @@ -118,7 +128,7 @@ def test_fiscal_code_check_company_VAT_change_to_person(self): ) partner.fiscalcode = company_vat # pre-condition - self.assertFalse(isvalid(partner.fiscalcode)) + self.assertFalse(codicefiscale.is_valid(partner.fiscalcode)) # Act with self.assertRaises(ValidationError) as ve: diff --git a/l10n_it_fiscalcode/wizard/compute_fc.py b/l10n_it_fiscalcode/wizard/compute_fc.py index 2271a985df4a..307b52fb5cad 100644 --- a/l10n_it_fiscalcode/wizard/compute_fc.py +++ b/l10n_it_fiscalcode/wizard/compute_fc.py @@ -1,23 +1,16 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +import datetime import logging +from codicefiscale import codicefiscale + from odoo import _, api, fields, models from odoo.exceptions import UserError from odoo.osv import expression _logger = logging.getLogger(__name__) -try: - from codicefiscale import build - -except ImportError: - _logger.warning( - "codicefiscale library not found. " - "If you plan to use it, please install the codicefiscale library" - " from https://pypi.python.org/pypi/codicefiscale" - ) - class WizardComputeFc(models.TransientModel): _name = "wizard.compute.fc" @@ -185,16 +178,23 @@ def compute_fc(self): or not f.sex ): raise UserError(_("One or more fields are missing")) + nat_code = self._get_national_code( f.birth_city.name, f.birth_province.code, f.birth_date ) if not nat_code: raise UserError(_("National code is missing")) - c_f = build( + + if isinstance(f.birth_date, datetime.date): + birth_date = f.birth_date.strftime("%d/%m/%Y") + else: + birth_date = f.birth_date + + c_f = codicefiscale.encode( f.fiscalcode_surname, f.fiscalcode_firstname, - f.birth_date, f.sex, + birth_date, nat_code, ) if partner.fiscalcode and partner.fiscalcode != c_f: diff --git a/requirements.txt b/requirements.txt index 7052f10569c4..f66bf0b0d4e1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,8 +1,8 @@ # generated from manifests external_dependencies asn1crypto -codicefiscale elementpath mock openupgradelib +python-codicefiscale unidecode xmlschema