[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 <jco@odoo.com>
This commit is contained in:
Paolo (pgi)
2022-01-20 22:05:06 +00:00
parent 7638bada9c
commit 583b48cedd
3 changed files with 13 additions and 6 deletions
@@ -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."))
)
+7 -3
View File
@@ -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'
@@ -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'}