Skip to content

Commit

Permalink
edi_oca: refactor exchange_generate_send
Browse files Browse the repository at this point in the history
Make it easier to understand how it works and avoid checks on attributes.
  • Loading branch information
simahawk committed Dec 2, 2024
1 parent 0b9452d commit 040b1db
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions edi_oca/models/edi_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,17 +399,27 @@ def _cron_check_output_exchange_sync(self, **kw):
backend._check_output_exchange_sync(**kw)

def exchange_generate_send(self, recordset, skip_generate=False, skip_send=False):
"""Generate and send output files for given records.
If both are False, the record will be generated and sent right away
with chained jobs.
If both `skip_generate` and `skip_send` are True, nothing will be done.
:param recordset: edi.exchange.record recordset
:param skip_generate: only send records
:param skip_send: only generate missing output
"""
for rec in recordset:
if skip_generate:
job1 = rec
else:
if not skip_generate and not skip_send:
job1 = rec.delayable().action_exchange_generate()
if hasattr(job1, "on_done"):
if not skip_send:
# Chain send job.
# Raise prio to max to send the record out as fast as possible.
job1.on_done(rec.delayable(priority=0).action_exchange_send())
# Chain send job.
# Raise prio to max to send the record out as fast as possible.
job1.on_done(rec.delayable(priority=0).action_exchange_send())
job1.delay()
elif skip_send:
rec.with_delay().action_exchange_generate()
elif not skip_send:
rec.with_delay(priority=0).action_exchange_send()

def _check_output_exchange_sync(
self, skip_send=False, skip_sent=True, record_ids=None
Expand Down

0 comments on commit 040b1db

Please sign in to comment.