diff options
| author | ijas ahammed <ija@odoo.com> | 2021-02-25 09:24:23 +0000 |
|---|---|---|
| committer | Dharmraj Jhala <dja@odoo.com> | 2021-03-01 09:27:25 +0000 |
| commit | b92ebf3a47b7b1263669ac020ac8c213027400ea (patch) | |
| tree | 1a4e1fe130554302473d39b4fbbb984b349c07f0 | |
| parent | ebadf16c7c38ca52ec4c5ce871c2584aaa98b91d (diff) | |
[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: Thibault Delavallee (tde) <tde@openerp.com>
| -rw-r--r-- | addons/mass_mailing/models/mailing_contact.py | 9 | ||||
| -rw-r--r-- | addons/mass_mailing/tests/test_mailing_list.py | 12 |
2 files changed, 21 insertions, 0 deletions
diff --git a/addons/mass_mailing/models/mailing_contact.py b/addons/mass_mailing/models/mailing_contact.py index 5d74fd511f9..27ce87a24ff 100644 --- a/addons/mass_mailing/models/mailing_contact.py +++ b/addons/mass_mailing/models/mailing_contact.py @@ -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) diff --git a/addons/mass_mailing/tests/test_mailing_list.py b/addons/mass_mailing/tests/test_mailing_list.py index a9c6b5a2c2e..4a67818ffe9 100644 --- a/addons/mass_mailing/tests/test_mailing_list.py +++ b/addons/mass_mailing/tests/test_mailing_list.py @@ -54,6 +54,18 @@ class TestMailingListMerge(MassMailCommon): 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 # The mailing list C contains the same email address than 'Norbert' in list B |
