[IMP] mass_mailing: improve list duplication and protect "opt-out-ness" of contacts

Before this commit, on duplication, the contacts who opted-out from the
original list have the opt-out field set to False on the duplicated list.

After this commit, on duplication, for a contact who has opted-out from the
original list,the opt-out field will be set to True on the duplicated list,
Because when a recipient opt-out from a mailing list, chances are high that he
does not want to be included in the new duplicated list.

This commit also brings some fixes to the update and create methods on the
mailing_contact_subscription model so that

- The unsubscription_date is set to now only when no unsubscription_date is
  given, because when another value for unsubscription_date is given by the
  user it should be applied

- The opt_out field is set to True when the user sets an unsubscription_date,
  because when a date is set for unsubscription_date, it means that the user
  has opted-out from the list

We also update name of mailing list when duplicating it, adding a copy
mark to it.

Finally we also avoid copying mailing_ids through m2m relationship as it
may impact existing mailings.

Task ID-2431383

closes odoo/odoo#65277

Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
This commit is contained in:
nounoubensebia
2021-03-02 14:19:34 +00:00
committed by Thibault Delavallée
parent c21d523623
commit 52df97e4f3
2 changed files with 16 additions and 5 deletions
@@ -31,13 +31,17 @@ class MassMailingContactListRel(models.Model):
def create(self, vals_list):
now = fields.Datetime.now()
for vals in vals_list:
if 'opt_out' in vals:
if 'opt_out' in vals and 'unsubscription_date' not in vals:
vals['unsubscription_date'] = now if vals['opt_out'] else False
if vals.get('unsubscription_date'):
vals['opt_out'] = True
return super().create(vals_list)
def write(self, vals):
if 'opt_out' in vals:
if 'opt_out' in vals and 'unsubscription_date' not in vals:
vals['unsubscription_date'] = fields.Datetime.now() if vals['opt_out'] else False
if vals.get('unsubscription_date'):
vals['opt_out'] = True
return super(MassMailingContactListRel, self).write(vals)
+10 -3
View File
@@ -22,11 +22,11 @@ class MassMailingList(models.Model):
contact_pct_bounce = fields.Float(compute="_compute_mailing_list_statistics", string="Percentage of Bouncing")
contact_ids = fields.Many2many(
'mailing.contact', 'mailing_contact_list_rel', 'list_id', 'contact_id',
string='Mailing Lists')
string='Mailing Lists', copy=False)
mailing_count = fields.Integer(compute="_compute_mailing_list_count", string="Number of Mailing")
mailing_ids = fields.Many2many('mailing.mailing', 'mail_mass_mailing_list_rel', string='Mass Mailings')
mailing_ids = fields.Many2many('mailing.mailing', 'mail_mass_mailing_list_rel', string='Mass Mailings', copy=False)
subscription_ids = fields.One2many('mailing.contact.subscription', 'list_id',
string='Subscription Information')
string='Subscription Information', copy=True)
is_public = fields.Boolean(default=True, help="The mailing list can be accessible by recipient in the unsubscription"
" page to allows him to update his subscription preferences.")
@@ -109,6 +109,13 @@ class MassMailingList(models.Model):
def name_get(self):
return [(list.id, "%s (%s)" % (list.name, list.contact_count)) for list in self]
def copy(self, default=None):
self.ensure_one()
default = dict(default or {},
name=_('%s (copy)', self.name),)
return super(MassMailingList, self).copy(default)
# ------------------------------------------------------
# ACTIONS
# ------------------------------------------------------