Skip to content
Snippets Groups Projects
Commit b92ebf3a authored by ijas ahammed's avatar ijas ahammed Committed by Dharmraj Jhala
Browse files

[FIX] mass_mailing: allow duplicating mailing contact from mailing list


Before this commit:
While trying to duplicate a mailing contact within particular
mailing list, it  throws an user error saysing that 'A mailing
contact cannot subscribe to the same mailing list multiple times.'

After this commit:
User can duplicate a mailing contact from a mailing list without
the user error. In this case, we simply remove the default_list_ids
from the context, because all the mailing lists will be simply be
copied over from the existing contact and so we don't have to
re-add the default ones.

closes odoo/odoo#66827

Task-id: 2431344
Signed-off-by: default avatarThibault Delavallee (tde) <tde@openerp.com>
parent ebadf16c
Branches
Tags
No related merge requests found
......@@ -140,6 +140,15 @@ class MassMailingContact(models.Model):
return super(MassMailingContact, self.with_context(default_list_ids=False)).create(vals_list)
@api.returns('self', lambda value: value.id)
def copy(self, default=None):
""" Cleans the default_list_ids while duplicating mailing contact in context of
a mailing list because we already have subscription lists copied over for newly
created contact, no need to add the ones from default_list_ids again """
if self.env.context.get('default_list_ids'):
self = self.with_context(default_list_ids=False)
return super().copy(default)
@api.model
def name_create(self, name):
name, email = self.get_name_email(name)
......
......@@ -53,6 +53,18 @@ class TestMailingListMerge(MassMailCommon):
new = new.with_context(default_list_ids=[list_id])
self.assertFalse(any(contact.opt_out for contact in new))
@users('user_marketing')
def test_mailing_list_contact_copy_in_context_of_mailing_list(self):
MailingContact = self.env['mailing.contact']
contact_1 = MailingContact.create({
'name': 'Sam',
'email': 'gamgee@shire.com',
'subscription_list_ids': [(0, 0, {'list_id': self.mailing_list_3.id})],
})
# Copy the contact with default_list_ids in context, which should not raise anything
contact_2 = contact_1.with_context(default_list_ids=self.mailing_list_3.ids).copy()
self.assertEqual(contact_1.list_ids, contact_2.list_ids, 'Should copy the existing mailing list(s)')
@users('user_marketing')
def test_mailing_list_merge(self):
# TEST CASE: Merge A,B into the existing mailing list C
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment