From 583b48ceddb6600f78ffe457382a25fdb0d19181 Mon Sep 17 00:00:00 2001 From: "Paolo (pgi)" Date: Fri, 14 Jan 2022 17:32:20 +0000 Subject: [PATCH] [FIX] l10n_it_edi_sdicoop: Success on send for b2b invoices B2b invoices have no success notification event (notificaEsito), so invoices can be considered successfully sent right after posting. closes odoo/odoo#83145 Task: https://www.odoo.com/web#id=2729771&model=project.task Spec: https://www.fatturapa.gov.it/export/documenti/ws/trasmissione/v3.x/Istruzioni-per-il-servizio-SDICoop-Trasmissione-versione3.2.pdf Ref: https://www.fatturapa.gov.it/it/norme-e-regole/DocumentazioneSDI/ X-original-commit: 110ef3868fd0a05f4393c78b0c5bb10a515e34ce Signed-off-by: Josse Colpaert --- addons/l10n_it_edi/models/account_edi_format.py | 2 +- addons/l10n_it_edi/models/account_invoice.py | 10 +++++++--- .../l10n_it_edi_sdicoop/models/account_edi_format.py | 7 +++++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/addons/l10n_it_edi/models/account_edi_format.py b/addons/l10n_it_edi/models/account_edi_format.py index fa468d902a3..9b16fbc8576 100644 --- a/addons/l10n_it_edi/models/account_edi_format.py +++ b/addons/l10n_it_edi/models/account_edi_format.py @@ -154,7 +154,7 @@ class AccountEdiFormat(models.Model): if invoice.l10n_it_einvoice_id: invoice.l10n_it_einvoice_id.unlink() res = invoice.invoice_generate_xml() - if len(invoice.commercial_partner_id.l10n_it_pa_index or '') == 6: + if invoice._is_commercial_partner_pa(): invoice.message_post( body=(_("Invoices for PA are not managed by Odoo, you can download the document and send it on your own.")) ) diff --git a/addons/l10n_it_edi/models/account_invoice.py b/addons/l10n_it_edi/models/account_invoice.py index e0c7c10505b..7895fde702a 100644 --- a/addons/l10n_it_edi/models/account_invoice.py +++ b/addons/l10n_it_edi/models/account_invoice.py @@ -81,6 +81,12 @@ class AccountMove(models.Model): ) return {'attachment': attachment} + def _is_commercial_partner_pa(self): + """ + Returns True if the destination of the FatturaPA belongs to the Public Administration. + """ + return len(self.commercial_partner_id.l10n_it_pa_index or '') == 6 + def _prepare_fatturapa_export_values(self): self.ensure_one() @@ -132,9 +138,7 @@ class AccountMove(models.Model): return True return False - formato_trasmissione = "FPR12" - if len(self.commercial_partner_id.l10n_it_pa_index or '1') == 6: - formato_trasmissione = "FPA12" + formato_trasmissione = "FPA12" if self._is_commercial_partner_pa() else "FPR12" if self.move_type == 'out_invoice': document_type = 'TD01' diff --git a/addons/l10n_it_edi_sdicoop/models/account_edi_format.py b/addons/l10n_it_edi_sdicoop/models/account_edi_format.py index 7ed1e9ac1a1..ba5d12bf23b 100644 --- a/addons/l10n_it_edi_sdicoop/models/account_edi_format.py +++ b/addons/l10n_it_edi_sdicoop/models/account_edi_format.py @@ -136,7 +136,7 @@ class AccountEdiFormat(models.Model): }) invoice.l10n_it_edi_attachment_id = attachment - if len(invoice.commercial_partner_id.l10n_it_pa_index or '') == 6: + if invoice._is_commercial_partner_pa(): invoice.message_post( body=(_("Invoices for PA are not managed by Odoo, you can download the document and send it on your own.")) ) @@ -223,7 +223,10 @@ class AccountEdiFormat(models.Model): xml = proxy_user._decrypt_data(response['file'], response['key']) response_tree = etree.fromstring(xml) if state == 'ricevutaConsegna': - to_return[invoice] = {'error': _('The invoice has been succesfully transmitted. The addressee has 15 days to accept or reject it.')} + if invoice._is_commercial_partner_pa(): + to_return[invoice] = {'error': _('The invoice has been succesfully transmitted. The addressee has 15 days to accept or reject it.')} + else: + to_return[invoice] = {'attachment': invoice.l10n_it_edi_attachment_id, 'success': True} elif state == 'notificaScarto': errors = [element.find('Descrizione').text for element in response_tree.xpath('//Errore')] to_return[invoice] = {'error': self._format_error_message(_('The invoice has been refused by the Exchange System'), errors), 'blocking_level': 'error'}