diff --git a/l10n_it_fatturapa/controllers/main.py b/l10n_it_fatturapa/controllers/main.py index 2b7a795dcd25..5abd7b4e52f1 100644 --- a/l10n_it_fatturapa/controllers/main.py +++ b/l10n_it_fatturapa/controllers/main.py @@ -5,9 +5,6 @@ class FatturaElettronicaController(Controller): - #------------------------------------------------------ - # Report controllers - #------------------------------------------------------ @route([ '/fatturapa/preview/', ], type='http', auth='user', website=True) @@ -17,10 +14,6 @@ def pdf_preview(self, attachment_id, **data): pdf = request.env['report']._run_wkhtmltopdf( [], [], [[False, html]], None, None) pdfhttpheaders = [ - ('Content-Type', 'application/pdf'), ('Content-Length', len(pdf)), - # ( - # 'Content-Disposition', 'attachment; ' - # 'filename="fatturaelettronica%s.pdf"' % attachment_id - # ), + ('Content-Type', 'application/pdf'), ('Content-Length', len(pdf)) ] return request.make_response(pdf, headers=pdfhttpheaders) diff --git a/l10n_it_fatturapa/models/account.py b/l10n_it_fatturapa/models/account.py index 66cdf4c11c20..d89a08bcd740 100644 --- a/l10n_it_fatturapa/models/account.py +++ b/l10n_it_fatturapa/models/account.py @@ -54,7 +54,8 @@ class FatturapaPaymentDetail(models.Model): _name = "fatturapa.payment.detail" recipient = fields.Char('Recipient', size=200) fatturapa_pm_id = fields.Many2one( - 'fatturapa.payment_method', string="Fattura Elettronica Payment Method") + 'fatturapa.payment_method', string="Fattura Elettronica Payment Method" + ) payment_term_start = fields.Date('Payment Term Start') payment_days = fields.Integer('Payment Term Days') payment_due_date = fields.Date('Payment due Date') diff --git a/l10n_it_fatturapa/models/partner.py b/l10n_it_fatturapa/models/partner.py index 47be8333fb75..ad26cd687a92 100644 --- a/l10n_it_fatturapa/models/partner.py +++ b/l10n_it_fatturapa/models/partner.py @@ -75,4 +75,4 @@ def _check_codice_destinatario(self): raise ValidationError(_( "Il partner %s, con Codice Destinatario '0000000'," " deve avere o P.IVA o codice fiscale" - ) % partner.name) \ No newline at end of file + ) % partner.name) diff --git a/l10n_it_fatturapa_in/models/account.py b/l10n_it_fatturapa_in/models/account.py index 4f869fe1ef03..5b8ea991fc8c 100644 --- a/l10n_it_fatturapa_in/models/account.py +++ b/l10n_it_fatturapa_in/models/account.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -from odoo import fields, models, api, _ +from odoo import fields, models, api class AccountInvoice(models.Model): @@ -35,6 +35,7 @@ def remove_attachment_link(self): self.fatturapa_attachment_in_id = False return {'type': 'ir.actions.client', 'tag': 'reload'} + class fatturapa_article_code(models.Model): # _position = ['2.2.1.3'] _name = "fatturapa.article.code" @@ -105,4 +106,4 @@ class EInvoiceLineOtherData(models.Model): name = fields.Char("Tipo Dato", readonly=True) text_ref = fields.Char("Riferimento Testo", readonly=True) num_ref = fields.Float("Riferimento Numero", readonly=True) - date_ref = fields.Char("Riferimento Data", readonly=True) \ No newline at end of file + date_ref = fields.Char("Riferimento Data", readonly=True) diff --git a/l10n_it_fatturapa_in/tests/test_import_fatturapa_xml.py b/l10n_it_fatturapa_in/tests/test_import_fatturapa_xml.py index 91d895f271d4..b1be1d7a6468 100644 --- a/l10n_it_fatturapa_in/tests/test_import_fatturapa_xml.py +++ b/l10n_it_fatturapa_in/tests/test_import_fatturapa_xml.py @@ -91,7 +91,7 @@ def test_00_xml_import(self): self.assertEqual(line.price_unit, 3) welfare_found = True self.assertTrue(welfare_found) - self.assertTrue(len(invoice.e_invoice_line_ids)==1) + self.assertTrue(len(invoice.e_invoice_line_ids) == 1) self.assertEqual( invoice.e_invoice_line_ids[0].name, 'Prodotto di test al giorno') self.assertEqual( @@ -106,7 +106,7 @@ def test_00_xml_import(self): invoice.e_invoice_line_ids[0].tax_amount, 0) self.assertEqual( invoice.e_invoice_line_ids[0].tax_kind, 'N4') - self.assertTrue(len(invoice.e_invoice_line_ids[0].other_data_ids)==2) + self.assertTrue(len(invoice.e_invoice_line_ids[0].other_data_ids) == 2) self.assertEqual( invoice.e_invoice_line_ids[0].other_data_ids[0].text_ref, 'Riferimento') @@ -190,7 +190,7 @@ def test_04_xml_import(self): invoice.invoice_line_ids[1].invoice_line_tax_ids[0].amount, 22) self.assertEqual( invoice.invoice_line_ids[1].price_unit, 2) - self.assertTrue(len(invoice.e_invoice_line_ids)==2) + self.assertTrue(len(invoice.e_invoice_line_ids) == 2) for e_line in invoice.e_invoice_line_ids: self.assertTrue(e_line.line_number in (1, 2)) if e_line.line_number == 1: @@ -225,7 +225,8 @@ def test_05_xml_import(self): 'SC') self.assertEqual( invoice.e_invoice_line_ids[0].discount_rise_price_ids[0]. - percentage, 10) + percentage, 10 + ) self.assertEqual(invoice.amount_untaxed, 15) self.assertEqual(invoice.amount_tax, 0) self.assertEqual(invoice.amount_total, 15) @@ -417,4 +418,4 @@ def test_16_xml_import(self): invoices = self.invoice_model.browse(invoice_ids) self.assertTrue(len(invoices) == 2) for invoice in invoices: - self.assertTrue(len(invoice.invoice_line_ids) == 0) \ No newline at end of file + self.assertTrue(len(invoice.invoice_line_ids) == 0) diff --git a/l10n_it_fatturapa_in/wizard/wizard_import_fatturapa.py b/l10n_it_fatturapa_in/wizard/wizard_import_fatturapa.py index 1224139cb5e9..2045ba3528b7 100644 --- a/l10n_it_fatturapa_in/wizard/wizard_import_fatturapa.py +++ b/l10n_it_fatturapa_in/wizard/wizard_import_fatturapa.py @@ -917,7 +917,6 @@ def invoiceCreate( )) invoice_data['ftpa_withholding_type'] = Withholding.TipoRitenuta # 2.2.1 - CodeArts = self.env['fatturapa.article.code'] e_invoice_line_ids = [] for line in FatturaBody.DatiBeniServizi.DettaglioLinee: if self.e_invoice_detail_level == '2': @@ -1296,7 +1295,7 @@ def importFatturaPA(self): else: invoice_inconsistencies = '' invoice.inconsistencies = ( - generic_inconsistencies + invoice_inconsistencies) + generic_inconsistencies + invoice_inconsistencies) return { 'view_type': 'form', diff --git a/l10n_it_fatturapa_out/models/attachment.py b/l10n_it_fatturapa_out/models/attachment.py index 645dac0d16eb..e5ef87bb7881 100644 --- a/l10n_it_fatturapa_out/models/attachment.py +++ b/l10n_it_fatturapa_out/models/attachment.py @@ -3,7 +3,7 @@ # Copyright 2016 Lorenzo Battistini - Agile Business Group # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). -from odoo import fields, models, api +from odoo import fields, models class FatturaPAAttachment(models.Model): diff --git a/l10n_it_fatturapa_out/tests/fatturapa_common.py b/l10n_it_fatturapa_out/tests/fatturapa_common.py index 52abc87b442a..403ab724e1ce 100644 --- a/l10n_it_fatturapa_out/tests/fatturapa_common.py +++ b/l10n_it_fatturapa_out/tests/fatturapa_common.py @@ -133,4 +133,4 @@ def getFile(self, filename, module_name=None): if module_name is None: module_name = 'l10n_it_fatturapa_out' path = get_module_resource(module_name, 'tests', 'data', filename) - return self.getFilePath(path) \ No newline at end of file + return self.getFilePath(path) diff --git a/l10n_it_fatturapa_out/wizard/wizard_export_fatturapa.py b/l10n_it_fatturapa_out/wizard/wizard_export_fatturapa.py index 38ce62eec4f6..99970831a211 100644 --- a/l10n_it_fatturapa_out/wizard/wizard_export_fatturapa.py +++ b/l10n_it_fatturapa_out/wizard/wizard_export_fatturapa.py @@ -354,7 +354,6 @@ def _setDatiAnagraficiCessionario(self, partner, fatturapa): Nome=partner.firstname ) - if partner.eori_code: fatturapa.FatturaElettronicaHeader.CessionarioCommittente.\ DatiAnagrafici.Anagrafica.CodEORI = partner.eori_code diff --git a/l10n_it_fatturapa_out_ddt/README.rst b/l10n_it_fatturapa_out_ddt/README.rst new file mode 100644 index 000000000000..2b017a9e79c9 --- /dev/null +++ b/l10n_it_fatturapa_out_ddt/README.rst @@ -0,0 +1,78 @@ +========================= +Fattura Elettronica & DDT +========================= + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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-LGPL--3-blue.png + :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html + :alt: License: LGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fl10n--italy-lightgray.png?logo=github + :target: https://github.com/OCA/l10n-italy/tree/10.0/l10n_it_fatturapa_out_ddt + :alt: OCA/l10n-italy +.. |badge4| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/122/10.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| + +Il modulo permette all'utente di scegliere se e come riempire i campi dell'XML della fattura elettronica con i dati relativi al DDT, nei due scenari di fattura differita e fattura accompagnatoria + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +Nel wizard di esportazione della fattura elettronica, è possibile scegliere 'Includi Dati DDT' o 'Includi Dati Trasporto'. + +Nel primo caso viene gestito il blocco da valorizzare nei casi di fattura "differita" per indicare il documento con cui è stato consegnato il bene. + +Nel secondo il blocco valorizzabile nei casi di fattura "accompagnatoria" per inserire informazioni relative al trasporto + +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 +~~~~~~~ + +* Agile Business Group + +Contributors +~~~~~~~~~~~~ + +* 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. + +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_ddt/__init__.py b/l10n_it_fatturapa_out_ddt/__init__.py new file mode 100644 index 000000000000..09e999105d3c --- /dev/null +++ b/l10n_it_fatturapa_out_ddt/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). + +from . import wizard diff --git a/l10n_it_fatturapa_out_ddt/__manifest__.py b/l10n_it_fatturapa_out_ddt/__manifest__.py new file mode 100644 index 000000000000..89e43fa34cc4 --- /dev/null +++ b/l10n_it_fatturapa_out_ddt/__manifest__.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# Copyright 2018 Lorenzo Battistini +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). + +{ + "name": "Fattura Elettronica & DDT", + "summary": "Bridge module", + "version": "10.0.1.0.0", + "development_status": "Beta", + "category": "Hidden", + "website": "https://github.com/OCA/l10n-italy", + "author": "Agile Business Group, Odoo Community Association (OCA)", + "maintainers": [], + "license": "LGPL-3", + "application": False, + "installable": True, + "auto_install": True, + "depends": [ + "l10n_it_fatturapa_out", + "l10n_it_ddt", + ], + "data": [ + "wizard/wizard_export_fatturapa_view.xml" + ], +} diff --git a/l10n_it_fatturapa_out_ddt/i18n/it.po b/l10n_it_fatturapa_out_ddt/i18n/it.po new file mode 100644 index 000000000000..dbb0b7e0b7d1 --- /dev/null +++ b/l10n_it_fatturapa_out_ddt/i18n/it.po @@ -0,0 +1,50 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * l10n_it_fatturapa_out_ddt +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-09-24 16:24+0000\n" +"PO-Revision-Date: 2018-09-24 16:24+0000\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_ddt +#: model:ir.model.fields,field_description:l10n_it_fatturapa_out_ddt.field_wizard_export_fatturapa_include_ddt_data +msgid "Dati DDT" +msgstr "Dati DDT" + +#. module: l10n_it_fatturapa_out_ddt +#: model:ir.model,name:l10n_it_fatturapa_out_ddt.model_wizard_export_fatturapa +msgid "Export FatturaPA" +msgstr "Esporta fattura elettronica" + +#. module: l10n_it_fatturapa_out_ddt +#: selection:wizard.export.fatturapa,include_ddt_data:0 +msgid "Includi Dati DDT" +msgstr "Includi Dati DDT" + +#. module: l10n_it_fatturapa_out_ddt +#: model:ir.model.fields,help:l10n_it_fatturapa_out_ddt.field_wizard_export_fatturapa_include_ddt_data +msgid "Includi Dati DDT: Blocco da valorizzare nei casi di fattura \"differita\" per indicare il documento con cui è stato consegnato il bene\n" +"Includi Dati Trasporto: Blocco valorizzabile nei casi di fattura \"accompagnatoria\" per inserire informazioni relative al trasporto" +msgstr "Includi Dati DDT: Blocco da valorizzare nei casi di fattura \"differita\" per indicare il documento con cui è stato consegnato il bene\n" +"Includi Dati Trasporto: Blocco valorizzabile nei casi di fattura \"accompagnatoria\" per inserire informazioni relative al trasporto" + +#. module: l10n_it_fatturapa_out_ddt +#: selection:wizard.export.fatturapa,include_ddt_data:0 +msgid "Includi Dati Trasporto" +msgstr "Includi Dati Trasporto" + +#. module: l10n_it_fatturapa_out_ddt +#: code:addons/l10n_it_fatturapa_out_ddt/wizard/wizard_export_fatturapa.py:82 +#, python-format +msgid "TIN not set for %s" +msgstr "Partita IVA non impostata per %s" + diff --git a/l10n_it_fatturapa_out_ddt/readme/CONTRIBUTORS.rst b/l10n_it_fatturapa_out_ddt/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000000..f52b696bb04f --- /dev/null +++ b/l10n_it_fatturapa_out_ddt/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Lorenzo Battistini diff --git a/l10n_it_fatturapa_out_ddt/readme/DESCRIPTION.rst b/l10n_it_fatturapa_out_ddt/readme/DESCRIPTION.rst new file mode 100644 index 000000000000..0770e1a8d4f6 --- /dev/null +++ b/l10n_it_fatturapa_out_ddt/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +Il modulo permette all'utente di scegliere se e come riempire i campi dell'XML della fattura elettronica con i dati relativi al DDT, nei due scenari di fattura differita e fattura accompagnatoria diff --git a/l10n_it_fatturapa_out_ddt/readme/USAGE.rst b/l10n_it_fatturapa_out_ddt/readme/USAGE.rst new file mode 100644 index 000000000000..00d3d70a2524 --- /dev/null +++ b/l10n_it_fatturapa_out_ddt/readme/USAGE.rst @@ -0,0 +1,5 @@ +Nel wizard di esportazione della fattura elettronica, è possibile scegliere 'Includi Dati DDT' o 'Includi Dati Trasporto'. + +Nel primo caso viene gestito il blocco da valorizzare nei casi di fattura "differita" per indicare il documento con cui è stato consegnato il bene. + +Nel secondo il blocco valorizzabile nei casi di fattura "accompagnatoria" per inserire informazioni relative al trasporto diff --git a/l10n_it_fatturapa_out_ddt/tests/__init__.py b/l10n_it_fatturapa_out_ddt/tests/__init__.py new file mode 100644 index 000000000000..3af81e0fedfc --- /dev/null +++ b/l10n_it_fatturapa_out_ddt/tests/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). + +from . import test_fatturapa_ddt diff --git a/l10n_it_fatturapa_out_ddt/tests/data/IT06363391001_00006.xml b/l10n_it_fatturapa_out_ddt/tests/data/IT06363391001_00006.xml new file mode 100644 index 000000000000..08ca09c374cd --- /dev/null +++ b/l10n_it_fatturapa_out_ddt/tests/data/IT06363391001_00006.xml @@ -0,0 +1,108 @@ + + + + + + IT + 06363391001 + + 00006 + FPR12 + 0000000 + + 06543534343 + info@yourcompany.example.com + + test@pec.it + + + + + IT + 06363391001 + + + YourCompany + + RF01 + + + Via Milano, 1 + 00100 + Roma + AK + IT + + + 06543534343 + info@yourcompany.example.com + + + + + + IT + 07973780013 + + 07973780013 + + Cliente B2B + + + + Via Roma, 1 + 16100 + Genova + AK + IT + + + + + + + TD01 + USD + 2018-01-07 + INV/2018/0013 + 61.00 + SI + + + DDT/0100 + 2018-01-07 + 1 + + + DDT/0101 + 2018-01-07 + 2 + + + + + 1 + Mouse Optical + 2.00 + Unit(s) + 10.00 + 20.00 + 22.00 + + + 2 + Mouse Optical + 3.00 + Unit(s) + 10.00 + 30.00 + 22.00 + + + 22.00 + 50.00 + 11.00 + + + + diff --git a/l10n_it_fatturapa_out_ddt/tests/data/IT06363391001_00007.xml b/l10n_it_fatturapa_out_ddt/tests/data/IT06363391001_00007.xml new file mode 100644 index 000000000000..2a5ee87809cf --- /dev/null +++ b/l10n_it_fatturapa_out_ddt/tests/data/IT06363391001_00007.xml @@ -0,0 +1,106 @@ + + + + + + IT + 06363391001 + + 00007 + FPR12 + 0000000 + + 06543534343 + info@yourcompany.example.com + + test@pec.it + + + + + IT + 06363391001 + + + YourCompany + + RF01 + + + Via Milano, 1 + 00100 + Roma + AK + IT + + + 06543534343 + info@yourcompany.example.com + + + + + + IT + 07973780013 + + 07973780013 + + Cliente B2B + + + + Via Roma, 1 + 16100 + Genova + AK + IT + + + + + + + TD01 + USD + 2018-01-07 + INV/2018/0014 + 24.40 + SI + + + + + IT + 03297040366 + + 03297040366 + + Intermediario + + + DESTINATARIO + VENDITA + CARTONE + 0.0 + 0.0 + + + + + 1 + Mouse Optical + 2.00 + Unit(s) + 10.00 + 20.00 + 22.00 + + + 22.00 + 20.00 + 4.40 + + + + diff --git a/l10n_it_fatturapa_out_ddt/tests/test_fatturapa_ddt.py b/l10n_it_fatturapa_out_ddt/tests/test_fatturapa_ddt.py new file mode 100644 index 000000000000..5c1866eea308 --- /dev/null +++ b/l10n_it_fatturapa_out_ddt/tests/test_fatturapa_ddt.py @@ -0,0 +1,140 @@ +# -*- coding: utf-8 -*- +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). + +from odoo.addons.l10n_it_fatturapa_out.tests.fatturapa_common import ( + FatturaPACommon) + + +class TestInvoiceDDT(FatturaPACommon): + + def setUp(self): + super(TestInvoiceDDT, self).setUp() + self.carriage_condition_PF = self.env.ref( + 'l10n_it_ddt.carriage_condition_PF') + self.goods_description_CAR = self.env.ref( + 'l10n_it_ddt.goods_description_CAR') + self.transportation_reason_VEN = self.env.ref( + 'l10n_it_ddt.transportation_reason_VEN') + self.transportation_reason_VEN.to_be_invoiced = True + self.transportation_method_DES = self.env.ref( + 'l10n_it_ddt.transportation_method_DES') + + def test_e_invoice_ddt(self): + # 2 ordini, 2 DDT e 1 fattura differita + self.so1 = self.env['sale.order'].create({ + 'partner_id': self.res_partner_fatturapa_2.id, + 'partner_invoice_id': self.res_partner_fatturapa_2.id, + 'partner_shipping_id': self.res_partner_fatturapa_2.id, + 'order_line': [(0, 0, { + 'name': 'Mouse Optical', + 'product_id': self.product_product_10.id, 'product_uom_qty': 2, + 'product_uom': self.product_uom_unit.id, 'price_unit': 10, + 'tax_id': [(6, 0, {self.tax_22.id})] + })], + 'pricelist_id': self.env.ref('product.list0').id, + 'carriage_condition_id': self.carriage_condition_PF.id, + 'goods_description_id': self.goods_description_CAR.id, + 'transportation_reason_id': self.transportation_reason_VEN.id, + 'transportation_method_id': self.transportation_method_DES.id, + }) + self.so2 = self.env['sale.order'].create({ + 'partner_id': self.res_partner_fatturapa_2.id, + 'partner_invoice_id': self.res_partner_fatturapa_2.id, + 'partner_shipping_id': self.res_partner_fatturapa_2.id, + 'order_line': [(0, 0, { + 'name': 'Mouse Optical', + 'product_id': self.product_product_10.id, 'product_uom_qty': 3, + 'product_uom': self.product_uom_unit.id, 'price_unit': 10, + 'tax_id': [(6, 0, {self.tax_22.id})] + })], + 'pricelist_id': self.env.ref('product.list0').id, + 'carriage_condition_id': self.carriage_condition_PF.id, + 'goods_description_id': self.goods_description_CAR.id, + 'transportation_reason_id': self.transportation_reason_VEN.id, + 'transportation_method_id': self.transportation_method_DES.id, + }) + self.so1.action_confirm() + self.so2.action_confirm() + (self.so1.picking_ids | self.so2.picking_ids).do_transfer() + self.env['ddt.from.pickings'].with_context({ + 'active_ids': self.so1.picking_ids.ids + }).create({}).create_ddt() + self.env['ddt.from.pickings'].with_context({ + 'active_ids': self.so2.picking_ids.ids + }).create({}).create_ddt() + self.so1.ddt_ids[0].date = '2018-01-07' + self.so2.ddt_ids[0].date = '2018-01-07' + self.so1.ddt_ids[0].ddt_number = 'DDT/0100' + self.so2.ddt_ids[0].ddt_number = 'DDT/0101' + self.so1.ddt_ids[0].set_done() + self.so2.ddt_ids[0].set_done() + invoice_wizard = self.env['ddt.create.invoice'].with_context( + {'active_ids': (self.so1.ddt_ids | self.so2.ddt_ids).ids} + ).create({}) + action = invoice_wizard.create_invoice() + invoice_ids = action['domain'][0][2] + invoice = self.env['account.invoice'].browse(invoice_ids[0]) + self.set_sequences(6, 13, '2018-01-07') + invoice.date_invoice = '2018-01-07' + invoice.action_invoice_open() + wizard = self.wizard_model.with_context( + {'active_ids': [invoice.id]} + ).create({}) + # default_get must set include_ddt_data + self.assertEqual(wizard.include_ddt_data, 'dati_ddt') + res = wizard.exportFatturaPA() + attachment = self.attach_model.browse(res['res_id']) + xml_content = attachment.datas.decode('base64') + self.assertEqual( + attachment.datas_fname, 'IT06363391001_00006.xml') + self.check_content( + xml_content, 'IT06363391001_00006.xml', + module_name='l10n_it_fatturapa_out_ddt' + ) + + # fattura accompagnatoria + self.so3 = self.env['sale.order'].create({ + 'partner_id': self.res_partner_fatturapa_2.id, + 'partner_invoice_id': self.res_partner_fatturapa_2.id, + 'partner_shipping_id': self.res_partner_fatturapa_2.id, + 'order_line': [(0, 0, { + 'name': 'Mouse Optical', + 'product_id': self.product_product_10.id, 'product_uom_qty': 2, + 'product_uom': self.product_uom_unit.id, 'price_unit': 10, + 'tax_id': [(6, 0, {self.tax_22.id})] + })], + 'pricelist_id': self.env.ref('product.list0').id, + 'carriage_condition_id': self.carriage_condition_PF.id, + 'goods_description_id': self.goods_description_CAR.id, + 'transportation_reason_id': self.transportation_reason_VEN.id, + 'transportation_method_id': self.transportation_method_DES.id, + }) + self.so3.action_confirm() + self.so3.picking_ids[0].do_transfer() + self.env['ddt.from.pickings'].with_context({ + 'active_ids': self.so3.picking_ids.ids + }).create({}).create_ddt() + self.so3.ddt_ids[0].carrier_id = self.intermediario.id + self.so3.ddt_ids[0].set_done() + invoice_wizard = self.env['ddt.create.invoice'].with_context( + {'active_ids': self.so3.ddt_ids.ids} + ).create({}) + action = invoice_wizard.create_invoice() + invoice_ids = action['domain'][0][2] + invoice = self.env['account.invoice'].browse(invoice_ids[0]) + self.set_sequences(7, 14, '2018-01-07') + invoice.date_invoice = '2018-01-07' + invoice.action_invoice_open() + wizard = self.wizard_model.with_context( + {'active_ids': [invoice.id]} + ).create({}) + wizard.include_ddt_data = 'dati_trasporto' + res = wizard.exportFatturaPA() + attachment = self.attach_model.browse(res['res_id']) + xml_content = attachment.datas.decode('base64') + self.assertEqual( + attachment.datas_fname, 'IT06363391001_00007.xml') + self.check_content( + xml_content, 'IT06363391001_00007.xml', + module_name='l10n_it_fatturapa_out_ddt' + ) diff --git a/l10n_it_fatturapa_out_ddt/wizard/__init__.py b/l10n_it_fatturapa_out_ddt/wizard/__init__.py new file mode 100644 index 000000000000..be4e4d181cb5 --- /dev/null +++ b/l10n_it_fatturapa_out_ddt/wizard/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). + +from . import wizard_export_fatturapa diff --git a/l10n_it_fatturapa_out_ddt/wizard/wizard_export_fatturapa.py b/l10n_it_fatturapa_out_ddt/wizard/wizard_export_fatturapa.py new file mode 100644 index 000000000000..450e1aa8c584 --- /dev/null +++ b/l10n_it_fatturapa_out_ddt/wizard/wizard_export_fatturapa.py @@ -0,0 +1,96 @@ +# -*- coding: utf-8 -*- +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). + +from odoo import models, fields, api, _ +from odoo.exceptions import UserError +from odoo.addons.l10n_it_fatturapa.bindings.fatturapa_v_1_2 import ( + DatiDDTType, + DatiTrasportoType, + DatiAnagraficiVettoreType, + IdFiscaleType, + AnagraficaType +) + + +class WizardExportFatturapa(models.TransientModel): + _inherit = "wizard.export.fatturapa" + + @api.model + def default_get(self, fields): + res = super(WizardExportFatturapa, self).default_get(fields) + invoice_ids = self.env.context.get('active_ids', False) + invoices = self.env['account.invoice'].browse(invoice_ids) + for invoice in invoices: + for line in invoice.invoice_line_ids: + if line.ddt_line_id: + res['include_ddt_data'] = 'dati_ddt' + return res + return res + + include_ddt_data = fields.Selection([ + ('dati_ddt', 'Includi Dati DDT'), + ('dati_trasporto', 'Includi Dati Trasporto'), + ], + string="Dati DDT", + help='Includi Dati DDT: Blocco da valorizzare nei casi di fattura ' + '"differita" per ' + 'indicare il documento con cui e\' stato consegnato il bene\n' + 'Includi Dati Trasporto: Blocco valorizzabile nei casi di ' + 'fattura "accompagnatoria" per ' + 'inserire informazioni relative al trasporto' + ) + + def setDatiDDT(self, invoice, body): + res = super(WizardExportFatturapa, self).setDatiDDT( + invoice, body) + if self.include_ddt_data == 'dati_ddt': + inv_lines_by_ddt = {} + for line in invoice.invoice_line_ids: + if ( + line.ddt_line_id and + line.ddt_line_id.package_preparation_id.ddt_number and + line.ddt_line_id.package_preparation_id.date + ): + key = ( + line.ddt_line_id.package_preparation_id.ddt_number, + line.ddt_line_id.package_preparation_id.date[:10] + ) + if key not in inv_lines_by_ddt: + inv_lines_by_ddt[key] = [] + inv_lines_by_ddt[key].append(line.ftpa_line_number) + for key in sorted(inv_lines_by_ddt.iterkeys()): + DatiDDT = DatiDDTType( + NumeroDDT=key[0], + DataDDT=key[1] + ) + for line_number in inv_lines_by_ddt[key]: + DatiDDT.RiferimentoNumeroLinea.append(line_number) + body.DatiGenerali.DatiDDT.append(DatiDDT) + elif self.include_ddt_data == 'dati_trasporto': + body.DatiGenerali.DatiTrasporto = DatiTrasportoType( + MezzoTrasporto=invoice.transportation_method_id.name or None, + CausaleTrasporto=invoice.transportation_reason_id.name or None, + NumeroColli=invoice.parcels or None, + Descrizione=invoice.goods_description_id.name or None, + PesoLordo='%.2f' % invoice.gross_weight, + PesoNetto='%.2f' % invoice.weight, + TipoResa=invoice.incoterms_id.code or None + ) + if invoice.carrier_id: + if not invoice.carrier_id.vat: + raise UserError( + _('TIN not set for %s') % invoice.carrier_id.name) + body.DatiGenerali.DatiTrasporto.DatiAnagraficiVettore = ( + DatiAnagraficiVettoreType()) + if invoice.carrier_id.fiscalcode: + body.DatiGenerali.DatiTrasporto.DatiAnagraficiVettore.\ + CodiceFiscale = invoice.carrier_id.fiscalcode + body.DatiGenerali.DatiTrasporto.DatiAnagraficiVettore.\ + IdFiscaleIVA = IdFiscaleType( + IdPaese=invoice.carrier_id.vat[0:2], + IdCodice=invoice.carrier_id.vat[2:] + ) + body.DatiGenerali.DatiTrasporto.DatiAnagraficiVettore.\ + Anagrafica = AnagraficaType( + Denominazione=invoice.carrier_id.name) + return res diff --git a/l10n_it_fatturapa_out_ddt/wizard/wizard_export_fatturapa_view.xml b/l10n_it_fatturapa_out_ddt/wizard/wizard_export_fatturapa_view.xml new file mode 100644 index 000000000000..b4a5c71fdac9 --- /dev/null +++ b/l10n_it_fatturapa_out_ddt/wizard/wizard_export_fatturapa_view.xml @@ -0,0 +1,14 @@ + + + + wizard_export_fatturapa_form_view_ddt + wizard.export.fatturapa + + + + + + + + + diff --git a/l10n_it_ipa/model/partner.py b/l10n_it_ipa/model/partner.py index 9cdd8551fde7..66854870242e 100644 --- a/l10n_it_ipa/model/partner.py +++ b/l10n_it_ipa/model/partner.py @@ -13,4 +13,4 @@ class ResPartner(models.Model): _inherit = 'res.partner' ipa_code = fields.Char(string='IPA Code') - is_pa = fields.Boolean("Public administration") \ No newline at end of file + is_pa = fields.Boolean("Public administration")