Skip to content
Snippets Groups Projects
Commit d6758919 authored by Patrick Hoste's avatar Patrick Hoste
Browse files

[FIX] mass_mailing: fix unsubscription_date when opt_out on create


Before this commit when creating a mailing contact with a mailing
list opt_out at creation the unsubscription_date wasn't set.
Indeed, from the mailing contact view the mailing list uses an
editable list that passes all the values at create even when not set
contrary to when one update the contact only the changed values are
passed. This commit fix this issue.

Task-3070852

closes odoo/odoo#105867

Signed-off-by: default avatarWarnon Aurélien (awa) <awa@odoo.com>
parent ff8a7206
No related branches found
No related tags found
No related merge requests found
......@@ -31,7 +31,7 @@ class MassMailingContactListRel(models.Model):
def create(self, vals_list):
now = fields.Datetime.now()
for vals in vals_list:
if 'opt_out' in vals and 'unsubscription_date' not in vals:
if 'opt_out' in vals and not vals.get('unsubscription_date'):
vals['unsubscription_date'] = now if vals['opt_out'] else False
if vals.get('unsubscription_date'):
vals['opt_out'] = True
......
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from datetime import datetime
from freezegun import freeze_time
from odoo import exceptions
from odoo.addons.mass_mailing.tests.common import MassMailCommon
from odoo.tests.common import Form, users
......@@ -99,6 +102,19 @@ class TestMailingListMerge(MassMailCommon):
new = new.with_context(default_list_ids=[list_id])
self.assertFalse(any(contact.opt_out for contact in new))
with freeze_time('2022-01-01 12:00'):
contact_form = Form(self.env['mailing.contact'])
contact_form.name = 'Contact_test'
with contact_form.subscription_list_ids.new() as subscription:
subscription.list_id = self.mailing_list_1
subscription.opt_out = True
with contact_form.subscription_list_ids.new() as subscription:
subscription.list_id = self.mailing_list_2
subscription.opt_out = False
contact = contact_form.save()
self.assertEqual(contact.subscription_list_ids[0].unsubscription_date, datetime(2022, 1, 1, 12, 0, 0))
self.assertFalse(contact.subscription_list_ids[1].unsubscription_date)
@users('user_marketing')
def test_mailing_list_contact_copy_in_context_of_mailing_list(self):
MailingContact = self.env['mailing.contact']
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment