diff --git a/edi_oca/models/edi_backend.py b/edi_oca/models/edi_backend.py index 6791a1f1d9..4527df3e24 100644 --- a/edi_oca/models/edi_backend.py +++ b/edi_oca/models/edi_backend.py @@ -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