[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) <tde@openerp.com>
This commit is contained in:
Priyanka Kakadiya
2020-10-19 14:31:54 +00:00
committed by Thibault Delavallée
parent f5dcbb297d
commit 7f5ef74b90
2 changed files with 3 additions and 5 deletions
-2
View File
@@ -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
@@ -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):