From ef47e5d498ee05729cd4c1e00ea269416837d091 Mon Sep 17 00:00:00 2001 From: Yann Papouin <> Date: Fri, 29 Jul 2011 14:25:09 +0530 Subject: [PATCH 1/3] [FIX] crm helpdesk : Email actions sends outdated data lp bug: https://launchpad.net/bugs/801540 fixed bzr revid: dbr@tinyerp.com-20110729085509-2qm85s551cthexbf --- addons/base_action_rule/base_action_rule.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/base_action_rule/base_action_rule.py b/addons/base_action_rule/base_action_rule.py index 80c1ab464f1..cc1f43ce0dc 100644 --- a/addons/base_action_rule/base_action_rule.py +++ b/addons/base_action_rule/base_action_rule.py @@ -183,9 +183,10 @@ the rule to mark CC(mail to any other person defined in actions)."), context = {} if isinstance(ids, (str, int, long)): ids = [ids] + id = old_write(cr, uid, ids, vals, context=context) if not context.get('action'): self.pre_action(cr, uid, ids, model, context=context) - return old_write(cr, uid, ids, vals, context=context) + return id return make_call_old def _register_hook(self, cr, uid, ids, context=None): From 238cd085bbdac5f01515a08f99da5e36e0004092 Mon Sep 17 00:00:00 2001 From: "DBR (OpenERP)" Date: Thu, 4 Aug 2011 13:00:52 +0530 Subject: [PATCH 2/3] [IMP]base_action_rule : Improve the code bzr revid: dbr@tinyerp.com-20110804073052-p9zrcaq9i71jopux --- addons/base_action_rule/base_action_rule.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/addons/base_action_rule/base_action_rule.py b/addons/base_action_rule/base_action_rule.py index cc1f43ce0dc..1319302ee20 100644 --- a/addons/base_action_rule/base_action_rule.py +++ b/addons/base_action_rule/base_action_rule.py @@ -176,17 +176,15 @@ the rule to mark CC(mail to any other person defined in actions)."), return make_call_old def _write(self, old_write, model, context=None): - if context is None: - context = {} def make_call_old(cr, uid, ids, vals, context=context): if context is None: context = {} if isinstance(ids, (str, int, long)): ids = [ids] - id = old_write(cr, uid, ids, vals, context=context) + change_id = old_write(cr, uid, ids, vals, context=context) if not context.get('action'): self.pre_action(cr, uid, ids, model, context=context) - return id + return change_id return make_call_old def _register_hook(self, cr, uid, ids, context=None): From 753e0f26d36c31d9895a30a9eaba6d4ffe580016 Mon Sep 17 00:00:00 2001 From: Vo Minh Thu Date: Mon, 14 Nov 2011 12:39:15 +0100 Subject: [PATCH 3/3] [FIX] base_action_rule: removed wrong default context (it should not be the one used to create/modify the rule). Also renamed pre_action in post_action since it is done after the create or write. Removed misleading variable to capture write() return value. bzr revid: vmt@openerp.com-20111114113915-0783vjb7f2jmznj7 --- addons/base_action_rule/base_action_rule.py | 43 ++++++++++++--------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/addons/base_action_rule/base_action_rule.py b/addons/base_action_rule/base_action_rule.py index 1319302ee20..f8d0e88a100 100644 --- a/addons/base_action_rule/base_action_rule.py +++ b/addons/base_action_rule/base_action_rule.py @@ -147,7 +147,7 @@ the rule to mark CC(mail to any other person defined in actions)."), res['value'] = {'filter_id':False} return res - def pre_action(self, cr, uid, ids, model, context=None): + def post_action(self, cr, uid, ids, model, context=None): # Searching for action rules cr.execute("SELECT model.model, rule.id FROM base_action_rule rule \ LEFT JOIN ir_model model on (model.id = rule.model_id) \ @@ -156,7 +156,7 @@ the rule to mark CC(mail to any other person defined in actions)."), # Check if any rule matching with current object for obj_name, rule_id in res: if not (model == obj_name): - continue + continue # TODO add this condition in the WHERE clause above. else: obj = self.pool.get(obj_name) # If the rule doesn't involve a time condition, run it immediately @@ -166,30 +166,36 @@ the rule to mark CC(mail to any other person defined in actions)."), return True def _create(self, old_create, model, context=None): - if context is None: - context = {} - def make_call_old(cr, uid, vals, context=context): + """ + Return a wrapper around `old_create` calling both `old_create` and + `post_action`, in that order. + """ + def wrapper(cr, uid, vals, context=context): new_id = old_create(cr, uid, vals, context=context) if not context.get('action'): - self.pre_action(cr, uid, [new_id], model, context=context) + self.post_action(cr, uid, [new_id], model, context=context) return new_id - return make_call_old + return wrapper def _write(self, old_write, model, context=None): - def make_call_old(cr, uid, ids, vals, context=context): - if context is None: - context = {} + """ + Return a wrapper around `old_write` calling both `old_write` and + `post_action`, in that order. + """ + def wrapper(cr, uid, ids, vals, context=context): if isinstance(ids, (str, int, long)): ids = [ids] - change_id = old_write(cr, uid, ids, vals, context=context) + old_write(cr, uid, ids, vals, context=context) if not context.get('action'): - self.pre_action(cr, uid, ids, model, context=context) - return change_id - return make_call_old + self.post_action(cr, uid, ids, model, context=context) + return True + return wrapper def _register_hook(self, cr, uid, ids, context=None): - if context is None: - context = {} + """ + Wrap every `create` and `write` methods of the models specified by + the rules (given by `ids`). + """ for action_rule in self.browse(cr, uid, ids, context=context): model = action_rule.model_id.model obj_pool = self.pool.get(model) @@ -199,15 +205,16 @@ the rule to mark CC(mail to any other person defined in actions)."), obj_pool.base_action_ruled = True return True + def create(self, cr, uid, vals, context=None): res_id = super(base_action_rule, self).create(cr, uid, vals, context=context) self._register_hook(cr, uid, [res_id], context=context) return res_id def write(self, cr, uid, ids, vals, context=None): - res = super(base_action_rule, self).write(cr, uid, ids, vals, context=context) + super(base_action_rule, self).write(cr, uid, ids, vals, context=context) self._register_hook(cr, uid, ids, context=context) - return res + return True def _check(self, cr, uid, automatic=False, use_new_cursor=False, \ context=None):