Skip to content

Commit 040b1db

Browse files
committed
edi_oca: refactor exchange_generate_send
Make it easier to understand how it works and avoid checks on attributes.
1 parent 0b9452d commit 040b1db

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

edi_oca/models/edi_backend.py

+18-8
Original file line numberDiff line numberDiff line change
@@ -399,17 +399,27 @@ def _cron_check_output_exchange_sync(self, **kw):
399399
backend._check_output_exchange_sync(**kw)
400400

401401
def exchange_generate_send(self, recordset, skip_generate=False, skip_send=False):
402+
"""Generate and send output files for given records.
403+
404+
If both are False, the record will be generated and sent right away
405+
with chained jobs.
406+
407+
If both `skip_generate` and `skip_send` are True, nothing will be done.
408+
:param recordset: edi.exchange.record recordset
409+
:param skip_generate: only send records
410+
:param skip_send: only generate missing output
411+
"""
402412
for rec in recordset:
403-
if skip_generate:
404-
job1 = rec
405-
else:
413+
if not skip_generate and not skip_send:
406414
job1 = rec.delayable().action_exchange_generate()
407-
if hasattr(job1, "on_done"):
408-
if not skip_send:
409-
# Chain send job.
410-
# Raise prio to max to send the record out as fast as possible.
411-
job1.on_done(rec.delayable(priority=0).action_exchange_send())
415+
# Chain send job.
416+
# Raise prio to max to send the record out as fast as possible.
417+
job1.on_done(rec.delayable(priority=0).action_exchange_send())
412418
job1.delay()
419+
elif skip_send:
420+
rec.with_delay().action_exchange_generate()
421+
elif not skip_send:
422+
rec.with_delay(priority=0).action_exchange_send()
413423

414424
def _check_output_exchange_sync(
415425
self, skip_send=False, skip_sent=True, record_ids=None

0 commit comments

Comments
 (0)