Skip to content

Commit 0b9452d

Browse files
committed
edi_oca: consumer mixin trigger state event
Models using the consumer mixing and having a state field will now trigger a specific event when the state is updated.
1 parent 01303a0 commit 0b9452d

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

edi_oca/models/edi_exchange_consumer_mixin.py

+17
Original file line numberDiff line numberDiff line change
@@ -404,3 +404,20 @@ def _edi_send_via_email(
404404
# Send the email
405405
composer.send_mail()
406406
return True
407+
408+
def write(self, vals):
409+
# Generic event to match a state change
410+
# TODO: this can be added to component_event for models having the state field
411+
state_change = "state" in vals and "state" in self._fields
412+
if state_change:
413+
for rec in self:
414+
rec._event(f"on_edi_{self._table}_before_state_change").notify(
415+
rec, state=vals["state"]
416+
)
417+
res = super().write(vals)
418+
if state_change:
419+
for rec in self:
420+
rec._event(f"on_edi_{self._table}_state_change").notify(
421+
rec, state=vals["state"]
422+
)
423+
return res

0 commit comments

Comments
 (0)