Skip to content
Snippets Groups Projects
Commit 270b2a0c authored by Paolo Gatti (pgi)'s avatar Paolo Gatti (pgi)
Browse files

[IMP] l10n_it_edi_sdicoop: retrigger receiving cron for more docs


In case we retrieve the maximum number of documents the IAP server
can send, we retrigger the cron to receive more documents, until
we get them all.

Parameter `recipient_codice_fiscale` wasn't used at all, download is
related to the proxy user which is determined by authentication on the
IAP proxy.

See odoo/iap-apps#583

closes odoo/odoo#116373

Signed-off-by: default avatarJosse Colpaert <jco@odoo.com>
parent a70f804d
No related branches found
No related tags found
No related merge requests found
......@@ -30,14 +30,22 @@ class AccountEdiFormat(models.Model):
for proxy_user in proxy_users:
company = proxy_user.company_id
try:
res = proxy_user._make_request(proxy_user._get_server_url() + '/api/l10n_it_edi/1/in/RicezioneInvoice',
params={'recipient_codice_fiscale': company.l10n_it_codice_fiscale})
res = proxy_user._make_request(proxy_user._get_server_url() + '/api/l10n_it_edi/1/in/RicezioneInvoice')
except AccountEdiProxyError as e:
res = {}
_logger.error('Error while receiving file from SdiCoop: %s', e)
proxy_acks = []
retrigger = False
for id_transaction, fattura in res.items():
# The server has a maximum number of documents it can send at a time
# If that maximum is reached, then we search for more
# by re-triggering the download cron, avoiding the timeout.
current_num, max_num = fattura.get('current_num', 0), fattura.get('max_num', 0)
retrigger = retrigger or current_num == max_num > 0
if self.env['ir.attachment'].search([('name', '=', fattura['filename']), ('res_model', '=', 'account.move')], limit=1):
# name should be unique, the invoice already exists
_logger.info('E-invoice already exist: %s', fattura['filename'])
......@@ -80,6 +88,9 @@ class AccountEdiFormat(models.Model):
except AccountEdiProxyError as e:
_logger.error('Error while receiving file from SdiCoop: %s', e)
if retrigger:
self.env.ref('l10n_it_edi.ir_cron_receive_fattura_pa_invoice')._trigger()
# -------------------------------------------------------------------------
# Export
# -------------------------------------------------------------------------
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment