[FIX] l10n_it_edi_sdicoop: avoid tracebacks when no file, batching
When we ack a file for having correctly received the response e.g., the file is deleted on the server and will not have a file key in the reponse, at least before the server itself will have a new response to share. Before, it would traceback, while now, we do nothing. (as we are still waiting) Also, when we get the notice that the term of 2 weeks is passed, it means it is successfull. Also, for the batching we had a traceback, because it was possible to have a batching mixing step 1 and step 2, which fails doing invoices.l10n_it_edi_transaction So we added whether there is a tranaction or not in the batch key. opw-2703669 closes odoo/odoo#82358 X-original-commit: c20e3b95a82fd35c1dcefd159525f59e2c255e9d Signed-off-by: William André (wan) <wan@odoo.com>
This commit is contained in:
@@ -110,6 +110,13 @@ class AccountEdiFormat(models.Model):
|
||||
|
||||
return super()._support_batching(move=move, state=state, company=company)
|
||||
|
||||
def _get_batch_key(self, move, state):
|
||||
# OVERRIDE
|
||||
if self.code != 'fattura_pa':
|
||||
return super()._get_batch_key(move, state)
|
||||
|
||||
return move.move_type, bool(move.l10n_it_edi_transaction)
|
||||
|
||||
def _l10n_it_post_invoices_step_1(self, invoices):
|
||||
''' Send the invoices to the proxy.
|
||||
'''
|
||||
@@ -209,6 +216,10 @@ class AccountEdiFormat(models.Model):
|
||||
to_return[invoice] = {'error': _('You are not allowed to check the status of this invoice.'), 'blocking_level': 'error'}
|
||||
continue
|
||||
|
||||
if not response.get('file'): # It means there is no status update, so we can skip it
|
||||
document = invoice.edi_document_ids.filtered(lambda d: d.edi_format_id.code == 'fattura_pa')
|
||||
to_return[invoice] = {'error': document.error, 'blocking_level': document.blocking_level}
|
||||
continue
|
||||
xml = proxy_user._decrypt_data(response['file'], response['key'])
|
||||
response_tree = etree.fromstring(xml)
|
||||
if state == 'ricevutaConsegna':
|
||||
@@ -231,21 +242,22 @@ class AccountEdiFormat(models.Model):
|
||||
else: # ECO2
|
||||
to_return[invoice] = {'error': _('The invoice was refused by the addressee.'), 'blocking_level': 'error'}
|
||||
elif state == 'NotificaDecorrenzaTermini':
|
||||
to_return[invoice] = {'error': _('Expiration of the maximum term for communication of acceptance/refusal'), 'blocking_level': 'error'}
|
||||
to_return[invoice] = {'attachment': invoice.l10n_it_edi_attachment_id, 'success': True}
|
||||
proxy_acks.append(id_transaction)
|
||||
|
||||
try:
|
||||
proxy_user._make_request(server_url + '/api/l10n_it_edi/1/ack',
|
||||
params={'transaction_ids': proxy_acks})
|
||||
except AccountEdiProxyError as e:
|
||||
# Will be ignored and acked again next time.
|
||||
_logger.error('Error while acking file to SdiCoop: %s', e)
|
||||
if proxy_acks:
|
||||
try:
|
||||
proxy_user._make_request(server_url + '/api/l10n_it_edi/1/ack',
|
||||
params={'transaction_ids': proxy_acks})
|
||||
except AccountEdiProxyError as e:
|
||||
# Will be ignored and acked again next time.
|
||||
_logger.error('Error while acking file to SdiCoop: %s', e)
|
||||
|
||||
return to_return
|
||||
|
||||
def _post_fattura_pa(self, invoices):
|
||||
# OVERRIDE
|
||||
if not invoices.l10n_it_edi_transaction:
|
||||
if not invoices[0].l10n_it_edi_transaction:
|
||||
return self._l10n_it_post_invoices_step_1(invoices)
|
||||
else:
|
||||
return self._l10n_it_post_invoices_step_2(invoices)
|
||||
|
||||
Reference in New Issue
Block a user