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

[16.0] [FIX] l10n_it_fatturapa_in: Il codice fiscale non sembra corretto #3996

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
2 changes: 1 addition & 1 deletion l10n_it_fatturapa_in/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ Authors
Contributors
------------

- Lorenzo Battistini <[email protected]>
- Lorenzo Battistini
- Roberto Onnis
- Alessio Gerace
- Sergio Zanchetta <https://github.com/primes2h>
Expand Down
2 changes: 2 additions & 0 deletions l10n_it_fatturapa_in/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Copyright 2018 Lorenzo Battistini
# Copyright 2018 Sergio Zanchetta (Associazione PNLUG - Gruppo Odoo)
# Copyright 2022 Marco Colombo (<[email protected]>)
# Copyright 2023 Simone Rubino - TAKOBI
# Copyright 2024 Simone Rubino - Aion Tech
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

Expand All @@ -18,6 +19,7 @@
"depends": [
"base_vat",
"mail",
"l10n_it_fiscalcode",
"l10n_it_fatturapa",
"l10n_it_fiscal_document_type",
"l10n_it_withholding_tax_reason",
Expand Down
2 changes: 1 addition & 1 deletion l10n_it_fatturapa_in/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
- Lorenzo Battistini \<<[email protected]>\>
- Lorenzo Battistini
- Roberto Onnis
- Alessio Gerace
- Sergio Zanchetta \<<https://github.com/primes2h>\>
Expand Down
2 changes: 1 addition & 1 deletion l10n_it_fatturapa_in/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ <h2><a class="toc-backref" href="#toc-entry-7">Authors</a></h2>
<div class="section" id="contributors">
<h2><a class="toc-backref" href="#toc-entry-8">Contributors</a></h2>
<ul class="simple">
<li>Lorenzo Battistini &lt;<a class="reference external" href="mailto:lorenzo.battistini&#64;agilebg.com">lorenzo.battistini&#64;agilebg.com</a>&gt;</li>
<li>Lorenzo Battistini</li>
<li>Roberto Onnis</li>
<li>Alessio Gerace</li>
<li>Sergio Zanchetta &lt;<a class="reference external" href="https://github.com/primes2h">https://github.com/primes2h</a>&gt;</li>
Expand Down
98 changes: 98 additions & 0 deletions l10n_it_fatturapa_in/tests/data/IT04333730275_FPR17.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type='text/xsl' href='fatturapa_v1.2.xsl'?>
<p:FatturaElettronica versione="FPR12" xmlns:p="http://ivaservizi.agenziaentrate.gov.it/docs/xsd/fatture/v1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<FatturaElettronicaHeader>
<DatiTrasmissione>
<IdTrasmittente>
<IdPaese>IT</IdPaese>
<IdCodice>04333730275</IdCodice>
</IdTrasmittente>
<ProgressivoInvio>qtungosjgi</ProgressivoInvio>
<FormatoTrasmissione>FPR12</FormatoTrasmissione>
<CodiceDestinatario>ZG4QBXW</CodiceDestinatario>
<ContattiTrasmittente>
</ContattiTrasmittente>
</DatiTrasmissione>
<CedentePrestatore>
<DatiAnagrafici>
<IdFiscaleIVA>
<IdPaese>IT</IdPaese>
<IdCodice>04333730275</IdCodice>
</IdFiscaleIVA>
<CodiceFiscale>04333730275</CodiceFiscale>
<Anagrafica>
<Nome><![CDATA[NOME]]></Nome>
<Cognome><![CDATA[Cognome]]></Cognome>
</Anagrafica>
<RegimeFiscale>RF01</RegimeFiscale>
</DatiAnagrafici>
<Sede>
<Indirizzo>VIALE ROMA 543B</Indirizzo>
<CAP>07100</CAP>
<Comune>SASSARI</Comune>
<Provincia>SS</Provincia>
<Nazione></Nazione>
</Sede>
<Contatti>
</Contatti>
</CedentePrestatore>
<CessionarioCommittente>
<DatiAnagrafici>
<IdFiscaleIVA>
<IdPaese>IT</IdPaese>
<IdCodice>10538570960</IdCodice>
</IdFiscaleIVA>
<CodiceFiscale>10538570960</CodiceFiscale>
<Anagrafica>
<Denominazione><![CDATA[AZIENDA]]></Denominazione>
</Anagrafica>
</DatiAnagrafici>
<Sede>
<Indirizzo>VIA TORINO 38-B</Indirizzo>
<CAP>00145</CAP>
<Comune>ROMA</Comune>
<Provincia>RM</Provincia>
<Nazione>IT</Nazione>
</Sede>
</CessionarioCommittente>
<SoggettoEmittente>TZ</SoggettoEmittente>
</FatturaElettronicaHeader>
<FatturaElettronicaBody>
<DatiGenerali>
<DatiGeneraliDocumento>
<TipoDocumento>TD01</TipoDocumento>
<Divisa>EUR</Divisa>
<Data>2023-08-17</Data>
<Numero>177</Numero>
<ImportoTotaleDocumento>679.14</ImportoTotaleDocumento>
</DatiGeneraliDocumento>
</DatiGenerali>
<DatiBeniServizi>
<DettaglioLinee>
<NumeroLinea>10</NumeroLinea>
<Descrizione><![CDATA[TORTA]]></Descrizione>
<Quantita>34.30000000</Quantita>
<UnitaMisura>KG</UnitaMisura>
<PrezzoUnitario>18.00000000</PrezzoUnitario>
<PrezzoTotale>617.40000000</PrezzoTotale>
<AliquotaIVA>10.00</AliquotaIVA>
</DettaglioLinee>
<DatiRiepilogo>
<AliquotaIVA>10.00</AliquotaIVA>
<ImponibileImporto>617.40</ImponibileImporto>
<Imposta>61.74</Imposta>
<EsigibilitaIVA>I</EsigibilitaIVA>
</DatiRiepilogo>
</DatiBeniServizi>
<DatiPagamento>
<CondizioniPagamento>TP02</CondizioniPagamento>
<DettaglioPagamento>
<ModalitaPagamento>MP05</ModalitaPagamento>
<DataRiferimentoTerminiPagamento>2023-08-17</DataRiferimentoTerminiPagamento>
<GiorniTerminiPagamento>44</GiorniTerminiPagamento>
<DataScadenzaPagamento>2023-09-30</DataScadenzaPagamento>
<ImportoPagamento>679.14</ImportoPagamento>
</DettaglioPagamento>
</DatiPagamento>
</FatturaElettronicaBody>
</p:FatturaElettronica>
16 changes: 16 additions & 0 deletions l10n_it_fatturapa_in/tests/test_import_fatturapa_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,22 @@ def test_ignore_global_discount(self):
self.assertEqual(invoice.amount_tax, 5.12)
self.assertEqual(invoice.amount_total, 28.39)

def test_xml_import_missing_Denominazione(self):
"""When CedentePrestatore has no Denominazione and the Fiscal Code of a Company,
it is imported as a Company.
"""
res = self.run_wizard(
"test_xml_import_missing_Denominazione",
"IT04333730275_FPR17.xml",
)
bill_model = res.get("res_model")
bill_domain = res.get("domain")
bill = self.env[bill_model].search(bill_domain)

partner = bill.partner_id
self.assertTrue(partner.is_company)
self.assertEqual(partner.fiscalcode, "04333730275")


class TestFatturaPAEnasarco(FatturapaCommon):
def setUp(self):
Expand Down
13 changes: 9 additions & 4 deletions l10n_it_fatturapa_in/wizard/wizard_import_fatturapa.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2022 Simone Rubino - TAKOBI
# Copyright 2022 ~ 2023 Simone Rubino - TAKOBI
# Copyright 2024 Simone Rubino - Aion Tech
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

Expand All @@ -14,6 +14,7 @@
from odoo.tools.translate import _

from odoo.addons.base_iban.models.res_partner_bank import pretty_iban
from odoo.addons.l10n_it_fiscalcode.model.res_partner import _check_company_fiscal_code

_logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -299,12 +300,16 @@ def getPartnerBase(self, DatiAnagrafici): # noqa: C901
raise UserError(
_("Country Code %s not found in system.") % CountryCode
)
if cf:
is_company = _check_company_fiscal_code(cf)
else:
# This is a weaker condition because
# Denominazione is also present when the partner is a person.
is_company = bool(DatiAnagrafici.Anagrafica.Denominazione)
vals = {
"vat": vat,
"fiscalcode": cf,
"is_company": (
DatiAnagrafici.Anagrafica.Denominazione and True or False
),
"is_company": is_company,
"eori_code": DatiAnagrafici.Anagrafica.CodEORI or "",
"country_id": country_id,
}
Expand Down
2 changes: 1 addition & 1 deletion l10n_it_fiscalcode/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ Contributors
- Mario Riva <[email protected]>
- Mauro Soligo <[email protected]>
- Giovanni Barzan <[email protected]>
- Lorenzo Battistini <[email protected]>
- Lorenzo Battistini
- Roberto Onnis <[email protected]>
- Franco Tampieri
- Andrea Cometa <[email protected]>
Expand Down
25 changes: 21 additions & 4 deletions l10n_it_fiscalcode/model/res_partner.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Copyright 2023 Simone Rubino - TAKOBI
# Copyright 2024 Simone Rubino - Aion Tech
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

Expand All @@ -7,6 +8,16 @@
from odoo.exceptions import ValidationError


def _check_company_fiscal_code(fiscal_code):
"""`fiscal_code` is the Fiscal Code of a Company."""
return len(fiscal_code) == 11


def _check_person_fiscal_code(fiscal_code):
"""`fiscal_code` is the Fiscal Code of a Person."""
return len(fiscal_code) == 16


class ResPartner(models.Model):
_inherit = "res.partner"

Expand All @@ -16,24 +27,30 @@ class ResPartner(models.Model):
)
def check_fiscalcode(self):
for partner in self:
if not partner.fiscalcode:
fiscal_code = partner.fiscalcode
if not fiscal_code:
# 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:
if not _check_company_fiscal_code(fiscal_code):
raise ValidationError(
_("The fiscal code must have 11 characters.")
)
elif not _check_person_fiscal_code(fiscal_code):
# 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)
elif partner.company_type == "company":
if not _check_company_fiscal_code(fiscal_code):
raise ValidationError(_("The fiscal code must have 11 characters."))
return True

fiscalcode = fields.Char("Fiscal Code", size=16, help="Italian Fiscal Code")
Expand Down
2 changes: 1 addition & 1 deletion l10n_it_fiscalcode/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
- Mario Riva \<<[email protected]>\>
- Mauro Soligo \<<[email protected]>\>
- Giovanni Barzan \<<[email protected]>\>
- Lorenzo Battistini \<<[email protected]>\>
- Lorenzo Battistini
- Roberto Onnis \<<[email protected]>\>
- Franco Tampieri
- Andrea Cometa \<<[email protected]>\>
Expand Down
2 changes: 1 addition & 1 deletion l10n_it_fiscalcode/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ <h2><a class="toc-backref" href="#toc-entry-9">Contributors</a></h2>
<li>Mario Riva &lt;<a class="reference external" href="mailto:mario.riva&#64;agilebg.com">mario.riva&#64;agilebg.com</a>&gt;</li>
<li>Mauro Soligo &lt;<a class="reference external" href="mailto:mauro.soligo&#64;katodo.com">mauro.soligo&#64;katodo.com</a>&gt;</li>
<li>Giovanni Barzan &lt;<a class="reference external" href="mailto:giovanni.barzan&#64;gmail.com">giovanni.barzan&#64;gmail.com</a>&gt;</li>
<li>Lorenzo Battistini &lt;<a class="reference external" href="mailto:lorenzo.battistini&#64;agilebg.com">lorenzo.battistini&#64;agilebg.com</a>&gt;</li>
<li>Lorenzo Battistini</li>
<li>Roberto Onnis &lt;<a class="reference external" href="mailto:onnis.roberto&#64;gmail.com">onnis.roberto&#64;gmail.com</a>&gt;</li>
<li>Franco Tampieri</li>
<li>Andrea Cometa &lt;<a class="reference external" href="mailto:info&#64;andreacometa.it">info&#64;andreacometa.it</a>&gt;</li>
Expand Down
27 changes: 25 additions & 2 deletions l10n_it_fiscalcode/tests/test_fiscalcode.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Copyright 2023 Simone Rubino - TAKOBI
# Copyright 2024 Simone Rubino - Aion Tech
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

Expand Down Expand Up @@ -62,8 +63,8 @@ def test_fiscalcode_check(self):
{
"name": "Person",
"company_name": "Company",
"is_company": False,
"fiscalcode": "123456789",
"is_company": True,
"fiscalcode": "12345670017",
}
)
# Invalid FC
Expand Down Expand Up @@ -128,3 +129,25 @@ def test_fiscal_code_check_company_VAT_change_to_person(self):
# Assert
self.assertIn("fiscal code", exc_message)
self.assertIn("16 characters", exc_message)

def test_company_fiscal_code(self):
base_company_partner_values = {
"name": "Company",
"is_company": True,
}

wrong_fiscal_code_partner_values = dict(
**base_company_partner_values,
fiscalcode="123456789",
)
with self.assertRaises(ValidationError):
self.env["res.partner"].create(wrong_fiscal_code_partner_values)

correct_fiscal_code_partner_values = dict(
**base_company_partner_values,
fiscalcode="12345670017",
)
self.env["res.partner"].create(correct_fiscal_code_partner_values)

empty_fiscal_code_partner_values = base_company_partner_values.copy()
self.env["res.partner"].create(empty_fiscal_code_partner_values)
3 changes: 2 additions & 1 deletion l10n_it_fiscalcode/wizard/compute_fc.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Copyright 2023 Simone Rubino - TAKOBI
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

import logging
Expand Down Expand Up @@ -206,6 +207,6 @@ def compute_fc(self):
)
% {"partner_fiscalcode": partner.fiscalcode, "compute": c_f}
)
partner.fiscalcode = c_f
partner.company_type = "person"
partner.fiscalcode = c_f
return {"type": "ir.actions.act_window_close"}
Original file line number Diff line number Diff line change
Expand Up @@ -334,11 +334,11 @@ def test_onchange_company(self):
old_company = comunicazione_liquidazione.company_id

old_company.partner_id.write(
{"vat": "IT12345670017", "fiscalcode": "FNCPLC19D01I168X"}
{"vat": "IT12345670017", "fiscalcode": "12345670017"}
)

company = self.env["res.company"].create(
{"name": "foo", "vat": "IT12345670017", "fiscalcode": "FNCPLC19D01I168X"}
{"name": "foo", "vat": "IT12345670017", "fiscalcode": "12345670017"}
)

with Form(comunicazione_liquidazione) as invoice_form:
Expand Down
Loading