diff --git a/l10n_it_fatturapa_out/data/invoice_it_template.xml b/l10n_it_fatturapa_out/data/invoice_it_template.xml index 64ae611f38db..6f8335659e3f 100644 --- a/l10n_it_fatturapa_out/data/invoice_it_template.xml +++ b/l10n_it_fatturapa_out/data/invoice_it_template.xml @@ -32,10 +32,7 @@ e 'line' per riga di fattura (a seconda del livello in cui sono chiamati) - + - + `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Marco Colombo + +Contributors +------------ + +- Marco Colombo +- `TAKOBI `__: + + - Simone Rubino + +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. + +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_dn/__init__.py b/l10n_it_fatturapa_out_dn/__init__.py new file mode 100644 index 000000000000..40272379f721 --- /dev/null +++ b/l10n_it_fatturapa_out_dn/__init__.py @@ -0,0 +1 @@ +from . import wizard diff --git a/l10n_it_fatturapa_out_dn/__manifest__.py b/l10n_it_fatturapa_out_dn/__manifest__.py new file mode 100644 index 000000000000..54593366f4ee --- /dev/null +++ b/l10n_it_fatturapa_out_dn/__manifest__.py @@ -0,0 +1,22 @@ +# Copyright 2021 Marco Colombo +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +{ + "name": "ITA - Fattura elettronica - Emissione - DDT", + "version": "16.0.1.0.0", + "development_status": "Beta", + "category": "Localization/Italy", + "summary": "DDT in fatture elettroniche", + "author": "Marco Colombo," "Odoo Community Association (OCA)", + "website": "https://github.com/OCA/l10n-italy", + "license": "AGPL-3", + "depends": [ + "l10n_it_fatturapa_out", + "l10n_it_delivery_note", + ], + "data": [ + "data/invoice_it_template.xml", + "wizard/wizard_export_fatturapa_view.xml", + "security/ir.model.access.csv", + ], + "installable": True, +} diff --git a/l10n_it_fatturapa_out_dn/data/invoice_it_template.xml b/l10n_it_fatturapa_out_dn/data/invoice_it_template.xml new file mode 100644 index 000000000000..500d5c87683b --- /dev/null +++ b/l10n_it_fatturapa_out_dn/data/invoice_it_template.xml @@ -0,0 +1,30 @@ + + + + + diff --git a/l10n_it_fatturapa_out_dn/pyproject.toml b/l10n_it_fatturapa_out_dn/pyproject.toml new file mode 100644 index 000000000000..4231d0cccb3d --- /dev/null +++ b/l10n_it_fatturapa_out_dn/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/l10n_it_fatturapa_out_dn/readme/CONTRIBUTORS.md b/l10n_it_fatturapa_out_dn/readme/CONTRIBUTORS.md new file mode 100644 index 000000000000..e306ea450ef2 --- /dev/null +++ b/l10n_it_fatturapa_out_dn/readme/CONTRIBUTORS.md @@ -0,0 +1,3 @@ +- Marco Colombo \<\> +- [TAKOBI](https://takobi.online): + - Simone Rubino \<\> diff --git a/l10n_it_fatturapa_out_dn/readme/DESCRIPTION.md b/l10n_it_fatturapa_out_dn/readme/DESCRIPTION.md new file mode 100644 index 000000000000..daef64c0b4c5 --- /dev/null +++ b/l10n_it_fatturapa_out_dn/readme/DESCRIPTION.md @@ -0,0 +1,21 @@ +**Italiano** + +Questo modulo consente di aggiungere le informazione relative ai DDT al +file XML della fattura elettronica versione 1.6. + + + +da inviare al Sistema di Interscambio (SdI). + + + +**English** + +This module allows you to add DDT information to the Electronic Invoice +XML file version 1.6 + + + +to be sent to the Exchange System (ES). + + diff --git a/l10n_it_fatturapa_out_dn/readme/ROADMAP.md b/l10n_it_fatturapa_out_dn/readme/ROADMAP.md new file mode 100644 index 000000000000..133c6bf86d1f --- /dev/null +++ b/l10n_it_fatturapa_out_dn/readme/ROADMAP.md @@ -0,0 +1,7 @@ +There are a couple of minor issues since l10n_it_delivery_note only +links a Note line of the invoice to the delivery note: + +- RiferimentoNumeroLinea refers to a descriptive line, but it should + enumerate (at least) the products lines +- RiferimentoNumeroLinea is always populated, but it should only be + populated when the linked lines are not all the invoice lines diff --git a/l10n_it_fatturapa_out_dn/security/ir.model.access.csv b/l10n_it_fatturapa_out_dn/security/ir.model.access.csv new file mode 100644 index 000000000000..47b4d2b449de --- /dev/null +++ b/l10n_it_fatturapa_out_dn/security/ir.model.access.csv @@ -0,0 +1,2 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_wizard_export_fatturapa,access_wizard_export_fatturapa,model_wizard_export_fatturapa,account.group_account_invoice,1,1,1,1 diff --git a/l10n_it_fatturapa_out_dn/static/description/icon.png b/l10n_it_fatturapa_out_dn/static/description/icon.png new file mode 100644 index 000000000000..1f07394c3b79 Binary files /dev/null and b/l10n_it_fatturapa_out_dn/static/description/icon.png differ diff --git a/l10n_it_fatturapa_out_dn/static/description/index.html b/l10n_it_fatturapa_out_dn/static/description/index.html new file mode 100644 index 000000000000..6cc75d4f924e --- /dev/null +++ b/l10n_it_fatturapa_out_dn/static/description/index.html @@ -0,0 +1,450 @@ + + + + + +ITA - Fattura elettronica - Emissione - DDT + + + +
+

ITA - Fattura elettronica - Emissione - DDT

+ + +

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

+

Italiano

+

Questo modulo consente di aggiungere le informazione relative ai DDT al +file XML della fattura elettronica versione 1.6.

+

https://www.fatturapa.gov.it/export/documenti/Specifiche_tecniche_del_formato_FatturaPA_V1.3.1.pdf

+

da inviare al Sistema di Interscambio (SdI).

+

https://www.fatturapa.gov.it/it/sistemainterscambio/cose-il-sdi/

+

English

+

This module allows you to add DDT information to the Electronic Invoice +XML file version 1.6

+

https://www.fatturapa.gov.it/export/documenti/Specifiche_tecniche_del_formato_FatturaPA_V1.3.1.pdf

+

to be sent to the Exchange System (ES).

+

https://www.fatturapa.gov.it/en/

+

Table of contents

+ +
+

Known issues / Roadmap

+

There are a couple of minor issues since l10n_it_delivery_note only +links a Note line of the invoice to the delivery note:

+
    +
  • RiferimentoNumeroLinea refers to a descriptive line, but it should +enumerate (at least) the products lines
  • +
  • RiferimentoNumeroLinea is always populated, but it should only be +populated when the linked lines are not all the invoice lines
  • +
+
+
+

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 to smash it by providing a detailed and welcomed +feedback.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Marco Colombo
  • +
+
+
+

Contributors

+ +
+
+

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.

+

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_dn/tests/__init__.py b/l10n_it_fatturapa_out_dn/tests/__init__.py new file mode 100644 index 000000000000..4e8c866e88fb --- /dev/null +++ b/l10n_it_fatturapa_out_dn/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import test_l10n_it_fatturapa_out_dn diff --git a/l10n_it_fatturapa_out_dn/tests/data/IT06363391001_outDDT.xml b/l10n_it_fatturapa_out_dn/tests/data/IT06363391001_outDDT.xml new file mode 100644 index 000000000000..055aeb5bd20e --- /dev/null +++ b/l10n_it_fatturapa_out_dn/tests/data/IT06363391001_outDDT.xml @@ -0,0 +1,132 @@ + + + + + IT + 06363391001 + + outDDT + FPA12 + UFPQ1O + + 06543534343 + info@yourcompany.example.com + + + + + + IT + 06363391001 + + + YourCompany + + RF01 + + + Via Milano, 1 + 00100 + Roma + AK + IT + + + 06543534343 + info@yourcompany.example.com + + + + + + IT + 06363391001 + + 06363391001 + + Public Administration + + + + Via Roma, 1 + 10100 + Torino + AK + IT + + + + + + + TD01 + EUR + 2019-08-07 + INV/2019/08/0001 + 2.30 + SI + + + DDT/00001 + 2019-08-07 + 1 + + + + + 1 + Delivery Note "DDT/00001" of 07/08/2019 + 0.00 + 0.00000 + 0.00 + 15.00 + + + 2 + Test product + 1.00 + Units + 1.00000 + 1.00 + 15.00 + + Valuta + USD + 1.00000 + 2019-08-07 + + + + 3 + Test product + 1.00 + Units + 1.00000 + 1.00 + 15.00 + + Valuta + USD + 1.00000 + 2019-08-07 + + + + 15.00 + 2.00 + 0.30 + + + + TP02 + + MP05 + 2019-08-07 + 2.30 + + + + diff --git a/l10n_it_fatturapa_out_dn/tests/test_l10n_it_fatturapa_out_dn.py b/l10n_it_fatturapa_out_dn/tests/test_l10n_it_fatturapa_out_dn.py new file mode 100644 index 000000000000..9aaacb2952f2 --- /dev/null +++ b/l10n_it_fatturapa_out_dn/tests/test_l10n_it_fatturapa_out_dn.py @@ -0,0 +1,112 @@ +# Copyright 2022 Simone Rubino - TAKOBI +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +import base64 + +from freezegun import freeze_time + +from odoo.tests import Form, tagged + +from odoo.addons.l10n_it_fatturapa_out.tests.fatturapa_common import FatturaPACommon + + +@tagged("post_install", "-at_install") +class TestFatturaOutDN(FatturaPACommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + + # See https://github.com/OCA/l10n-italy/issues/2507 + # XXX - a company named "YourCompany" alread exists + # we move it out of the way but we should do better here + cls.env.company.sudo().search([("name", "=", "YourCompany")]).write( + {"name": "YourCompany_"} + ) + + cls.env.company.name = "YourCompany" + cls.env.company.vat = "IT06363391001" + cls.env.company.fatturapa_art73 = True + cls.env.company.partner_id.street = "Via Milano, 1" + cls.env.company.partner_id.city = "Roma" + cls.env.company.partner_id.state_id = cls.env.ref("base.state_us_2").id + cls.env.company.partner_id.zip = "00100" + cls.env.company.partner_id.phone = "06543534343" + cls.env.company.email = "info@yourcompany.example.com" + cls.env.company.partner_id.country_id = cls.env.ref("base.it").id + cls.env.company.fatturapa_fiscal_position_id = cls.env.ref( + "l10n_it_fatturapa.fatturapa_RF01" + ).id + + product_form = Form(cls.env["product.product"]) + product_form.name = "Test product" + product_form.detailed_type = "product" + product_form.invoice_policy = "delivery" + cls.product = product_form.save() + + cls.delivery_note_outgoing_type = cls.env["stock.delivery.note.type"].search( + [("code", "=", "outgoing"), ("company_id", "=", cls.env.company.id)] + ) + cls.delivery_note_outgoing_type.sequence_id.prefix = "DDT/" + + def _create_so_dn_invoice(self, partner, products, date): + # Create and confirm the sale order + sales_order_form = Form(self.env["sale.order"]) + sales_order_form.partner_id = partner + sales_order_form.payment_term_id = self.env.ref( + "account.account_payment_term_immediate" + ) + for product in products: + with sales_order_form.order_line.new() as line: + line.product_id = product + line.product_uom_qty = 1 + sales_order = sales_order_form.save() + sales_order.action_confirm() + + # Validate the picking + picking = sales_order.picking_ids + picking.move_ids[0].quantity_done = 1 + picking.button_validate() + + # Invoice the delivery note + delivery_note = picking.delivery_note_id + self.assertTrue(delivery_note.type_id in self.delivery_note_outgoing_type) + delivery_note.date = date + delivery_note.action_confirm() + delivery_note.action_invoice() + + invoice = sales_order.invoice_ids + invoice.related_documents = False + return sales_order, delivery_note, invoice + + def test_01_invoice_delivery(self): + """ + DatiDDT is added in the Electronic Invoice + with reference to the lines linked to a DdT. + """ + invoice_date = "2019-08-07" + partner = self.res_partner_fatturapa_0 + products = self.product + with freeze_time(invoice_date): + sales_order, delivery_note, invoice = self._create_so_dn_invoice( + partner, products, invoice_date + ) + # Add to the invoice a line that is not linked with the DdT + invoice_form = Form(invoice) + with invoice_form.invoice_line_ids.new() as line: + line.product_id = self.product + invoice_form.save() + # we don't want to really depend on defaults for the name, here + invoice.name = "INV/2019/08/0001" + invoice.action_post() + wizard = self.wizard_model.with_context(active_ids=invoice.ids).create({}) + res = wizard.exportFatturaPA() + attachment = self.attach_model.browse(res["res_id"]) + self.set_e_invoice_file_id(attachment, "IT06363391001_outDDT.xml") + + # XML doc to be validated + xml_content = base64.decodebytes(attachment.datas) + self.check_content( + xml_content, + "IT06363391001_outDDT.xml", + module_name="l10n_it_fatturapa_out_dn", + ) diff --git a/l10n_it_fatturapa_out_dn/wizard/__init__.py b/l10n_it_fatturapa_out_dn/wizard/__init__.py new file mode 100644 index 000000000000..5196bb6ea240 --- /dev/null +++ b/l10n_it_fatturapa_out_dn/wizard/__init__.py @@ -0,0 +1 @@ +from . import wizard_export_fatturapa diff --git a/l10n_it_fatturapa_out_dn/wizard/wizard_export_fatturapa.py b/l10n_it_fatturapa_out_dn/wizard/wizard_export_fatturapa.py new file mode 100644 index 000000000000..78c41e42dd5a --- /dev/null +++ b/l10n_it_fatturapa_out_dn/wizard/wizard_export_fatturapa.py @@ -0,0 +1,83 @@ +# Copyright 2020 Marco Colommbo +# Copyright 2022 Simone Rubino - TAKOBI +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import api, fields, models + + +class WizardExportFatturapa(models.TransientModel): + _inherit = "wizard.export.fatturapa" + + @api.model + def default_get(self, fields): + res = super().default_get(fields) + invoice_ids = self.env.context.get("active_ids", False) + invoices = self.env["account.move"].browse(invoice_ids) + # enable option by default if any invoice is connected to a dn + if any(invoices.invoice_line_ids.mapped("delivery_note_id")): + res["include_transport_data"] = "dati_dn" + return res + + include_transport_data = fields.Selection( + [ + ("dati_dn", "Include DN Data"), + ], + string="DN Data", + help="Include DN data: The field must be entered when a transport " + "document associated with a deferred invoice is present", + ) + + def getDatiDDT(self, invoice): + """ + Get the data for rendering DatiDDT. + + :return: a list of dictionaries, with one dictionary per involved DdT. + Each dictionary has shape: + { + '_delivery_note': , + + 'NumeroDDT': , + + 'DataDDT': , + + '_invoice_lines': (optional) + , + 'RiferimentoNumeroLinea': (optional) + , + } + """ + self.ensure_one() + dati_ddt_list = list() + for delivery_note in invoice.delivery_note_ids: + ddt_data = { + "_delivery_note": delivery_note, + "NumeroDDT": delivery_note.name, + "DataDDT": delivery_note.date, + } + e_invoice_lines = self.get_e_invoice_lines(invoice) + + def _filterfn(li, delivery_note=delivery_note): + return li.delivery_note_id == delivery_note + + e_invoice_delivery_note_lines = e_invoice_lines.filtered(_filterfn) + if e_invoice_delivery_note_lines: + # RiferimentoNumeroLinea should not be populated + # if all the lines of the invoice + # are linked to this delivery_note, + # but we can't verify this condition + # because only note lines (not product lines) + # are linked to a delivery note. + e_invoice_lines_list = list(e_invoice_lines) + lines_refs_list = [ + e_invoice_lines_list.index(line) + 1 # NumeroLinea is 1-based + for line in e_invoice_delivery_note_lines + ] + ddt_data.update( + { + "_invoice_lines": e_invoice_delivery_note_lines, + "RiferimentoNumeroLinea": lines_refs_list, + } + ) + + dati_ddt_list.append(ddt_data) + return dati_ddt_list diff --git a/l10n_it_fatturapa_out_dn/wizard/wizard_export_fatturapa_view.xml b/l10n_it_fatturapa_out_dn/wizard/wizard_export_fatturapa_view.xml new file mode 100644 index 000000000000..dc6942288472 --- /dev/null +++ b/l10n_it_fatturapa_out_dn/wizard/wizard_export_fatturapa_view.xml @@ -0,0 +1,16 @@ + + + + wizard_export_fatturapa_form_view_dn + wizard.export.fatturapa + + + + + + + +