[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#67094 Task-id: 2431344 X-original-commit: b92ebf3a47b7b1263669ac020ac8c213027400ea Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
This commit is contained in:
committed by
Dharmraj Jhala
parent
56097c56e1
commit
836f962404
@@ -146,6 +146,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
|
||||
|
||||
Reference in New Issue
Block a user