From af6305722fd3a67be43547c3a759a3584d898d1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 23 Oct 2015 16:19:50 +0200 Subject: [PATCH] [FIX] mail: server action: do not send directly email notifications This is a backport of a fix in 9, revision 890f1302c7175e24887e66a2f8b973e72fb4c7e9. In this revision a context key is added wshen evaluating server actions. Notification emails created during a server action will be set in the queue and not send directly. --- addons/email_template/ir_actions.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/addons/email_template/ir_actions.py b/addons/email_template/ir_actions.py index 3e7d2c1c67a..5304b6f6cbc 100644 --- a/addons/email_template/ir_actions.py +++ b/addons/email_template/ir_actions.py @@ -79,5 +79,18 @@ class actions_server(osv.Model): force_send=False, raise_exception=False, context=context) return False + def _get_eval_context(self, cr, uid, action, context=None): + """ Override the method giving the evaluation context but also the + context used in all subsequent calls. Add the mail_notify_force_send + key set to False in the context. This way all notification emails linked + to the currently executed action will be set in the queue instead of + sent directly. This will avoid possible break in transactions. """ + eval_context = super(actions_server, self)._get_eval_context(cr, uid, action, context=context) + # re-dictify, because eval_context['context'] is a frozendict + ctx = dict(eval_context.get('context', {})) + ctx['mail_notify_force_send'] = False + eval_context['context'] = ctx + return eval_context + # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: