diff --git a/l10n_it_fatturapa_out/data/invoice_it_template.xml b/l10n_it_fatturapa_out/data/invoice_it_template.xml index 748a9989a2b4..2a4ef2bd1922 100644 --- a/l10n_it_fatturapa_out/data/invoice_it_template.xml +++ b/l10n_it_fatturapa_out/data/invoice_it_template.xml @@ -296,44 +296,44 @@ e 'line' per riga di fattura (a seconda del livello in cui sono chiamati) - - + + - + - + RF01 + + - - - + - + @@ -701,7 +701,9 @@ e 'line' per riga di fattura (a seconda del livello in cui sono chiamati) /> + > + + diff --git a/l10n_it_fatturapa_out/models/account.py b/l10n_it_fatturapa_out/models/account.py index 69549a5de343..18d093b79f3a 100644 --- a/l10n_it_fatturapa_out/models/account.py +++ b/l10n_it_fatturapa_out/models/account.py @@ -87,6 +87,12 @@ def preventive_checks(self): raise UserError( _("Invoice %s contains product lines w/o taxes") % invoice.name ) + company_id = invoice.company_id + if company_id.vat != company_id.partner_id.vat: + raise UserError( + _("Invoice %s: company and company partner must have same vat") + % invoice.name + ) return def action_invoice_cancel(self): diff --git a/l10n_it_fatturapa_out/tests/fatturapa_common.py b/l10n_it_fatturapa_out/tests/fatturapa_common.py index 3a840ec75008..0208d5530335 100644 --- a/l10n_it_fatturapa_out/tests/fatturapa_common.py +++ b/l10n_it_fatturapa_out/tests/fatturapa_common.py @@ -162,11 +162,14 @@ def AttachFileToInvoice(self, InvoiceId, filename): } ) - def set_sequences(self, invoice_number, dt): + def set_sequences( + self, + invoice_number, + dt, + sequence_name="Customer Invoices : Check Number Sequence", + ): seq_pool = self.env["ir.sequence"] - inv_seq = seq_pool.search( - [("name", "=", "Customer Invoices : Check Number Sequence")], limit=1 - ) + inv_seq = seq_pool.search([("name", "=", sequence_name)], limit=1) seq_date = self.env["ir.sequence.date_range"].search( [ ("sequence_id", "=", inv_seq.id), diff --git a/l10n_it_fatturapa_out/wizard/efattura.py b/l10n_it_fatturapa_out/wizard/efattura.py index d288d9a2832f..fa5e7d0f696d 100644 --- a/l10n_it_fatturapa_out/wizard/efattura.py +++ b/l10n_it_fatturapa_out/wizard/efattura.py @@ -99,7 +99,7 @@ def format_phone(number): return number return False - def format_price(line): + def format_price(line, sign=1): res = line.price_unit if line.tax_ids and line.tax_ids[0].price_include: res = line.price_unit / (1 + (line.tax_ids[0].amount / 100)) @@ -115,7 +115,9 @@ def format_price(line): res = -res # XXX arrotondamento? - res = "{prezzo:.{precision}f}".format(prezzo=res, precision=price_precision) + res = "{prezzo:.{precision}f}".format( + prezzo=sign * res, precision=price_precision + ) return res def format_quantity(line): diff --git a/l10n_it_fatturapa_out_rc/README.rst b/l10n_it_fatturapa_out_rc/README.rst new file mode 100644 index 000000000000..372d948f8628 --- /dev/null +++ b/l10n_it_fatturapa_out_rc/README.rst @@ -0,0 +1,104 @@ +============================================ +ITA - Emissione e-fattura con reverse charge +============================================ + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fl10n--italy-lightgray.png?logo=github + :target: https://github.com/OCA/l10n-italy/tree/12.0/l10n_it_fatturapa_out_rc + :alt: OCA/l10n-italy +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/l10n-italy-12-0/l10n-italy-12-0-l10n_it_fatturapa_out_rc + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/122/12.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +**Italiano** + +Gestione tipi documento fiscale TD16, TD17, TD18, TD19 in generazione fattura elettronica. + +Il modulo permette di impostare, nell'XML, il corretto fornitore in caso di reverse charge. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +**Italiano** + +Vedi ``l10n_it_reverse_charge`` per la configurazione dei tipi di reverse charge. + +Per le autofatture da comunicare a SDI va impostato + +**Tipo partner** = **Altro** + +e + +**Partner autofattura** = **My company** + +Sul tipo di reverse charge impostare anche il relativo **Tipo documento fiscale** + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* TAKOBI + +Contributors +~~~~~~~~~~~~ + +* `TAKOBI `_: + + * Lorenzo Battistini + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +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. + +.. |maintainer-eLBati| image:: https://github.com/eLBati.png?size=40px + :target: https://github.com/eLBati + :alt: eLBati + +Current `maintainer `__: + +|maintainer-eLBati| + +This module is part of the `OCA/l10n-italy `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/l10n_it_fatturapa_out_rc/__init__.py b/l10n_it_fatturapa_out_rc/__init__.py new file mode 100644 index 000000000000..134df274351c --- /dev/null +++ b/l10n_it_fatturapa_out_rc/__init__.py @@ -0,0 +1,2 @@ +from . import wizard +from . import models diff --git a/l10n_it_fatturapa_out_rc/__manifest__.py b/l10n_it_fatturapa_out_rc/__manifest__.py new file mode 100644 index 000000000000..0dd7a500ca0c --- /dev/null +++ b/l10n_it_fatturapa_out_rc/__manifest__.py @@ -0,0 +1,26 @@ +# 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": "14.0.1.0.0", + "development_status": "Beta", + "category": "Hidden", + "website": "https://github.com/OCA/l10n-italy", + "author": "TAKOBI, Odoo Community Association (OCA)", + "maintainers": ["eLBati"], + "license": "AGPL-3", + "application": False, + "installable": True, + "auto_install": True, + "depends": [ + "l10n_it_fatturapa_out", + "l10n_it_fatturapa_in", + "l10n_it_reverse_charge", + ], + "data": [ + "views/rc_type_views.xml", + "views/invoice_it_template.xml", + ], +} diff --git a/l10n_it_fatturapa_out_rc/i18n/it.po b/l10n_it_fatturapa_out_rc/i18n/it.po new file mode 100644 index 000000000000..5d0c65a8f304 --- /dev/null +++ b/l10n_it_fatturapa_out_rc/i18n/it.po @@ -0,0 +1,122 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * l10n_it_fatturapa_out_rc +# +msgid "" +msgstr "" +"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" +"Last-Translator: <>\n" +"Language-Team: \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: l10n_it_fatturapa_out_rc +#: code:addons/l10n_it_fatturapa_out_rc/wizard/wizard_export_e_invoice.py:68 +#, python-format +msgid "" +"A self-invoice cannot be issued with IT country code and fiscal document " +"type in 'TD17', 'TD18', 'TD19'." +msgstr "" + +#. module: l10n_it_fatturapa_out_rc +#: code:addons/l10n_it_fatturapa_out_rc/wizard/wizard_export_e_invoice.py:74 +#, python-format +msgid "Country code does not exist or it is not mapped in countries: %s" +msgstr "" + +#. module: l10n_it_fatturapa_out_rc +#: model:ir.model,name:l10n_it_fatturapa_out_rc.model_wizard_export_fatturapa +msgid "Export E-invoice" +msgstr "Esporta e-fattura" + +#. module: l10n_it_fatturapa_out_rc +#: model:ir.model.fields,field_description:l10n_it_fatturapa_out_rc.field_account_rc_type__fiscal_document_type_id +msgid "Fiscal Document Type" +msgstr "Tipo di documento fiscale" + +#. module: l10n_it_fatturapa_out_rc +#: code:addons/l10n_it_fatturapa_out_rc/wizard/wizard_export_e_invoice.py:85 +#, python-format +msgid "Impossible to set IdFiscaleIVA for %s" +msgstr "Impossibile impostare IdFiscaleIVA per %s" + +#. module: l10n_it_fatturapa_out_rc +#: model:ir.model,name:l10n_it_fatturapa_out_rc.model_account_invoice +msgid "Invoice" +msgstr "" + +#. module: l10n_it_fatturapa_out_rc +#: code:addons/l10n_it_fatturapa_out_rc/wizard/wizard_export_e_invoice.py:100 +#, python-format +msgid "Partner %s, City is not set." +msgstr "Partner %s, la città non è impostata" + +#. module: l10n_it_fatturapa_out_rc +#: code:addons/l10n_it_fatturapa_out_rc/wizard/wizard_export_e_invoice.py:103 +#, python-format +msgid "Partner %s, Country is not set." +msgstr "Partner %s, la nazione non è impostata" + +#. module: l10n_it_fatturapa_out_rc +#: code:addons/l10n_it_fatturapa_out_rc/wizard/wizard_export_e_invoice.py:97 +#, python-format +msgid "Partner %s, Street is not set." +msgstr "Partner %s, l'indirizzo non è impostato" + +#. module: l10n_it_fatturapa_out_rc +#: code:addons/l10n_it_fatturapa_out_rc/wizard/wizard_export_e_invoice.py:115 +#, python-format +msgid "Partner %s, ZIP is not set." +msgstr "Partner %s, il CAP non è impostato" + +#. module: l10n_it_fatturapa_out_rc +#: model:ir.model,name:l10n_it_fatturapa_out_rc.model_account_rc_type +msgid "Reverse Charge Type" +msgstr "Tipo inversione contabile" + +#. module: l10n_it_fatturapa_out_rc +#: code:addons/l10n_it_fatturapa_out_rc/wizard/wizard_export_e_invoice.py:38 +#, python-format +msgid "" +"Select invoices are of too many fiscal document types: select invoices " +"exclusively of type 'TD17', 'TD18', 'TD19' or exclusively of other types." +msgstr "" + +#. module: l10n_it_fatturapa_out_rc +#: code:addons/l10n_it_fatturapa_out_rc/wizard/wizard_export_e_invoice.py:28 +#, python-format +msgid "" +"Selected invoices are both with and without reverse charge. You should " +"selected a smaller set of invoices" +msgstr "" +"Le fatture selezionate sono sia con che senza inversione contabile. È " +"necessario selezionare un insieme più piccolo di fatture" + +#. module: l10n_it_fatturapa_out_rc +#: code:addons/l10n_it_fatturapa_out_rc/wizard/wizard_export_e_invoice.py:45 +#, python-format +msgid "" +"Selected reverse charge invoices have different suppliers. Please select " +"invoices with same supplier" +msgstr "" +"Le fatture in inversione contabile selezionate hanno fornitori diversi. " +"Selezionare fatture con lo stesso fornitore" + +#. module: l10n_it_fatturapa_out_rc +#: model:ir.model.fields,help:l10n_it_fatturapa_out_rc.field_account_rc_type__fiscal_document_type_id +msgid "To be used when sending self invoices to the exchange system" +msgstr "Da usare quando si inviano le autofatture al sistema di interscambio" + +#. module: l10n_it_fatturapa_out_rc +#: code:addons/l10n_it_fatturapa_out_rc/models/account_invoice.py:34 +#, python-format +msgid "" +"Vendor invoice that has generated this self invoice isn't validated. " +"Validate vendor invoice before." +msgstr "" diff --git a/l10n_it_fatturapa_out_rc/i18n/l10n_it_fatturapa_out_rc.pot b/l10n_it_fatturapa_out_rc/i18n/l10n_it_fatturapa_out_rc.pot new file mode 100644 index 000000000000..554221902564 --- /dev/null +++ b/l10n_it_fatturapa_out_rc/i18n/l10n_it_fatturapa_out_rc.pot @@ -0,0 +1,106 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * l10n_it_fatturapa_out_rc +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: l10n_it_fatturapa_out_rc +#: code:addons/l10n_it_fatturapa_out_rc/wizard/wizard_export_e_invoice.py:68 +#, python-format +msgid "A self-invoice cannot be issued with IT country code and fiscal document type in 'TD17', 'TD18', 'TD19'." +msgstr "" + +#. module: l10n_it_fatturapa_out_rc +#: code:addons/l10n_it_fatturapa_out_rc/wizard/wizard_export_e_invoice.py:74 +#, python-format +msgid "Country code does not exist or it is not mapped in countries: %s" +msgstr "" + +#. module: l10n_it_fatturapa_out_rc +#: model:ir.model,name:l10n_it_fatturapa_out_rc.model_wizard_export_fatturapa +msgid "Export E-invoice" +msgstr "" + +#. module: l10n_it_fatturapa_out_rc +#: model:ir.model.fields,field_description:l10n_it_fatturapa_out_rc.field_account_rc_type__fiscal_document_type_id +msgid "Fiscal Document Type" +msgstr "" + +#. module: l10n_it_fatturapa_out_rc +#: code:addons/l10n_it_fatturapa_out_rc/wizard/wizard_export_e_invoice.py:85 +#, python-format +msgid "Impossible to set IdFiscaleIVA for %s" +msgstr "" + +#. module: l10n_it_fatturapa_out_rc +#: model:ir.model,name:l10n_it_fatturapa_out_rc.model_account_invoice +msgid "Invoice" +msgstr "" + +#. module: l10n_it_fatturapa_out_rc +#: code:addons/l10n_it_fatturapa_out_rc/wizard/wizard_export_e_invoice.py:100 +#, python-format +msgid "Partner %s, City is not set." +msgstr "" + +#. module: l10n_it_fatturapa_out_rc +#: code:addons/l10n_it_fatturapa_out_rc/wizard/wizard_export_e_invoice.py:103 +#, python-format +msgid "Partner %s, Country is not set." +msgstr "" + +#. module: l10n_it_fatturapa_out_rc +#: code:addons/l10n_it_fatturapa_out_rc/wizard/wizard_export_e_invoice.py:97 +#, python-format +msgid "Partner %s, Street is not set." +msgstr "" + +#. module: l10n_it_fatturapa_out_rc +#: code:addons/l10n_it_fatturapa_out_rc/wizard/wizard_export_e_invoice.py:115 +#, python-format +msgid "Partner %s, ZIP is not set." +msgstr "" + +#. module: l10n_it_fatturapa_out_rc +#: model:ir.model,name:l10n_it_fatturapa_out_rc.model_account_rc_type +msgid "Reverse Charge Type" +msgstr "" + +#. module: l10n_it_fatturapa_out_rc +#: code:addons/l10n_it_fatturapa_out_rc/wizard/wizard_export_e_invoice.py:38 +#, python-format +msgid "Select invoices are of too many fiscal document types: select invoices exclusively of type 'TD17', 'TD18', 'TD19' or exclusively of other types." +msgstr "" + +#. module: l10n_it_fatturapa_out_rc +#: code:addons/l10n_it_fatturapa_out_rc/wizard/wizard_export_e_invoice.py:28 +#, python-format +msgid "Selected invoices are both with and without reverse charge. You should selected a smaller set of invoices" +msgstr "" + +#. module: l10n_it_fatturapa_out_rc +#: code:addons/l10n_it_fatturapa_out_rc/wizard/wizard_export_e_invoice.py:45 +#, python-format +msgid "Selected reverse charge invoices have different suppliers. Please select invoices with same supplier" +msgstr "" + +#. module: l10n_it_fatturapa_out_rc +#: model:ir.model.fields,help:l10n_it_fatturapa_out_rc.field_account_rc_type__fiscal_document_type_id +msgid "To be used when sending self invoices to the exchange system" +msgstr "" + +#. module: l10n_it_fatturapa_out_rc +#: code:addons/l10n_it_fatturapa_out_rc/models/account_invoice.py:34 +#, python-format +msgid "Vendor invoice that has generated this self invoice isn't validated. Validate vendor invoice before." +msgstr "" + diff --git a/l10n_it_fatturapa_out_rc/models/__init__.py b/l10n_it_fatturapa_out_rc/models/__init__.py new file mode 100644 index 000000000000..166e50c64ad5 --- /dev/null +++ b/l10n_it_fatturapa_out_rc/models/__init__.py @@ -0,0 +1,2 @@ +from . import rc_type +from . import account_move diff --git a/l10n_it_fatturapa_out_rc/models/account_move.py b/l10n_it_fatturapa_out_rc/models/account_move.py new file mode 100644 index 000000000000..141466b7f516 --- /dev/null +++ b/l10n_it_fatturapa_out_rc/models/account_move.py @@ -0,0 +1,117 @@ +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." + ) + ) + + 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 and rc_suppliers[0] or self.env["res.partner"].browse() + 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 + vat = partner.vat and partner.vat[0:2] + if vat: + if vat == "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 vat not in self.env["res.country"].search([]).mapped("code"): + raise ValueError( + _( + "Country code does not exist or it is not mapped in countries: " + "%s" % vat + ) + ) + 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 diff --git a/l10n_it_fatturapa_out_rc/models/rc_type.py b/l10n_it_fatturapa_out_rc/models/rc_type.py new file mode 100644 index 000000000000..78a120fa8d4c --- /dev/null +++ b/l10n_it_fatturapa_out_rc/models/rc_type.py @@ -0,0 +1,11 @@ +from odoo import fields, models + + +class AccountRCType(models.Model): + _inherit = "account.rc.type" + + fiscal_document_type_id = fields.Many2one( + "fiscal.document.type", + string="Fiscal Document Type", + help="To be used when sending self invoices to the exchange system", + ) diff --git a/l10n_it_fatturapa_out_rc/readme/CONFIGURE.rst b/l10n_it_fatturapa_out_rc/readme/CONFIGURE.rst new file mode 100644 index 000000000000..783f1384de24 --- /dev/null +++ b/l10n_it_fatturapa_out_rc/readme/CONFIGURE.rst @@ -0,0 +1,13 @@ +**Italiano** + +Vedi ``l10n_it_reverse_charge`` per la configurazione dei tipi di reverse charge. + +Per le autofatture da comunicare a SDI va impostato + +**Tipo partner** = **Altro** + +e + +**Partner autofattura** = **My company** + +Sul tipo di reverse charge impostare anche il relativo **Tipo documento fiscale** diff --git a/l10n_it_fatturapa_out_rc/readme/CONTRIBUTORS.rst b/l10n_it_fatturapa_out_rc/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000000..27fc8303500e --- /dev/null +++ b/l10n_it_fatturapa_out_rc/readme/CONTRIBUTORS.rst @@ -0,0 +1,6 @@ +* `TAKOBI `_: + + * Lorenzo Battistini +* `Agile Business Group `_: + + * Alex Comba diff --git a/l10n_it_fatturapa_out_rc/readme/DESCRIPTION.rst b/l10n_it_fatturapa_out_rc/readme/DESCRIPTION.rst new file mode 100644 index 000000000000..473c567a4f65 --- /dev/null +++ b/l10n_it_fatturapa_out_rc/readme/DESCRIPTION.rst @@ -0,0 +1,5 @@ +**Italiano** + +Gestione tipi documento fiscale TD16, TD17, TD18, TD19 in generazione fattura elettronica. + +Il modulo permette di impostare, nell'XML, il corretto fornitore in caso di reverse charge. diff --git a/l10n_it_fatturapa_out_rc/static/description/icon.png b/l10n_it_fatturapa_out_rc/static/description/icon.png new file mode 100644 index 000000000000..3a0328b516c4 Binary files /dev/null and b/l10n_it_fatturapa_out_rc/static/description/icon.png differ diff --git a/l10n_it_fatturapa_out_rc/static/description/index.html b/l10n_it_fatturapa_out_rc/static/description/index.html new file mode 100644 index 000000000000..c956a84a698f --- /dev/null +++ b/l10n_it_fatturapa_out_rc/static/description/index.html @@ -0,0 +1,437 @@ + + + + + + +ITA - Emissione e-fattura con reverse charge + + + +
+

ITA - Emissione e-fattura con reverse charge

+ + +

Beta License: AGPL-3 OCA/l10n-italy Translate me on Weblate Try me on Runbot

+

Italiano

+

Gestione tipi documento fiscale TD16, TD17, TD18, TD19 in generazione fattura elettronica.

+

Il modulo permette di impostare, nell’XML, il corretto fornitore in caso di reverse charge.

+

Table of contents

+ +
+

Configuration

+

Italiano

+

Vedi l10n_it_reverse_charge per la configurazione dei tipi di reverse charge.

+

Per le autofatture da comunicare a SDI va impostato

+

Tipo partner = Altro

+

e

+

Partner autofattura = My company

+

Sul tipo di reverse charge impostare anche il relativo Tipo documento fiscale

+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • TAKOBI
  • +
+
+
+

Contributors

+
    +
  • TAKOBI:
      +
    • Lorenzo Battistini
    • +
    +
  • +
+
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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.

+

Current maintainer:

+

eLBati

+

This module is part of the OCA/l10n-italy project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/l10n_it_fatturapa_out_rc/tests/__init__.py b/l10n_it_fatturapa_out_rc/tests/__init__.py new file mode 100644 index 000000000000..c4c14b87a47c --- /dev/null +++ b/l10n_it_fatturapa_out_rc/tests/__init__.py @@ -0,0 +1,2 @@ +from . import fatturapa_common +from . import test_fatturapa_xml_validation diff --git a/l10n_it_fatturapa_out_rc/tests/data/IT10538570960_00002.xml b/l10n_it_fatturapa_out_rc/tests/data/IT10538570960_00002.xml new file mode 100644 index 000000000000..7d30bc92fce8 --- /dev/null +++ b/l10n_it_fatturapa_out_rc/tests/data/IT10538570960_00002.xml @@ -0,0 +1,97 @@ + + + + + + IT + 10538570960 + + 00002 + FPR12 + 0000000 + + 06543534343 + info@yourcompany.example.com + + + + + + BE + 0477472701 + + + Intra EU supplier + + RF01 + + + Street + 12345 + city + BE + + + + + + IT + 10538570960 + + + YourCompany + + + + Via Milano, 1 + 00100 + Roma + AK + IT + + + + + + + TD17 + EUR + 2020-12-01 + SLF/2020/12/0001 + 122.00 + Reverse charge self invoice. + Supplier: Intra EU supplier + Reference: EU-SUPPLIER-REF + Date: 2020-12-01 + Internal reference: BILL/2020/12/0001 + + + EU-SUPPLIER-REF + 2020-12-01 + + + + + 1 + + ODOO + DESK0004 + + Invoice for sample product + 1.000 + Unit(s) + 100.00000 + 100.00 + 22.00 + + + 22.00 + 100.00 + 22.00 + + + + diff --git a/l10n_it_fatturapa_out_rc/tests/data/IT10538570960_00003.xml b/l10n_it_fatturapa_out_rc/tests/data/IT10538570960_00003.xml new file mode 100644 index 000000000000..ae91d199dd4f --- /dev/null +++ b/l10n_it_fatturapa_out_rc/tests/data/IT10538570960_00003.xml @@ -0,0 +1,97 @@ + + + + + + IT + 10538570960 + + 00003 + FPR12 + 0000000 + + 06543534343 + info@yourcompany.example.com + + + + + + BE + 0477472701 + + + Intra EU supplier + + RF01 + + + Street + 12345 + city + BE + + + + + + IT + 10538570960 + + + YourCompany + + + + Via Milano, 1 + 00100 + Roma + AK + IT + + + + + + + TD17 + EUR + 2020-12-01 + RSLF/2020/12/0001 + -122.00 + Reverse charge self invoice. + Supplier: Intra EU supplier + Reference: EU-SUPPLIER-REF + Date: 2020-12-01 + Internal reference: RBILL/2020/12/0001 + + + EU-SUPPLIER-REF + 2020-12-01 + + + + + 1 + + ODOO + DESK0004 + + Invoice for sample product + 1.000 + Unit(s) + -100.00000 + -100.00 + 22.00 + + + 22.00 + -100.00 + -22.00 + + + + diff --git a/l10n_it_fatturapa_out_rc/tests/data/IT10538570960_00004.xml b/l10n_it_fatturapa_out_rc/tests/data/IT10538570960_00004.xml new file mode 100644 index 000000000000..46aedcac83b4 --- /dev/null +++ b/l10n_it_fatturapa_out_rc/tests/data/IT10538570960_00004.xml @@ -0,0 +1,97 @@ + + + + + + IT + 10538570960 + + 00004 + FPR12 + 0000000 + + 06543534343 + info@yourcompany.example.com + + + + + + US + 484762844 + + + Extra EU supplier + + RF01 + + + Street + 12345 + city + US + + + + + + IT + 10538570960 + + + YourCompany + + + + Via Milano, 1 + 00100 + Roma + AK + IT + + + + + + + TD17 + EUR + 2020-12-01 + SLFEX/2020/12/0001 + 122.00 + Reverse charge self invoice. + Supplier: Extra EU supplier + Reference: EXEU-SUPPLIER-REF + Date: 2020-12-01 + Internal reference: BILL/2020/12/0001 + + + EXEU-SUPPLIER-REF + 2020-12-01 + + + + + 1 + + ODOO + DESK0004 + + Invoice for sample product + 1.000 + Unit(s) + 100.00000 + 100.00 + 22.00 + + + 22.00 + 100.00 + 22.00 + + + + diff --git a/l10n_it_fatturapa_out_rc/tests/fatturapa_common.py b/l10n_it_fatturapa_out_rc/tests/fatturapa_common.py new file mode 100644 index 000000000000..c49043651785 --- /dev/null +++ b/l10n_it_fatturapa_out_rc/tests/fatturapa_common.py @@ -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) diff --git a/l10n_it_fatturapa_out_rc/tests/test_fatturapa_xml_validation.py b/l10n_it_fatturapa_out_rc/tests/test_fatturapa_xml_validation.py new file mode 100644 index 000000000000..72fa21d46e05 --- /dev/null +++ b/l10n_it_fatturapa_out_rc/tests/test_fatturapa_xml_validation.py @@ -0,0 +1,237 @@ +# Copyright 2021 Alex Comba - Agile Business Group +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +import base64 + +from odoo import fields +from odoo.exceptions import UserError +from odoo.tests.common import Form + +from odoo.addons.l10n_it_fatturapa_out.tests.fatturapa_common import FatturaPACommon +from odoo.addons.l10n_it_reverse_charge.tests.rc_common import ReverseChargeCommon + + +class TestFatturaPAXMLValidation(ReverseChargeCommon, FatturaPACommon): + def setUp(self): + super().setUp() + + # XXX - a company named "YourCompany" already exists + # we move it out of the way but we should do better here + self.env.company.sudo().search([("name", "=", "YourCompany")]).write( + {"name": "YourCompany_"} + ) + + self.env.company.name = "YourCompany" + self.env.company.vat = "IT10538570960" + self.env.company.fatturapa_art73 = False + self.env.company.partner_id.street = "Via Milano, 1" + self.env.company.partner_id.city = "Roma" + self.env.company.partner_id.state_id = self.env.ref("base.state_us_2").id + self.env.company.partner_id.zip = "00100" + self.env.company.partner_id.phone = "06543534343" + self.env.company.email = "info@yourcompany.example.com" + self.env.company.partner_id.country_id = self.env.ref("base.it").id + self.env.company.fatturapa_fiscal_position_id = self.env.ref( + "l10n_it_fatturapa.fatturapa_RF01" + ).id + + self.env["decimal.precision"].search( + [("name", "=", "Product Unit of Measure")] + ).digits = 3 + self.env["uom.uom"].search([("name", "=", "Units")]).name = "Unit(s)" + + self.rc_type_ieu.partner_type = "other" + self.rc_type_ieu.partner_id = self.env.company.partner_id.id + self.rc_type_ieu.fiscal_document_type_id = self.env.ref( + "l10n_it_fiscal_document_type.15" + ).id + self.rc_type_eeu.partner_id = self.env.company.partner_id.id + self.rc_type_eeu.fiscal_document_type_id = self.env.ref( + "l10n_it_fiscal_document_type.15" + ).id + # l'auto fattura non deve avere la natura di esenzione + # self.tax_22vi.kind_id = self.env.ref("l10n_it_account_tax_kind.n6").id + self.supplier_intraEU.customer_rank = 0 + self.bill_sequence_name = "Vendor Bills : Check Number Sequence" + self.selfinvoice_sequence_name = "selfinvoice : Check Number Sequence" + + @classmethod + def _create_invoice(cls, move_type, partner, name, invoice_date, ref, taxes): + invoice_form = Form( + cls.env["account.move"].with_context({"default_move_type": move_type}) + ) + invoice_form.partner_id = partner + invoice_form.name = name + invoice_form.invoice_date = fields.Date.from_string(invoice_date) + invoice_form.date = fields.Date.from_string(invoice_date) + invoice_form.ref = ref + with invoice_form.line_ids.new() as line_form: + line_form.product_id = cls.env.ref("product.product_product_4d") + line_form.name = "Invoice for sample product" + line_form.price_unit = 100 + line_form.tax_ids.clear() + line_form.tax_ids.add(taxes) + return invoice_form + + def test_intra_EU(self): + self.set_sequences( + 15, "2020-12-01", sequence_name=self.selfinvoice_sequence_name + ) + self.set_sequences(25, "2020-12-01", sequence_name=self.bill_sequence_name) + self.supplier_intraEU.property_payment_term_id = self.term_15_30.id + + invoice_form = self._create_invoice( + move_type="in_invoice", + partner=self.supplier_intraEU, + name="BILL/2021/12/0001", + invoice_date="2020-12-01", + ref="EU-SUPPLIER-REF", + taxes=self.tax_22ai, + ) + invoice = invoice_form.save() + invoice.action_post() + + self.assertEqual( + invoice.rc_self_invoice_id.fiscal_document_type_id.code, "TD17" + ) + with self.assertRaises(UserError): + # Impossible to set IdFiscaleIVA + self.run_wizard(invoice.rc_self_invoice_id.id) + self.supplier_intraEU.vat = "BE0477472701" + with self.assertRaises(UserError): + # Street is not set + self.run_wizard(invoice.rc_self_invoice_id.id) + self.supplier_intraEU.street = "Street" + self.supplier_intraEU.zip = "12345" + self.supplier_intraEU.city = "city" + self.supplier_intraEU.country_id = self.env.ref("base.be") + self.supplier_intraEU.is_company = True + res = self.run_wizard(invoice.rc_self_invoice_id.id) + attachment = self.attach_model.browse(res["res_id"]) + self.set_e_invoice_file_id(attachment, "IT10538570960_00002.xml") + xml_content = base64.decodebytes(attachment.datas) + self.check_content( + xml_content, "IT10538570960_00002.xml", "l10n_it_fatturapa_out_rc" + ) + + def test_intra_EU_customer(self): + self.set_sequences( + 15, "2020-12-01", sequence_name=self.selfinvoice_sequence_name + ) + self.set_sequences(25, "2020-12-01", sequence_name=self.bill_sequence_name) + self.supplier_intraEU.property_payment_term_id = self.term_15_30.id + + invoice_form = self._create_invoice( + move_type="out_invoice", + partner=self.supplier_intraEU, + name="BILL/2021/12/0002", + invoice_date="2020-12-01", + ref="EU-CUSTOMER-REF", + taxes=self.tax_22vi, + ) + invoice = invoice_form.save() + invoice.action_post() + self.assertFalse(invoice.rc_self_invoice_id) + + def test_intra_EU_draft(self): + self.set_sequences( + 15, "2020-12-01", sequence_name=self.selfinvoice_sequence_name + ) + self.set_sequences(25, "2020-12-01", sequence_name=self.bill_sequence_name) + self.supplier_intraEU.property_payment_term_id = self.term_15_30.id + + invoice_form = self._create_invoice( + move_type="in_invoice", + partner=self.supplier_intraEU, + name="BILL/2021/12/0003", + invoice_date="2020-12-01", + ref="EU-SUPPLIER-REF", + taxes=self.tax_22ai, + ) + invoice = invoice_form.save() + invoice.action_post() + invoice.button_cancel() + self.assertEqual(invoice.state, "cancel") + self.assertEqual(invoice.state, "cancel") + self.assertFalse(invoice.rc_self_invoice_id.state) + invoice.button_draft() + self.assertEqual(invoice.state, "draft") + + def test_intra_EU_supplier_refund(self): + self.set_sequences( + 16, "2020-12-01", sequence_name=self.selfinvoice_sequence_name + ) + self.set_sequences(26, "2020-12-01", sequence_name=self.bill_sequence_name) + self.supplier_intraEU.property_payment_term_id = self.term_15_30.id + + invoice_form = self._create_invoice( + move_type="in_refund", + partner=self.supplier_intraEU, + name="BILL/2021/12/0004", + invoice_date="2020-12-01", + ref="EU-SUPPLIER-REF", + taxes=self.tax_22ai, + ) + invoice = invoice_form.save() + invoice.action_post() + self.assertEqual( + invoice.rc_self_invoice_id.fiscal_document_type_id.code, "TD17" + ) + with self.assertRaises(UserError): + # Impossible to set IdFiscaleIVA + self.run_wizard(invoice.rc_self_invoice_id.id) + self.supplier_intraEU.vat = "BE0477472701" + with self.assertRaises(UserError): + # Street is not set + self.run_wizard(invoice.rc_self_invoice_id.id) + self.supplier_intraEU.street = "Street" + self.supplier_intraEU.zip = "12345" + self.supplier_intraEU.city = "city" + self.supplier_intraEU.country_id = self.env.ref("base.be") + self.supplier_intraEU.is_company = True + res = self.run_wizard(invoice.rc_self_invoice_id.id) + attachment = self.attach_model.browse(res["res_id"]) + self.set_e_invoice_file_id(attachment, "IT10538570960_00003.xml") + xml_content = base64.decodebytes(attachment.datas) + self.check_content( + xml_content, "IT10538570960_00003.xml", "l10n_it_fatturapa_out_rc" + ) + + def test_extra_EU(self): + self.set_sequences(27, "2020-12-01", sequence_name=self.bill_sequence_name) + self.supplier_extraEU.property_payment_term_id = self.term_15_30.id + self.rc_type_eeu.with_supplier_self_invoice = False + + invoice_form = self._create_invoice( + move_type="in_invoice", + partner=self.supplier_extraEU, + name="BILL/2021/12/0005", + invoice_date="2020-12-01", + ref="EXEU-SUPPLIER-REF", + taxes=self.tax_22ae, + ) + invoice = invoice_form.save() + invoice.action_post() + + self.assertEqual( + invoice.rc_self_invoice_id.fiscal_document_type_id.code, "TD17" + ) + with self.assertRaises(UserError): + # Impossible to set IdFiscaleIVA + self.run_wizard(invoice.rc_self_invoice_id.id) + self.supplier_extraEU.vat = "US484762844" + with self.assertRaises(UserError): + # Street is not set + self.run_wizard(invoice.rc_self_invoice_id.id) + self.supplier_extraEU.street = "Street" + self.supplier_extraEU.zip = "12345" + self.supplier_extraEU.city = "city" + self.supplier_extraEU.country_id = self.env.ref("base.us") + self.supplier_extraEU.is_company = True + res = self.run_wizard(invoice.rc_self_invoice_id.id) + attachment = self.attach_model.browse(res["res_id"]) + self.set_e_invoice_file_id(attachment, "IT10538570960_00004.xml") + xml_content = base64.decodebytes(attachment.datas) + self.check_content( + xml_content, "IT10538570960_00004.xml", "l10n_it_fatturapa_out_rc" + ) diff --git a/l10n_it_fatturapa_out_rc/views/invoice_it_template.xml b/l10n_it_fatturapa_out_rc/views/invoice_it_template.xml new file mode 100644 index 000000000000..5b5046e8b6b7 --- /dev/null +++ b/l10n_it_fatturapa_out_rc/views/invoice_it_template.xml @@ -0,0 +1,95 @@ + + + + + + + + + + diff --git a/l10n_it_fatturapa_out_rc/views/rc_type_views.xml b/l10n_it_fatturapa_out_rc/views/rc_type_views.xml new file mode 100644 index 000000000000..509b7a62dd60 --- /dev/null +++ b/l10n_it_fatturapa_out_rc/views/rc_type_views.xml @@ -0,0 +1,13 @@ + + + + view_rc_type_form_td + account.rc.type + + + + + + + + diff --git a/l10n_it_fatturapa_out_rc/wizard/__init__.py b/l10n_it_fatturapa_out_rc/wizard/__init__.py new file mode 100644 index 000000000000..861a0af3e6aa --- /dev/null +++ b/l10n_it_fatturapa_out_rc/wizard/__init__.py @@ -0,0 +1,2 @@ +from . import efattura +from . import wizard_export_fatturapa diff --git a/l10n_it_fatturapa_out_rc/wizard/efattura.py b/l10n_it_fatturapa_out_rc/wizard/efattura.py new file mode 100644 index 000000000000..abce603bd7c5 --- /dev/null +++ b/l10n_it_fatturapa_out_rc/wizard/efattura.py @@ -0,0 +1,26 @@ +# Copyright 2021 Alex Comba - Agile Business Group +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo.addons.l10n_it_fatturapa_out.wizard.efattura import ( + EFatturaOut as _EFatturaOut, +) + + +class EFatturaOut(_EFatturaOut): + def get_template_values(self): + def get_sign(invoice): + sign = 1 + if ( + invoice.move_type + in [ + "out_refund", + "in_refund", + ] + and invoice.fiscal_document_type_id.code not in ["TD04", "TD08"] + ): + sign = -1 + return sign + + template_values = super().get_template_values() + template_values.update({"get_sign": get_sign}) + return template_values diff --git a/l10n_it_fatturapa_out_rc/wizard/wizard_export_fatturapa.py b/l10n_it_fatturapa_out_rc/wizard/wizard_export_fatturapa.py new file mode 100644 index 000000000000..0b6c85346375 --- /dev/null +++ b/l10n_it_fatturapa_out_rc/wizard/wizard_export_fatturapa.py @@ -0,0 +1,13 @@ +# Copyright 2021 Alex Comba - Agile Business Group +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import models + +from .efattura import EFatturaOut + + +class WizardExportFatturapa(models.TransientModel): + _inherit = "wizard.export.fatturapa" + + def _get_efattura_class(self): + return EFatturaOut diff --git a/l10n_it_fatturapa_out_sp/view/invoice_it_template.xml b/l10n_it_fatturapa_out_sp/view/invoice_it_template.xml index cf37c5a3ecde..a106a951f782 100644 --- a/l10n_it_fatturapa_out_sp/view/invoice_it_template.xml +++ b/l10n_it_fatturapa_out_sp/view/invoice_it_template.xml @@ -5,14 +5,14 @@ inherit_id="l10n_it_fatturapa_out.account_invoice_it_fattura_elettronica_body" > - + diff --git a/setup/l10n_it_fatturapa_out_rc/odoo/addons/l10n_it_fatturapa_out_rc b/setup/l10n_it_fatturapa_out_rc/odoo/addons/l10n_it_fatturapa_out_rc new file mode 120000 index 000000000000..5060727cacdd --- /dev/null +++ b/setup/l10n_it_fatturapa_out_rc/odoo/addons/l10n_it_fatturapa_out_rc @@ -0,0 +1 @@ +../../../../l10n_it_fatturapa_out_rc \ No newline at end of file diff --git a/setup/l10n_it_fatturapa_out_rc/setup.py b/setup/l10n_it_fatturapa_out_rc/setup.py new file mode 100644 index 000000000000..28c57bb64031 --- /dev/null +++ b/setup/l10n_it_fatturapa_out_rc/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)