Skip to content

Commit

Permalink
edi_oca: consumer mixin trigger state event
Browse files Browse the repository at this point in the history
Models using the consumer mixing and having a state field
will now trigger a specific event when the state is updated.
  • Loading branch information
simahawk committed Dec 2, 2024
1 parent 01303a0 commit 0b9452d
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions edi_oca/models/edi_exchange_consumer_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,3 +404,20 @@ def _edi_send_via_email(
# Send the email
composer.send_mail()
return True

def write(self, vals):
# Generic event to match a state change
# TODO: this can be added to component_event for models having the state field
state_change = "state" in vals and "state" in self._fields
if state_change:
for rec in self:
rec._event(f"on_edi_{self._table}_before_state_change").notify(
rec, state=vals["state"]
)
res = super().write(vals)
if state_change:
for rec in self:
rec._event(f"on_edi_{self._table}_state_change").notify(
rec, state=vals["state"]
)
return res

0 comments on commit 0b9452d

Please sign in to comment.