Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP] l10n_it_fiscalcode: update library to check fiscalcode #4511

Open
wants to merge 3 commits into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified l10n_it_fatturapa_import_zip/tests/data/xml_import.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion l10n_it_fatturapa_in/tests/data/IT05979361218_003.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ xsi:schemaLocation="http://ivaservizi.agenziaentrate.gov.it/docs/xsd/fatture/v1.
<IdPaese>IT</IdPaese>
<IdCodice>03533590174</IdCodice>
</IdFiscaleIVA>
<CodiceFiscale>MRORSS90E25B111T</CodiceFiscale>
<CodiceFiscale>MRORSS90E25B111K</CodiceFiscale>
<Anagrafica>
<Nome>MARIO</Nome>
<Cognome>ROSSI</Cognome>
Expand Down
2 changes: 1 addition & 1 deletion l10n_it_fatturapa_in/tests/data/IT05979361218_004.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ xsi:schemaLocation="http://ivaservizi.agenziaentrate.gov.it/docs/xsd/fatture/v1.
<IdPaese>IT</IdPaese>
<IdCodice>03533590174</IdCodice>
</IdFiscaleIVA>
<CodiceFiscale>MRORSS90E25B111T</CodiceFiscale>
<CodiceFiscale>MRORSS90E25B111K</CodiceFiscale>
<Anagrafica>
<Nome>MARIO</Nome>
<Cognome>ROSSI</Cognome>
Expand Down
44 changes: 22 additions & 22 deletions l10n_it_fiscalcode/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ fragment is included. ]
16.0.1.0.0 (2022-11-11)
-----------------------

- [MIG] Migration from Odoo 14.0 to 16.0
- [IMP] Black, isort, prettier (pre-commit)
- [MIG] Migration from Odoo 14.0 to 16.0
- [IMP] Black, isort, prettier (pre-commit)

16.0.1.0.1 (2022-11-16)
-----------------------

- [IMP] Add codicefiscale.isvalid() to improve fiscalcode validation
- [IMP] Add codicefiscale.isvalid() to improve fiscalcode validation

Bug Tracker
===========
Expand All @@ -116,25 +116,25 @@ Authors
Contributors
------------

- Davide Corio
- Luca Subiaco <[email protected]>
- Simone Orsi <[email protected]>
- Mario Riva <[email protected]>
- Mauro Soligo <[email protected]>
- Giovanni Barzan <[email protected]>
- Lorenzo Battistini <[email protected]>
- Roberto Onnis <[email protected]>
- Franco Tampieri
- Andrea Cometa <[email protected]>
- Andrea Gallina
- Matteo Bilotta <[email protected]>
- Giuseppe Borruso - Dinamiche Aziendali srl
<[email protected]>
- Alex Comba <[email protected]>
- Marco Colombo <[email protected]>
- `Aion Tech <https://aiontech.company/>`__:

- Simone Rubino <[email protected]>
- Davide Corio
- Luca Subiaco <[email protected]>
- Simone Orsi <[email protected]>
- Mario Riva <[email protected]>
- Mauro Soligo <[email protected]>
- Giovanni Barzan <[email protected]>
- Lorenzo Battistini <[email protected]>
- Roberto Onnis <[email protected]>
- Franco Tampieri
- Andrea Cometa <[email protected]>
- Andrea Gallina
- Matteo Bilotta <[email protected]>
- Giuseppe Borruso - Dinamiche Aziendali srl
<[email protected]>
- Alex Comba <[email protected]>
- Marco Colombo <[email protected]>
- `Aion Tech <https://aiontech.company/>`__:

- Simone Rubino <[email protected]>

Maintainers
-----------
Expand Down
2 changes: 1 addition & 1 deletion l10n_it_fiscalcode/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"license": "AGPL-3",
"depends": ["account"],
"external_dependencies": {
"python": ["codicefiscale"],
"python": ["python-codicefiscale"],
},
"data": [
"security/ir.model.access.csv",
Expand Down
4 changes: 2 additions & 2 deletions l10n_it_fiscalcode/model/res_partner.py
Original file line number Diff line number Diff line change
@@ -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 import _, api, fields, models
from odoo.exceptions import ValidationError
Expand Down Expand Up @@ -30,7 +30,7 @@ def check_fiscalcode(self):
# Check fiscalcode length of a person
msg = _("The fiscal code must have 16 characters.")
raise ValidationError(msg)
if not isvalid(partner.fiscalcode):
if not codicefiscale.is_valid(partner.fiscalcode):
# Check fiscalcode validity
msg = _("The fiscal code isn't valid.")
raise ValidationError(msg)
Expand Down
11 changes: 7 additions & 4 deletions l10n_it_fiscalcode/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

/*
:Author: David Goodger ([email protected])
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Copyright: This stylesheet has been placed in the public domain.

Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.

See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
Expand Down Expand Up @@ -274,7 +275,7 @@
margin-left: 2em ;
margin-right: 2em }

pre.code .ln { color: grey; } /* line numbers */
pre.code .ln { color: gray; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
Expand All @@ -300,7 +301,7 @@
span.pre {
white-space: pre }

span.problematic {
span.problematic, pre.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -484,7 +485,9 @@ <h2><a class="toc-backref" href="#toc-entry-9">Contributors</a></h2>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-10">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<p>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.</p>
Expand Down
16 changes: 13 additions & 3 deletions l10n_it_fiscalcode/tests/test_fiscalcode.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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):
"""
Expand All @@ -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:
Expand All @@ -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:
Expand Down
24 changes: 12 additions & 12 deletions l10n_it_fiscalcode/wizard/compute_fc.py
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -185,16 +178,23 @@
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

Check warning on line 191 in l10n_it_fiscalcode/wizard/compute_fc.py

View check run for this annotation

Codecov / codecov/patch

l10n_it_fiscalcode/wizard/compute_fc.py#L191

Added line #L191 was not covered by tests

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:
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# generated from manifests external_dependencies
asn1crypto
codicefiscale
elementpath
mock
openupgradelib
python-codicefiscale
unidecode
xmlschema
Loading