From f5e844829e4c512851ec04d50cc7e689eda8e434 Mon Sep 17 00:00:00 2001 From: Ciro Urselli Date: Thu, 11 Jun 2020 17:31:17 +0200 Subject: [PATCH 1/3] [IMP] extend wt_types selection with new code and add tax_id for daticassa --- l10n_it_withholding_tax/i18n/it.po | 4 ++-- .../i18n/l10n_it_withholding_tax.pot | 4 ++-- l10n_it_withholding_tax/models/withholding_tax.py | 10 +++++++--- l10n_it_withholding_tax/views/withholding_tax.xml | 3 ++- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/l10n_it_withholding_tax/i18n/it.po b/l10n_it_withholding_tax/i18n/it.po index 51ae32999e3d..1e36c2078cca 100644 --- a/l10n_it_withholding_tax/i18n/it.po +++ b/l10n_it_withholding_tax/i18n/it.po @@ -166,7 +166,7 @@ msgid "Date Stop" msgstr "Data fine" #. module: l10n_it_withholding_tax -#: model:ir.model.fields,field_description:l10n_it_withholding_tax.field_withholding_tax__use_daticassaprev_for_enasarco +#: model:ir.model.fields,field_description:l10n_it_withholding_tax.field_withholding_tax__use_daticassaprev msgid "DatiCassa export" msgstr "Esportazione DatiCassa" @@ -419,7 +419,7 @@ msgid "Set to Due" msgstr "Imposta a dovuto" #. module: l10n_it_withholding_tax -#: model:ir.model.fields,help:l10n_it_withholding_tax.field_withholding_tax__use_daticassaprev_for_enasarco +#: model:ir.model.fields,help:l10n_it_withholding_tax.field_withholding_tax__use_daticassaprev msgid "" "Setting this, while exporting e-invoice XML, Enasarco data will be also " "added to DatiCassaPrevidenziale" diff --git a/l10n_it_withholding_tax/i18n/l10n_it_withholding_tax.pot b/l10n_it_withholding_tax/i18n/l10n_it_withholding_tax.pot index 03e38268a833..d7585362616d 100644 --- a/l10n_it_withholding_tax/i18n/l10n_it_withholding_tax.pot +++ b/l10n_it_withholding_tax/i18n/l10n_it_withholding_tax.pot @@ -158,7 +158,7 @@ msgid "Date Stop" msgstr "" #. module: l10n_it_withholding_tax -#: model:ir.model.fields,field_description:l10n_it_withholding_tax.field_withholding_tax__use_daticassaprev_for_enasarco +#: model:ir.model.fields,field_description:l10n_it_withholding_tax.field_withholding_tax__use_daticassaprev msgid "DatiCassa export" msgstr "" @@ -406,7 +406,7 @@ msgid "Set to Due" msgstr "" #. module: l10n_it_withholding_tax -#: model:ir.model.fields,help:l10n_it_withholding_tax.field_withholding_tax__use_daticassaprev_for_enasarco +#: model:ir.model.fields,help:l10n_it_withholding_tax.field_withholding_tax__use_daticassaprev msgid "Setting this, while exporting e-invoice XML, Enasarco data will be also added to DatiCassaPrevidenziale" msgstr "" diff --git a/l10n_it_withholding_tax/models/withholding_tax.py b/l10n_it_withholding_tax/models/withholding_tax.py index d0414ee2f561..18539f4f5f42 100644 --- a/l10n_it_withholding_tax/models/withholding_tax.py +++ b/l10n_it_withholding_tax/models/withholding_tax.py @@ -65,12 +65,16 @@ def _default_wt_journal(self): wt_types = fields.Selection([ ('enasarco', 'Enasarco tax'), ('ritenuta', 'Withholding tax'), + ('inps', 'Inps Tax'), + ('enpam', 'Enpam Tax'), + ('other', 'Other Tax') ], 'Withholding tax type', required=True, default='ritenuta') - use_daticassaprev_for_enasarco = fields.Boolean( - "DatiCassa export", + use_daticassaprev = fields.Boolean( + "DatiCassa export", oldname='use_daticassaprev_for_enasarco', help="Setting this, while exporting e-invoice XML, " - "Enasarco data will be also added to DatiCassaPrevidenziale" + "data will be also added to DatiCassaPrevidenziale" ) + daticassprev_tax_id = fields.Many2one('account.tax') @api.one @api.constrains('rate_ids') diff --git a/l10n_it_withholding_tax/views/withholding_tax.xml b/l10n_it_withholding_tax/views/withholding_tax.xml index ec403b532fcc..d7d17af6a8c4 100644 --- a/l10n_it_withholding_tax/views/withholding_tax.xml +++ b/l10n_it_withholding_tax/views/withholding_tax.xml @@ -38,7 +38,8 @@ - + + From 9c9cd173ca101ad23f4318887d36eaa164319ac1 Mon Sep 17 00:00:00 2001 From: Ciro Urselli Date: Fri, 12 Jun 2020 18:09:08 +0200 Subject: [PATCH 2/3] [IMP] use causale_pagamento for all withholding tax type --- l10n_it_withholding_tax_causali/views/withholding_tax.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/l10n_it_withholding_tax_causali/views/withholding_tax.xml b/l10n_it_withholding_tax_causali/views/withholding_tax.xml index 244414c3febe..8016fe665d6a 100644 --- a/l10n_it_withholding_tax_causali/views/withholding_tax.xml +++ b/l10n_it_withholding_tax_causali/views/withholding_tax.xml @@ -6,7 +6,7 @@ - + From 629f931d98c3c991acef668a2a689716e1314959 Mon Sep 17 00:00:00 2001 From: Ciro Urselli Date: Mon, 15 Jun 2020 14:49:52 +0200 Subject: [PATCH 3/3] [IMP] improve wizard_export_fatturapa with new 1.6 xml tack specific --- .../tests/data/IT06363391001_00014.xml | 11 +- .../tests/data/IT06363391001_00015.xml | 11 +- .../tests/data/IT06363391001_00016.xml | 11 +- .../tests/data/IT06363391001_00017.xml | 109 +++++++++++++ .../tests/data/IT06363391001_00018.xml | 125 ++++++++++++++ .../tests/data/IT06363391001_00019.xml | 121 ++++++++++++++ .../tests/test_fatturapa_wt.py | 153 +++++++++++++++++- .../wizard/wizard_export_fatturapa.py | 107 ++++++------ 8 files changed, 585 insertions(+), 63 deletions(-) create mode 100644 l10n_it_fatturapa_out_wt/tests/data/IT06363391001_00017.xml create mode 100644 l10n_it_fatturapa_out_wt/tests/data/IT06363391001_00018.xml create mode 100644 l10n_it_fatturapa_out_wt/tests/data/IT06363391001_00019.xml diff --git a/l10n_it_fatturapa_out_wt/tests/data/IT06363391001_00014.xml b/l10n_it_fatturapa_out_wt/tests/data/IT06363391001_00014.xml index 365f5ed0d81e..62e62d11764d 100644 --- a/l10n_it_fatturapa_out_wt/tests/data/IT06363391001_00014.xml +++ b/l10n_it_fatturapa_out_wt/tests/data/IT06363391001_00014.xml @@ -70,6 +70,12 @@ 20.00 A + + RT04 + 0.83 + 8.25 + A + 12.20 SI @@ -84,11 +90,6 @@ 10.00 22.00 SI - - CASSA-PREV - ENASARCO TC07 (8.25%) - 0.83 - 22.00 diff --git a/l10n_it_fatturapa_out_wt/tests/data/IT06363391001_00015.xml b/l10n_it_fatturapa_out_wt/tests/data/IT06363391001_00015.xml index 9169c047d7c3..499f80b90df4 100644 --- a/l10n_it_fatturapa_out_wt/tests/data/IT06363391001_00015.xml +++ b/l10n_it_fatturapa_out_wt/tests/data/IT06363391001_00015.xml @@ -72,6 +72,12 @@ 20.00 A + + RT04 + 0.83 + 8.25 + A + TC07 8.25 @@ -93,11 +99,6 @@ 10.00 22.00 SI - - CASSA-PREV - ENASARCO TC07 (8.25%) - 0.83 - 22.00 diff --git a/l10n_it_fatturapa_out_wt/tests/data/IT06363391001_00016.xml b/l10n_it_fatturapa_out_wt/tests/data/IT06363391001_00016.xml index ef6d31bbf1db..e4a0d31db6d5 100644 --- a/l10n_it_fatturapa_out_wt/tests/data/IT06363391001_00016.xml +++ b/l10n_it_fatturapa_out_wt/tests/data/IT06363391001_00016.xml @@ -71,6 +71,12 @@ 2.00 20.00 A + + + RT04 + 0.83 + 8.25 + A TC07 @@ -94,11 +100,6 @@ 0.00 SI N2 - - CASSA-PREV - ENASARCO TC07 (8.25%) - 0.83 - 0.00 diff --git a/l10n_it_fatturapa_out_wt/tests/data/IT06363391001_00017.xml b/l10n_it_fatturapa_out_wt/tests/data/IT06363391001_00017.xml new file mode 100644 index 000000000000..24d061d89797 --- /dev/null +++ b/l10n_it_fatturapa_out_wt/tests/data/IT06363391001_00017.xml @@ -0,0 +1,109 @@ + + + + + IT + 06363391001 + + 00014 + 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 + + B2B Customer + + + + Via Roma, 1 + 16100 + Genova + AK + IT + + + + + + + TD01 + EUR + 2019-01-07 + INV/2019/0017 + + RT02 + 2.00 + 20.00 + A + + + RT03 + 0.53 + 5.25 + A + + 12.20 + SI + + + + + 1 + Service + 1.000 + Unit(s) + 10.00000 + 10.00 + 22.00 + SI + + + 22.00 + 10.00 + 2.20 + + + + TP02 + + MP05 + 2019-02-28 + 9.67 + + + + \ No newline at end of file diff --git a/l10n_it_fatturapa_out_wt/tests/data/IT06363391001_00018.xml b/l10n_it_fatturapa_out_wt/tests/data/IT06363391001_00018.xml new file mode 100644 index 000000000000..9f83d464bfcf --- /dev/null +++ b/l10n_it_fatturapa_out_wt/tests/data/IT06363391001_00018.xml @@ -0,0 +1,125 @@ + + + + + IT + 06363391001 + + 00015 + 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 + + B2B Customer + + + + Via Roma, 1 + 16100 + Genova + AK + IT + + + + + + + TD01 + EUR + 2019-01-07 + INV/2019/0018 + + RT02 + 2.00 + 20.00 + A + + + RT03 + 0.53 + 5.25 + A + + + TC22 + 5.25 + 0.53 + 0.00 + N2 + + 12.20 + SI + + + + + 1 + Service + 1.000 + Unit(s) + 10.00000 + 10.00 + 22.00 + SI + + + 22.00 + 10.00 + 2.20 + + + 0.00 + N2 + 0.83 + 0.00 + Escluso Art. 13 5C DPR 633/72 + + + + TP02 + + MP05 + 2019-02-28 + 9.67 + + + + \ No newline at end of file diff --git a/l10n_it_fatturapa_out_wt/tests/data/IT06363391001_00019.xml b/l10n_it_fatturapa_out_wt/tests/data/IT06363391001_00019.xml new file mode 100644 index 000000000000..cb3baaf639b5 --- /dev/null +++ b/l10n_it_fatturapa_out_wt/tests/data/IT06363391001_00019.xml @@ -0,0 +1,121 @@ + + + + + IT + 06363391001 + + 00016 + 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 + + B2B Customer + + + + Via Roma, 1 + 16100 + Genova + AK + IT + + + + + + + TD01 + EUR + 2019-01-07 + INV/2019/0019 + + RT02 + 2.00 + 20.00 + A + + + RT03 + 0.53 + 5.25 + A + + + TC22 + 5.25 + 0.53 + 0.00 + N2 + + 10.00 + SI + + + + + 1 + Service + 1.000 + Unit(s) + 10.00000 + 10.00 + 0.00 + SI + N2 + + + 0.00 + N2 + 10.83 + 0.00 + Escluso Art. 13 5C DPR 633/72 + + + + TP02 + + MP05 + 2019-02-28 + 7.47 + + + + \ No newline at end of file diff --git a/l10n_it_fatturapa_out_wt/tests/test_fatturapa_wt.py b/l10n_it_fatturapa_out_wt/tests/test_fatturapa_wt.py index 598dacd1182f..9381823ee797 100644 --- a/l10n_it_fatturapa_out_wt/tests/test_fatturapa_wt.py +++ b/l10n_it_fatturapa_out_wt/tests/test_fatturapa_wt.py @@ -56,12 +56,30 @@ def setUp(self): 'journal_id': self.journal_misc.id, 'wt_types': 'enasarco', 'payment_term': self.payment_term_15.id, + 'causale_pagamento_id': self.env.ref( + 'l10n_it_causali_pagamento.a').id, 'rate_ids': [(0, 0, { 'tax': 8.25, 'base': 1, })] } self.enasarco = self.env['withholding.tax'].create(wt_vals) + wt_vals = { + 'name': 'INPS', + 'code': 'INPS', + 'account_receivable_id': self.wt_account_receivable.id, + 'account_payable_id': self.wt_account_payable.id, + 'journal_id': self.journal_misc.id, + 'wt_types': 'enasarco', + 'payment_term': self.payment_term_15.id, + 'causale_pagamento_id': self.env.ref( + 'l10n_it_causali_pagamento.a').id, + 'rate_ids': [(0, 0, { + 'tax': 5.25, + 'base': 1, + })] + } + self.inps = self.env['withholding.tax'].create(wt_vals) def test_e_invoice_wt(self): self.set_sequences(13, '2019-01-07') @@ -143,7 +161,8 @@ def test_e_invoice_wt_enas_1(self): Fill DatiCassaPrevidenziale with Enasarco data """ self.set_sequences(15, '2019-01-07') - self.enasarco.use_daticassaprev_for_enasarco = True + self.enasarco.use_daticassaprev = True + self.enasarco.daticassprev_tax_id = self.tax_0 invoice = self.invoice_model.create({ 'date_invoice': '2019-01-07', 'partner_id': self.res_partner_fatturapa_2.id, @@ -187,7 +206,8 @@ def test_e_invoice_wt_enas_2(self): when DatiRiepilogo already has 0 VAT """ self.set_sequences(16, '2019-01-07') - self.enasarco.use_daticassaprev_for_enasarco = True + self.enasarco.use_daticassaprev = True + self.enasarco.daticassprev_tax_id = self.tax_0 invoice = self.invoice_model.create({ 'date_invoice': '2019-01-07', 'partner_id': self.res_partner_fatturapa_2.id, @@ -224,3 +244,132 @@ def test_e_invoice_wt_enas_2(self): self.check_content( xml_content, 'IT06363391001_00016.xml', module_name='l10n_it_fatturapa_out_wt') + +def test_e_invoice_wt_inps_0(self): + self.set_sequences(17, '2019-01-07') + invoice = self.invoice_model.create({ + 'date_invoice': '2019-01-07', + 'partner_id': self.res_partner_fatturapa_2.id, + 'journal_id': self.sales_journal.id, + 'account_id': self.a_recv.id, + 'payment_term_id': self.account_payment_term.id, + 'user_id': self.user_demo.id, + 'type': 'out_invoice', + 'currency_id': self.EUR.id, + 'invoice_line_ids': [ + (0, 0, { + 'account_id': self.a_sale.id, + 'name': 'Service', + 'quantity': 1, + 'uom_id': self.product_uom_unit.id, + 'price_unit': 10, + 'invoice_line_tax_ids': [(6, 0, [self.tax_22.id])], + 'invoice_line_tax_wt_ids': [(6, 0, [ + self.wt1040.id, + self.inps.id, + ])] + }), + ], + }) + invoice._onchange_invoice_line_wt_ids() + invoice.action_invoice_open() + res = self.run_wizard(invoice.id) + + attachment = self.attach_model.browse(res['res_id']) + self.set_e_invoice_file_id(attachment, 'IT06363391001_00017.xml') + + # XML doc to be validated + xml_content = base64.decodebytes(attachment.datas) + self.check_content( + xml_content, 'IT06363391001_00017.xml', + module_name='l10n_it_fatturapa_out_wt') + +def test_e_invoice_wt_inps_1(self): + """ + Fill DatiCassaPrevidenziale with INPS data + """ + self.set_sequences(18, '2019-01-07') + self.inps.use_daticassaprev = True + self.inps.daticassprev_tax_id = self.tax_0 + invoice = self.invoice_model.create({ + 'date_invoice': '2019-01-07', + 'partner_id': self.res_partner_fatturapa_2.id, + 'journal_id': self.sales_journal.id, + 'account_id': self.a_recv.id, + 'payment_term_id': self.account_payment_term.id, + 'user_id': self.user_demo.id, + 'type': 'out_invoice', + 'currency_id': self.EUR.id, + 'invoice_line_ids': [ + (0, 0, { + 'account_id': self.a_sale.id, + 'name': 'Service', + 'quantity': 1, + 'uom_id': self.product_uom_unit.id, + 'price_unit': 10, + 'invoice_line_tax_ids': [(6, 0, [self.tax_22.id])], + 'invoice_line_tax_wt_ids': [(6, 0, [ + self.wt1040.id, + self.inps.id, + ])] + }), + ], + }) + invoice._onchange_invoice_line_wt_ids() + invoice.action_invoice_open() + res = self.run_wizard(invoice.id) + + attachment = self.attach_model.browse(res['res_id']) + self.set_e_invoice_file_id(attachment, 'IT06363391001_00018.xml') + + # XML doc to be validated + xml_content = base64.decodebytes(attachment.datas) + self.check_content( + xml_content, 'IT06363391001_00018.xml', + module_name='l10n_it_fatturapa_out_wt') + +def test_e_invoice_wt_inps_2(self): + """ + Fill DatiCassaPrevidenziale with INPS data, + when DatiRiepilogo already has 0 VAT + """ + self.set_sequences(19, '2019-01-07') + self.inps.use_daticassaprev = True + self.inps.daticassprev_tax_id = self.tax_0 + invoice = self.invoice_model.create({ + 'date_invoice': '2019-01-07', + 'partner_id': self.res_partner_fatturapa_2.id, + 'journal_id': self.sales_journal.id, + 'account_id': self.a_recv.id, + 'payment_term_id': self.account_payment_term.id, + 'user_id': self.user_demo.id, + 'type': 'out_invoice', + 'currency_id': self.EUR.id, + 'invoice_line_ids': [ + (0, 0, { + 'account_id': self.a_sale.id, + 'name': 'Service', + 'quantity': 1, + 'uom_id': self.product_uom_unit.id, + 'price_unit': 10, + 'invoice_line_tax_ids': [(6, 0, [self.tax_0.id])], + 'invoice_line_tax_wt_ids': [(6, 0, [ + self.wt1040.id, + self.inps.id, + ])] + }), + ], + }) + invoice._onchange_invoice_line_wt_ids() + invoice.action_invoice_open() + res = self.run_wizard(invoice.id) + + attachment = self.attach_model.browse(res['res_id']) + self.set_e_invoice_file_id(attachment, 'IT06363391001_00019.xml') + + # XML doc to be validated + xml_content = base64.decodebytes(attachment.datas) + self.check_content( + xml_content, 'IT06363391001_00019.xml', + module_name='l10n_it_fatturapa_out_wt') + \ No newline at end of file diff --git a/l10n_it_fatturapa_out_wt/wizard/wizard_export_fatturapa.py b/l10n_it_fatturapa_out_wt/wizard/wizard_export_fatturapa.py index a4e003f0ba15..be56c7b4f25e 100644 --- a/l10n_it_fatturapa_out_wt/wizard/wizard_export_fatturapa.py +++ b/l10n_it_fatturapa_out_wt/wizard/wizard_export_fatturapa.py @@ -11,77 +11,102 @@ DatiRiepilogoType ) +WT_TAX_CODE = { + 'inps': 'RT03', + 'enasarco': 'RT04', + 'enpam': 'RT05', + 'other': 'RT06' +} + +TC_CODE = { + 'inps': 'TC22', + 'enasarco': 'TC07', + 'enpam': 'TC09', +} class WizardExportFatturapa(models.TransientModel): _inherit = "wizard.export.fatturapa" - + + def getTipoRitenuta(self, wt_types, partner): + if wt_types == 'ritenuta': + if partner.is_company: + tipoRitenuta = 'RT02' + else: + tipoRitenuta = 'RT01' + else: + tipoRitenuta = WT_TAX_CODE[wt_types] + return tipoRitenuta + def setDatiGeneraliDocumento(self, invoice, body): res = super(WizardExportFatturapa, self).setDatiGeneraliDocumento( invoice, body) - ritenuta_lines = invoice.withholding_tax_line_ids.filtered( - lambda x: x.withholding_tax_id.wt_types == 'ritenuta') - if len(ritenuta_lines) > 1: - raise UserError( - _("More than one withholding tax in invoice!")) + ritenuta_lines = invoice.withholding_tax_line_ids + # if len(ritenuta_lines) > 1: + # raise UserError( + # _("More than one withholding tax in invoice!")) for wt_line in ritenuta_lines: if not wt_line.withholding_tax_id.causale_pagamento_id.code: raise UserError(_('Missing payment reason for ' 'withholding tax %s!') % wt_line.withholding_tax_id.name) - body.DatiGenerali.DatiGeneraliDocumento.DatiRitenuta\ - = DatiRitenutaType( - TipoRitenuta="RT02" if invoice.partner_id.is_company - else "RT01", # RT02 persona giuridica + tipoRitenuta = self.getTipoRitenuta( + wt_line.withholding_tax_id.wt_types, + invoice.partner_id + ) + body.DatiGenerali.DatiGeneraliDocumento.DatiRitenuta.append( + DatiRitenutaType( + TipoRitenuta=tipoRitenuta, ImportoRitenuta='%.2f' % float_round(wt_line.tax, 2), AliquotaRitenuta='%.2f' % float_round( wt_line.withholding_tax_id.tax, 2), CausalePagamento=wt_line.withholding_tax_id. causale_pagamento_id.code - ) - enasarco_lines = invoice.withholding_tax_line_ids.filtered( - lambda x: x.withholding_tax_id.wt_types == 'enasarco') - for enas_line in enasarco_lines: - if enas_line.withholding_tax_id.use_daticassaprev_for_enasarco: + )) + if wt_line.withholding_tax_id.use_daticassaprev: + tax_id = wt_line.withholding_tax_id.daticassprev_tax_id + tax_kind = tax_id.kind_id.code body.DatiGenerali.DatiGeneraliDocumento.\ DatiCassaPrevidenziale.append( DatiCassaPrevidenzialeType( - TipoCassa='TC07', + TipoCassa=TC_CODE[wt_line.withholding_tax_id.wt_types], AlCassa='%.2f' % float_round( - enas_line.withholding_tax_id.tax, 2), + wt_line.withholding_tax_id.tax, 2), ImportoContributoCassa='%.2f' % float_round( - enas_line.tax, 2), + wt_line.tax, 2), AliquotaIVA='0.00', - Natura='N2' + Natura=tax_kind, ) ) return res - def get_n2_tax_riepilogo(self, body): + def get_tax_riepilogo(self, body, tax_id): for riepilogo in body.DatiBeniServizi.DatiRiepilogo: - if float(riepilogo.AliquotaIVA) == 0 and riepilogo.Natura == 'N2': + if float(riepilogo.AliquotaIVA) == 0.0 \ + and riepilogo.Natura == tax_id.kind_id.code: return riepilogo def setDatiRiepilogo(self, invoice, body): res = super(WizardExportFatturapa, self).setDatiRiepilogo( invoice, body) - enasarco_lines_to_write = invoice.withholding_tax_line_ids.filtered( - lambda x: x.withholding_tax_id.wt_types == 'enasarco' and - x.withholding_tax_id.use_daticassaprev_for_enasarco + wt_lines_to_write = invoice.withholding_tax_line_ids.filtered( + lambda x: x.withholding_tax_id.wt_types not in ('ritenuta', 'other') + and x.withholding_tax_id.use_daticassaprev ) - if enasarco_lines_to_write: - n2_riepilogo = self.get_n2_tax_riepilogo(body) - enasarco_base = sum(enasarco_lines_to_write.mapped('tax')) - if n2_riepilogo: - base_amount = float(n2_riepilogo.ImponibileImporto) - base_amount += enasarco_base - n2_riepilogo.ImponibileImporto = '%.2f' % float_round(base_amount, 2) + for wt_line in wt_lines_to_write: + tax_id = wt_line.withholding_tax_id.daticassprev_tax_id + tax_riepilogo = self.get_tax_riepilogo(body, tax_id) + if tax_riepilogo: + base_amount = float(tax_riepilogo.ImponibileImporto) + base_amount += wt_line.tax + tax_riepilogo.ImponibileImporto = '%.2f' % float_round( + base_amount, 2) else: riepilogo = DatiRiepilogoType( AliquotaIVA='0.00', - ImponibileImporto='%.2f' % float_round(enasarco_base, 2), + ImponibileImporto='%.2f' % float_round(wt_line.tax, 2), Imposta='0.00', - Natura='N2', - RiferimentoNormativo='Escluso Art. 13 5C DPR 633/72', + Natura=tax_id.kind_id.code, + RiferimentoNormativo=tax_id.law_reference, ) body.DatiBeniServizi.DatiRiepilogo.append(riepilogo) return res @@ -92,18 +117,8 @@ def setDettaglioLinea( DettaglioLinea = super(WizardExportFatturapa, self).setDettaglioLinea( line_no, line, body, price_precision, uom_precision ) - for wt in line.invoice_line_tax_wt_ids: - if wt.wt_types == 'enasarco': - amount = wt.compute_tax(line.price_subtotal)['tax'] - DettaglioLinea.AltriDatiGestionali.append( - AltriDatiGestionaliType( - TipoDato="CASSA-PREV", - RiferimentoTesto=('ENASARCO TC07 (%s%%)' % wt.tax), - RiferimentoNumero='%.2f' % float_round(amount, 2), - ) - ) - else: - DettaglioLinea.Ritenuta = 'SI' + if any([wt for wt in line.invoice_line_tax_wt_ids]): + DettaglioLinea.Ritenuta = 'SI' return DettaglioLinea def setDatiPagamento(self, invoice, body):