Skip to content

Commit

Permalink
[FIX] l10n_it_edi_sdicoop: avoid tracebacks when no file, batching
Browse files Browse the repository at this point in the history
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#82349

X-original-commit: c20e3b9
Signed-off-by: William André (wan) <wan@odoo.com>
  • Loading branch information
jco-odoo committed Jan 6, 2022
1 parent 1131f81 commit 9fae154
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions addons/l10n_it_edi_sdicoop/models/account_edi_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ def _support_batching(self, move=None, state=None, company=None):

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.
'''
Expand Down Expand Up @@ -209,6 +216,10 @@ def _l10n_it_post_invoices_step_2(self, invoices):
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':
Expand All @@ -231,21 +242,22 @@ def _l10n_it_post_invoices_step_2(self, invoices):
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)
Expand Down

0 comments on commit 9fae154

Please sign in to comment.