Is your feature request related to a problem?
Events are easily triggered several times, for instance an event on a write may be triggered each time a write is done on the same record.
Describe the solution you'd like
In most if not all cases, we'd like an event to be triggered only once for the same case. E.g. 2 write on a stock.picking should lead to a single event.
Describe alternatives you've considered
N/A
Additional context
We could use Cursor Callbacks to accumulate events and deduplicate them, and trigger them at once in precommit.
Since Callbacks have a data attribute, we could use self.env.cr.precommit.data to store the events and their payloads, then have a single trigger.
Very roughly
def notify(self, event, payload):
if not self.env.cr.precommit.data.get("events_data"):
@self.env.cr.precommit.add
def _trigger_all_events():
# consume all self.env.cr.precommit.data["events_data"]
self.env.cr.precommit.data.setdefault("events_data", {}).update(...)
Not a small change since maybe in some cases we do actually want several events, so maybe it cannot be a full replacement. Another change is that events would be triggered before commit, so it changes the execution order.
Is your feature request related to a problem?
Events are easily triggered several times, for instance an event on a write may be triggered each time a write is done on the same record.
Describe the solution you'd like
In most if not all cases, we'd like an event to be triggered only once for the same case. E.g. 2 write on a
stock.pickingshould lead to a single event.Describe alternatives you've considered
N/A
Additional context
We could use Cursor Callbacks to accumulate events and deduplicate them, and trigger them at once in precommit.
Since Callbacks have a data attribute, we could use
self.env.cr.precommit.datato store the events and their payloads, then have a single trigger.Very roughly
Not a small change since maybe in some cases we do actually want several events, so maybe it cannot be a full replacement. Another change is that events would be triggered before commit, so it changes the execution order.