[FIX] base_action_rule: attempt to reuse creator language when evaluating action...
authorOlivier Dony <odo@openerp.com>
Wed, 12 Feb 2014 11:39:24 +0000 (12:39 +0100)
committerOlivier Dony <odo@openerp.com>
Wed, 12 Feb 2014 11:39:24 +0000 (12:39 +0100)
Some filters needs to be evaluated with the same
language as their author, e.g. when searching on
translatable field values. When a time-based
action is processed by the scheduled task,
we should thus attempt to reuse the same
language as the author of the corresponding
filter.

bzr revid: odo@openerp.com-20140212113924-77sh4oj6dl2qwqka

addons/base_action_rule/base_action_rule.py

index 3d45407..37c4980 100644 (file)
@@ -242,6 +242,13 @@ class base_action_rule(osv.osv):
             if action.filter_id:
                 domain = eval(action.filter_id.domain)
                 ctx.update(eval(action.filter_id.context))
+                if 'lang' not in ctx:
+                    # Filters might be language-sensitive, attempt to reuse creator lang
+                    # as we are usually running this as super-user in background
+                    [filter_meta] = action.filter_id.perm_read()
+                    user_id = filter_meta['write_uid'] and filter_meta['write_uid'][0] or \
+                                    filter_meta['create_uid'][0]
+                    ctx['lang'] = self.pool['res.users'].browse(cr, uid, user_id).lang
             record_ids = model.search(cr, uid, domain, context=ctx)
 
             # determine when action should occur for the records