Skip to content

Commit

Permalink
[MIG] l10n_it_fatturapa_out_rc: Migration to 14.0
Browse files Browse the repository at this point in the history
  • Loading branch information
tafaRU committed Dec 15, 2021
1 parent ad792ce commit 38e732a
Show file tree
Hide file tree
Showing 21 changed files with 553 additions and 626 deletions.
4 changes: 3 additions & 1 deletion l10n_it_fatturapa_out_rc/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Copyright 2020 Lorenzo Battistini @ TAKOBI
# Copyright 2021 Alex Comba - Agile Business Group
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "ITA - Emissione e-fattura con reverse charge",
"summary": "Integrazione l10n_it_fatturapa_out e l10n_it_reverse_charge",
"version": "12.0.1.0.4",
"version": "14.0.1.0.0",
"development_status": "Beta",
"category": "Hidden",
"website": "https://github.com/OCA/l10n-italy",
Expand All @@ -20,5 +21,6 @@
],
"data": [
"views/rc_type_views.xml",
"views/invoice_it_template.xml",
],
}
2 changes: 1 addition & 1 deletion l10n_it_fatturapa_out_rc/i18n/it.po
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 12.0\n"
"Project-Id-Version: Odoo Server 14.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-12-25 05:47+0000\n"
"PO-Revision-Date: 2020-12-25 05:47+0000\n"
Expand Down
2 changes: 1 addition & 1 deletion l10n_it_fatturapa_out_rc/i18n/l10n_it_fatturapa_out_rc.pot
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 12.0\n"
"Project-Id-Version: Odoo Server 14.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: <>\n"
"Language-Team: \n"
Expand Down
2 changes: 1 addition & 1 deletion l10n_it_fatturapa_out_rc/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from . import rc_type
from . import account_invoice
from . import account_move
47 changes: 0 additions & 47 deletions l10n_it_fatturapa_out_rc/models/account_invoice.py

This file was deleted.

119 changes: 119 additions & 0 deletions l10n_it_fatturapa_out_rc/models/account_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
from odoo import _, models
from odoo.exceptions import UserError


class AccountMove(models.Model):
_inherit = "account.move"

def generate_self_invoice(self):
res = super().generate_self_invoice()
if self.rc_self_invoice_id:
rc_type = self.fiscal_position_id.rc_type_id
if rc_type.fiscal_document_type_id:
self.rc_self_invoice_id.fiscal_document_type_id = (
rc_type.fiscal_document_type_id.id
)
if self.fatturapa_attachment_in_id:
doc_id = self.fatturapa_attachment_in_id.name
else:
doc_id = self.ref if self.ref else self.name
self.rc_self_invoice_id.related_documents = [
(
0,
0,
{
"type": "invoice",
"name": doc_id,
"date": self.invoice_date,
},
)
]
return res

def button_draft(self):
super().button_draft()
for inv in self:
if not inv.env.context.get(
"rc_set_to_draft"
) and inv.rc_purchase_invoice_id.state in ["draft", "cancel"]:
raise UserError(
_(
"Vendor invoice that has generated this self invoice isn't "
"validated. "
"Validate vendor invoice before."
)
)
return True

def preventive_checks(self):
super().preventive_checks()
invoices = self
invoices_with_rc = invoices.filtered(lambda x: x.rc_purchase_invoice_id)
invoices_without_rc = invoices - invoices_with_rc
if invoices_with_rc and invoices_without_rc:
raise UserError(
_(
"Selected invoices are both with and without reverse charge. You "
"should selected a smaller set of invoices"
)
)
invoices_with_document_type_codes = invoices.filtered(
lambda x: x.fiscal_document_type_id.code in ["TD17", "TD18", "TD19"]
)
invoices_without_document_type_codes = (
invoices - invoices_with_document_type_codes
)
if invoices_with_document_type_codes and invoices_without_document_type_codes:
raise UserError(
_(
"Select invoices are of too many fiscal document types: "
"select invoices exclusively of type 'TD17', 'TD18', 'TD19' "
"or exclusively of other types."
)
)
rc_suppliers = invoices.mapped("rc_purchase_invoice_id.partner_id")
if len(rc_suppliers) > 1:
raise UserError(
_(
"Selected reverse charge invoices have different suppliers. Please "
"select invoices with same supplier"
)
)
# --- preventive checks related to set CedentePrestatore.DatiAnagrafici --- #
partner = rc_suppliers[0]
fiscal_document_type_codes = invoices.mapped("fiscal_document_type_id.code")
# Se vale IT , il sistema verifica che il TipoDocumento sia diverso da
# TD17, TD18 e TD19; in caso contrario il file viene scartato
if partner.vat:
if partner.vat[0:2] == "IT" and any(
[x in ["TD17", "TD18", "TD19"] for x in fiscal_document_type_codes]
):
raise UserError(
_(
"A self-invoice cannot be issued with IT country code and "
"fiscal document type in 'TD17', 'TD18', 'TD19'."
)
)
if partner.vat[0:2] not in self.env["res.country"].search([]).mapped(
"code"
):
raise ValueError(
_(
"Country code does not exist or it is not mapped in countries: "
"%s" % partner.vat[0:2]
)
)
elif not partner.country_id.code or partner.country_id.code == "IT":
raise UserError(
_("Impossible to set IdFiscaleIVA for %s") % partner.display_name
)
# --- preventive checks related to set CedentePrestatore.Sede --- #
if not partner.street:
raise UserError(_("Partner %s, Street is not set.") % partner.display_name)
if not partner.city:
raise UserError(_("Partner %s, City is not set.") % partner.display_name)
if not partner.country_id:
raise UserError(_("Partner %s, Country is not set.") % partner.display_name)
if not partner.zip:
raise UserError(_("Partner %s, ZIP is not set.") % partner.display_name)
return
3 changes: 3 additions & 0 deletions l10n_it_fatturapa_out_rc/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
* `TAKOBI <https://takobi.online>`_:

* Lorenzo Battistini
* `Agile Business Group <https://agilebg.com>`_:

* Alex Comba <alex.comba@agilebg.com>
3 changes: 2 additions & 1 deletion l10n_it_fatturapa_out_rc/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import test_e_invoice_out_rc
from . import fatturapa_common
from . import test_fatturapa_xml_validation
11 changes: 7 additions & 4 deletions l10n_it_fatturapa_out_rc/tests/data/IT10538570960_00002.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<ns1:FatturaElettronica xmlns:ns1="http://ivaservizi.agenziaentrate.gov.it/docs/xsd/fatture/v1.2" versione="FPR12">
<?xml version="1.0" encoding="UTF-8" ?>
<ns1:FatturaElettronica
xmlns:ns1="http://ivaservizi.agenziaentrate.gov.it/docs/xsd/fatture/v1.2"
versione="FPR12"
>
<FatturaElettronicaHeader>
<DatiTrasmissione>
<IdTrasmittente>
Expand Down Expand Up @@ -57,13 +60,13 @@
<TipoDocumento>TD17</TipoDocumento>
<Divisa>EUR</Divisa>
<Data>2020-12-01</Data>
<Numero>SLF/2020/0015</Numero>
<Numero>SLF/2020/12/0001</Numero>
<ImportoTotaleDocumento>122.00</ImportoTotaleDocumento>
<Causale>Reverse charge self invoice.</Causale>
<Causale>Supplier: Intra EU supplier</Causale>
<Causale>Reference: EU-SUPPLIER-REF</Causale>
<Causale>Date: 2020-12-01</Causale>
<Causale>Internal reference: BILL/2020/0025</Causale>
<Causale>Internal reference: BILL/2020/12/0001</Causale>
</DatiGeneraliDocumento>
<DatiFattureCollegate>
<IdDocumento>EU-SUPPLIER-REF</IdDocumento>
Expand Down
11 changes: 7 additions & 4 deletions l10n_it_fatturapa_out_rc/tests/data/IT10538570960_00003.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<ns1:FatturaElettronica xmlns:ns1="http://ivaservizi.agenziaentrate.gov.it/docs/xsd/fatture/v1.2" versione="FPR12">
<?xml version="1.0" encoding="UTF-8" ?>
<ns1:FatturaElettronica
xmlns:ns1="http://ivaservizi.agenziaentrate.gov.it/docs/xsd/fatture/v1.2"
versione="FPR12"
>
<FatturaElettronicaHeader>
<DatiTrasmissione>
<IdTrasmittente>
Expand Down Expand Up @@ -57,13 +60,13 @@
<TipoDocumento>TD17</TipoDocumento>
<Divisa>EUR</Divisa>
<Data>2020-12-01</Data>
<Numero>SLF/2020/0016</Numero>
<Numero>RSLF/2020/12/0001</Numero>
<ImportoTotaleDocumento>-122.00</ImportoTotaleDocumento>
<Causale>Reverse charge self invoice.</Causale>
<Causale>Supplier: Intra EU supplier</Causale>
<Causale>Reference: EU-SUPPLIER-REF</Causale>
<Causale>Date: 2020-12-01</Causale>
<Causale>Internal reference: BILL/2020/0026</Causale>
<Causale>Internal reference: RBILL/2020/12/0001</Causale>
</DatiGeneraliDocumento>
<DatiFattureCollegate>
<IdDocumento>EU-SUPPLIER-REF</IdDocumento>
Expand Down
4 changes: 2 additions & 2 deletions l10n_it_fatturapa_out_rc/tests/data/IT10538570960_00004.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@
<TipoDocumento>TD17</TipoDocumento>
<Divisa>EUR</Divisa>
<Data>2020-12-01</Data>
<Numero>SLFEX/2020/0001</Numero>
<Numero>SLFEX/2020/12/0001</Numero>
<ImportoTotaleDocumento>122.00</ImportoTotaleDocumento>
<Causale>Reverse charge self invoice.</Causale>
<Causale>Supplier: Extra EU supplier</Causale>
<Causale>Reference: EXEU-SUPPLIER-REF</Causale>
<Causale>Date: 2020-12-01</Causale>
<Causale>Internal reference: BILL/2020/0027</Causale>
<Causale>Internal reference: BILL/2020/12/0001</Causale>
</DatiGeneraliDocumento>
<DatiFattureCollegate>
<IdDocumento>EXEU-SUPPLIER-REF</IdDocumento>
Expand Down
27 changes: 27 additions & 0 deletions l10n_it_fatturapa_out_rc/tests/fatturapa_common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from odoo.addons.l10n_it_fatturapa_out.tests.fatturapa_common import (
FatturaPACommon as _FatturaPACommon,
)


class FatturaPACommon(_FatturaPACommon):
def setUp(self):
super().setUp()

def _fix_payability(tax, ref):
reftax = self.env.ref(ref).sudo()
tax.payability = reftax.payability

# XXX - to be moved to l10n_it_fatturapa_out.tests.fatturapa_common ?
_fix_payability(self.tax_22, "l10n_it_fatturapa.tax_22")
_fix_payability(self.tax_10, "l10n_it_fatturapa.tax_10")
_fix_payability(self.tax_22_SP, "l10n_it_fatturapa.tax_22_SP")

def getAttachment(self, name, module_name=None):
if module_name is None:
module_name = "l10n_it_fatturapa_out_rc"
return super().getAttachment(name, module_name)

def getFile(self, filename, module_name=None):
if module_name is None:
module_name = "l10n_it_fatturapa_out_rc"
return super().getFile(filename, module_name)
Loading

0 comments on commit 38e732a

Please sign in to comment.