From 202ecda9a84b0a960b7a82fd30df5c9a380c2eba Mon Sep 17 00:00:00 2001 From: Simone Orsi Date: Thu, 28 Nov 2024 08:59:03 +0100 Subject: [PATCH] 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. --- edi_oca/models/edi_exchange_consumer_mixin.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/edi_oca/models/edi_exchange_consumer_mixin.py b/edi_oca/models/edi_exchange_consumer_mixin.py index 7154e898459..8824a3768d7 100644 --- a/edi_oca/models/edi_exchange_consumer_mixin.py +++ b/edi_oca/models/edi_exchange_consumer_mixin.py @@ -404,3 +404,13 @@ 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 + if "state" in vals and "state" in self._fields: + for rec in self: + rec._event(f"on_edi_{self._table}_state_change").notify( + rec, state=vals["state"] + ) + return super().write(vals)