From f1da5a5d3651824feb531f93e3fdbb00c91317e7 Mon Sep 17 00:00:00 2001 From: Simone Orsi Date: Thu, 28 Nov 2024 12:01:29 +0100 Subject: [PATCH] fixup! edi_oca: consumer mixin trigger state event --- edi_oca/models/edi_exchange_consumer_mixin.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/edi_oca/models/edi_exchange_consumer_mixin.py b/edi_oca/models/edi_exchange_consumer_mixin.py index 8824a3768d..513bb09a89 100644 --- a/edi_oca/models/edi_exchange_consumer_mixin.py +++ b/edi_oca/models/edi_exchange_consumer_mixin.py @@ -408,9 +408,16 @@ def _edi_send_via_email( 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 - if "state" in vals and "state" in self._fields: + 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 super().write(vals) + return res