Skip to content

Commit

Permalink
fixup! edi_sale_ubl_oca: use edi.config
Browse files Browse the repository at this point in the history
  • Loading branch information
simahawk committed Nov 15, 2024
1 parent 43bfc5a commit 821a063
Showing 1 changed file with 0 additions and 65 deletions.
65 changes: 0 additions & 65 deletions edi_sale_ubl_oca/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,71 +83,6 @@ def create(self, vals_list):
.with_context(evt_from_create=None)
)

# FIXME: move to core
# TODO: test
def _edi_send_via_edi(self, exchange_type, force=False, **kw):
exchange_record = None
# If we are sending an ack, we must check if we can generate it
if exchange_type.ack_for_type_ids:
if self._edi_can_generate_ack(exchange_type):
__, exchange_record = self._edi_get_or_create_ack_record(
exchange_type, force=force
)
else:
exchange_record = self._edi_create_exchange_record(exchange_type)
if exchange_record:
exchange_record.action_exchange_generate_send(**kw)

def _edi_can_generate_ack(self, exchange_type, force=False):
"""Have to generate ack for this exchange type?
:param exchange_type: The exchange type to check.
It should be generated if:
- automation is not disabled and not forced
- origin exchange record is set (means it was originated by another record)
- origin exchange type is compatible with the configured ack types
"""
if (self.disable_edi_auto and not force) or not self.origin_exchange_record_id:
return False
return self.origin_exchange_type_id in exchange_type.ack_for_type_ids

def _edi_get_or_create_ack_record(self, exchange_type, force=False):
"""
Get or create a child record for the given exchange type.
If the record has not been sent out yet for whatever reason
(job delayed, job failed, send failed, etc)
we still want to generate a new up to date record to be sent.
:param exchange_type: The exchange type to create the record for.
:param force: If True, will force the creation of the record in case of ack type.
"""
if not self._edi_can_generate_ack(exchange_type, force=force):
return False, False
parent = self._edi_get_origin()
# Filter acks that are not valued yet.
exchange_record = self._get_exchange_record(exchange_type).filtered(
lambda x: not x.exchange_file
)
created = False
# If the record has not been sent out yet for whatever reason
# (job delayed, job failed, send failed, etc)
# we still want to generate a new up to date record to be sent.
still_pending = exchange_record.edi_exchange_state in (
"output_pending",
"output_error_on_send",
)
if not exchange_record or still_pending:
vals = exchange_record._exchange_child_record_values()
vals["parent_id"] = parent.id
# NOTE: to fully automatize this,
# is recommended to enable `quick_exec` on the type
# otherwise records will have to wait for the cron to pass by.
exchange_record = self._edi_create_exchange_record(exchange_type, vals=vals)
created = True
return created, exchange_record


class SaleOrderLine(models.Model):
_name = "sale.order.line"
Expand Down

0 comments on commit 821a063

Please sign in to comment.