From 7dea86387db28c40cc5a6aa275df07db35858c36 Mon Sep 17 00:00:00 2001 From: "Paolo (pgi)" Date: Fri, 18 Mar 2022 17:20:01 +0000 Subject: [PATCH] [IMP] l10n_it_edi_sdicoop: Added handling of duplicate sending Duplicate sending should be considered as positive outcome. We also post a message on the invoice to make the user aware. closes odoo/odoo#87292 X-original-commit: b49210bdf507850306d6f19306ea8cd6a91e3316 Signed-off-by: Josse Colpaert --- .../models/account_edi_format.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) 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 dea4c4672cd..f6ed849d479 100644 --- a/addons/l10n_it_edi_sdicoop/models/account_edi_format.py +++ b/addons/l10n_it_edi_sdicoop/models/account_edi_format.py @@ -237,9 +237,22 @@ class AccountEdiFormat(models.Model): 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'} - invoice.l10n_it_edi_transaction = False + elements = response_tree.xpath('//Errore') + error_codes = [element.find('Codice').text for element in elements] + errors = [element.find('Descrizione').text for element in elements] + # Duplicated invoice + if '00404' in error_codes: + idx = error_codes.index('00404') + invoice.message_post(body=_( + 'This invoice number had already been submitted to the SdI, so it is' + ' set as Sent. Please verify that the system is correctly configured,' + ' because the correct flow does not need to send the same invoice' + ' twice for any reason.\n' + ' Original message from the SDI: %s', errors[idx])) + to_return[invoice] = {'attachment': invoice.l10n_it_edi_attachment_id, 'success': True} + else: + to_return[invoice] = {'error': self._format_error_message(_('The invoice has been refused by the Exchange System'), errors), 'blocking_level': 'error'} + invoice.l10n_it_edi_transaction = False elif state == 'notificaMancataConsegna': if invoice._is_commercial_partner_pa(): to_return[invoice] = {'error': _(