From 4057bfadc45bb96f0ec22b95e7cd2832a7384d7b Mon Sep 17 00:00:00 2001 From: Lorenzo Battistini Date: Thu, 13 Dec 2018 15:45:01 +0100 Subject: [PATCH] ADD TD20 doc type (#725) IMP l10n_it_fiscal_document_type to be sure that doc type is always set FIX l10n_it_fatturapa_out to use the fiscal doc type --- l10n_it_fatturapa_out/__manifest__.py | 2 +- .../wizard/wizard_export_fatturapa.py | 4 +--- l10n_it_fiscal_document_type/__manifest__.py | 2 +- .../data/fiscal.document.type.csv | 1 + .../models/account_invoice.py | 11 +++++++++++ l10n_it_fiscal_document_type/tests/test_doc_type.py | 5 +++++ 6 files changed, 20 insertions(+), 5 deletions(-) diff --git a/l10n_it_fatturapa_out/__manifest__.py b/l10n_it_fatturapa_out/__manifest__.py index 8d4d98fdadbf..26e508b868c3 100644 --- a/l10n_it_fatturapa_out/__manifest__.py +++ b/l10n_it_fatturapa_out/__manifest__.py @@ -5,7 +5,7 @@ { 'name': 'Italian Localization - Fattura elettronica - Emissione', - 'version': '12.0.1.0.0', + 'version': '12.0.1.0.1', 'development_status': 'Beta', 'category': 'Localization/Italy', 'summary': 'Emissione fatture elettroniche', diff --git a/l10n_it_fatturapa_out/wizard/wizard_export_fatturapa.py b/l10n_it_fatturapa_out/wizard/wizard_export_fatturapa.py index a4c65f3d26ad..325aa7b5f32b 100644 --- a/l10n_it_fatturapa_out/wizard/wizard_export_fatturapa.py +++ b/l10n_it_fatturapa_out/wizard/wizard_export_fatturapa.py @@ -486,9 +486,7 @@ def setDatiGeneraliDocumento(self, invoice, body): raise UserError( _('Invoice does not have a number.')) - TipoDocumento = 'TD01' - if invoice.type == 'out_refund': - TipoDocumento = 'TD04' + TipoDocumento = invoice.fiscal_document_type_id.code ImportoTotaleDocumento = invoice.amount_total if invoice.split_payment: ImportoTotaleDocumento += invoice.amount_sp diff --git a/l10n_it_fiscal_document_type/__manifest__.py b/l10n_it_fiscal_document_type/__manifest__.py index 02cfbd88332b..da7221a8d2fe 100644 --- a/l10n_it_fiscal_document_type/__manifest__.py +++ b/l10n_it_fiscal_document_type/__manifest__.py @@ -6,7 +6,7 @@ { 'name': 'Italian Localization - ' 'Tipi di documento fiscale per dichiarativi', - 'version': '12.0.1.0.0', + 'version': '12.0.1.1.0', 'category': 'Localisation/Italy', 'author': "Link It srl, Odoo Community Association (OCA)", 'website': 'https://github.com/OCA/l10n-italy/tree/12.0/' diff --git a/l10n_it_fiscal_document_type/data/fiscal.document.type.csv b/l10n_it_fiscal_document_type/data/fiscal.document.type.csv index e4b74452cce1..cfed78e41f7f 100755 --- a/l10n_it_fiscal_document_type/data/fiscal.document.type.csv +++ b/l10n_it_fiscal_document_type/data/fiscal.document.type.csv @@ -11,3 +11,4 @@ id,code,name,out_invoice,in_invoice,out_refund,in_refund,priority 6,TD10,fattura di acquisto intracomunitario beni,False,True,False,False,3 7,TD11,fattura di acquisto intracomunitario servizi,False,True,False,False,3 8,TD12,documento riepilogativo,False,True,False,False,3 +13,TD20,autofattura,True,False,False,False,3 diff --git a/l10n_it_fiscal_document_type/models/account_invoice.py b/l10n_it_fiscal_document_type/models/account_invoice.py index b4079f054b73..2b84d0f4566d 100755 --- a/l10n_it_fiscal_document_type/models/account_invoice.py +++ b/l10n_it_fiscal_document_type/models/account_invoice.py @@ -12,6 +12,17 @@ def _set_document_fiscal_type(self): if dt: self.fiscal_document_type_id = dt[0] + @api.model + def create(self, vals): + invoice = super(AccountInvoice, self).create(vals) + if not invoice.fiscal_document_type_id: + dt = self._get_document_fiscal_type( + invoice.type, invoice.partner_id, invoice.fiscal_position_id, + invoice.journal_id) + if dt: + invoice.fiscal_document_type_id = dt[0] + return invoice + def _get_document_fiscal_type(self, type=None, partner=None, fiscal_position=None, journal=None): dt = [] diff --git a/l10n_it_fiscal_document_type/tests/test_doc_type.py b/l10n_it_fiscal_document_type/tests/test_doc_type.py index 8e9fb03ae84d..c9d808c45e69 100644 --- a/l10n_it_fiscal_document_type/tests/test_doc_type.py +++ b/l10n_it_fiscal_document_type/tests/test_doc_type.py @@ -21,3 +21,8 @@ def test_doc_type(self): }) invoice._set_document_fiscal_type() self.assertEqual(invoice.fiscal_document_type_id.id, self.TD01.id) + + invoice2 = self.inv_model.create({ + 'partner_id': self.partner3.id + }) + self.assertEqual(invoice2.fiscal_document_type_id.id, self.TD01.id)