From 2cdf080d5e9579fa9b9058985902c7402d3a6396 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Thu, 14 Sep 2017 16:58:06 +0200 Subject: [PATCH] [IMP] mass_mailing: do not auto commit emails in testing mode Otherwise the database state is committed and this leads to funny things when having mass mailing tests. --- addons/mass_mailing/models/mass_mailing.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/addons/mass_mailing/models/mass_mailing.py b/addons/mass_mailing/models/mass_mailing.py index 7050926c56a..c78cd4a5d9e 100644 --- a/addons/mass_mailing/models/mass_mailing.py +++ b/addons/mass_mailing/models/mass_mailing.py @@ -6,6 +6,7 @@ import hmac from datetime import datetime import logging import random +import threading from odoo import api, fields, models, tools, _ from odoo.exceptions import UserError @@ -676,7 +677,9 @@ class MassMailing(models.Model): composer = self.env['mail.compose.message'].with_context(active_ids=res_ids).create(composer_values) extra_context = self._get_mass_mailing_context() composer = composer.with_context(active_ids=res_ids, **extra_context) - composer.send_mail(auto_commit=True) + # auto-commit except in testing mode + auto_commit = not getattr(threading.currentThread(), 'testing', False) + composer.send_mail(auto_commit=auto_commit) mailing.state = 'done' return True