From 7f5ef74b902f53ff49ab54bafb72b1c55ef86bd0 Mon Sep 17 00:00:00 2001 From: Priyanka Kakadiya Date: Thu, 8 Oct 2020 07:27:26 +0000 Subject: [PATCH] [FIX] mass_mailing: do not add `opt_out` by default on mailing domains In mass mailing (_sms) when you set `Mailing Contact` as target model the `opt_out` field is added to the default domain. However as it is a computed field depending on a single mailing list given in context it should not be used that way. Moreover current implementation raises a warning as only some custom views can use this field accordingly. This commit removes `opt_out` field being set by default in mailing domain and also removes the UserError raised by the search function, thus avoiding unwanted warnings. Opt-out field is automatically taken into account when sending mass mailing on contacts (see ``_get_opt_out_list``) so removing it from domain is actually even better for coherency. Opt-out is not an option in sending process. Task Id-2300427 PR #57310 closes odoo/odoo#60262 X-original-commit: 5ccf5b51feaa348d775890e107fd30cd750699d8 Related: odoo/enterprise#14200 Signed-off-by: Thibault Delavallee (tde) --- addons/mass_mailing/models/mailing.py | 2 -- addons/mass_mailing/models/mailing_contact.py | 6 +++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/addons/mass_mailing/models/mailing.py b/addons/mass_mailing/models/mailing.py index 5136ae91624..abc63381bf7 100644 --- a/addons/mass_mailing/models/mailing.py +++ b/addons/mass_mailing/models/mailing.py @@ -771,8 +771,6 @@ class MassMailing(models.Model): if self.mailing_type == 'mail' and 'is_blacklisted' in self.env[self.mailing_model_name]._fields: mailing_domain = expression.AND([[('is_blacklisted', '=', False)], mailing_domain]) - if self.mailing_type == 'mail' and 'opt_out' in self.env[self.mailing_model_name]._fields: - mailing_domain = expression.AND([[('opt_out', '=', False)], mailing_domain]) return mailing_domain diff --git a/addons/mass_mailing/models/mailing_contact.py b/addons/mass_mailing/models/mailing_contact.py index 95627f4260e..6ebd1132820 100644 --- a/addons/mass_mailing/models/mailing_contact.py +++ b/addons/mass_mailing/models/mailing_contact.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from odoo import api, fields, models, tools, _ -from odoo.exceptions import UserError +from odoo import api, fields, models +from odoo.osv import expression class MassMailingContactListRel(models.Model): @@ -77,7 +77,7 @@ class MassMailingContact(models.Model): contacts = self.env['mailing.contact.subscription'].search([('list_id', '=', active_list_id)]) return [('id', 'in', [record.contact_id.id for record in contacts if record.opt_out == value])] else: - raise UserError(_('Search opt out cannot be executed without a unique and valid active mailing list context.')) + return expression.FALSE_DOMAIN if value else expression.TRUE_DOMAIN @api.depends('subscription_list_ids') def _compute_opt_out(self):