From d4356263f272cf25e6e7d29b2c4221522304af54 Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Wed, 11 Jun 2014 11:46:00 +0200 Subject: [PATCH] [FIX] base_action_rule: do not repeatedly trigger already-executed rules based on time condition A programming error introduced at rco@openerp.com-20121220142445-emzzvhlw400q37c9 fails to properly check when a rule has already been executed in the past. Time-based rules should only be executed if the trigger date is in the past and: - either they never executed before - or the last execution date is older than the trigger date --- addons/base_action_rule/base_action_rule.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/addons/base_action_rule/base_action_rule.py b/addons/base_action_rule/base_action_rule.py index 988cff1b972..2488ebcb946 100644 --- a/addons/base_action_rule/base_action_rule.py +++ b/addons/base_action_rule/base_action_rule.py @@ -235,7 +235,10 @@ class base_action_rule(osv.osv): action_ids = self.search(cr, uid, action_dom, context=context) for action in self.browse(cr, uid, action_ids, context=context): now = datetime.now() - last_run = get_datetime(action.last_run) if action.last_run else False + if action.last_run: + last_run = get_datetime(action.last_run) + else: + last_run = datetime.utcfromtimestamp(0) # retrieve all the records that satisfy the action's condition model = self.pool.get(action.model_id.model) @@ -268,7 +271,7 @@ class base_action_rule(osv.osv): if not record_dt: continue action_dt = get_datetime(record_dt) + delay - if last_run and (last_run <= action_dt < now) or (action_dt < now): + if last_run <= action_dt < now: try: self._process(cr, uid, action, [record.id], context=context) except Exception: