[FIX] mass_mailing: ignore default_list_ids when list_ids is given

Bug
===
Since 576556d846 we merged the list
coming from the context key default_list_ids and the list given by the
user in subscription_list_ids. It worked well because the 2 fields
"list_ids" and "subscription_list_ids" were not in the same view at the
same time.

But if we want to create from the backend <mailing.contact> by giving
a value in "list_ids", the context key "default_list_ids" must be
ignored (like standard Odoo fields).

Task-2703521

Part-of: odoo/odoo#82333
This commit is contained in:
std-odoo
2022-02-16 09:39:59 +00:00
parent f53ba2950c
commit 4498ec3f7d
@@ -1,7 +1,8 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models
from odoo import _, api, fields, models
from odoo.exceptions import UserError
from odoo.osv import expression
@@ -134,8 +135,14 @@ class MassMailingContact(models.Model):
default_list_ids = self._context.get('default_list_ids')
default_list_ids = default_list_ids if isinstance(default_list_ids, (list, tuple)) else []
for vals in vals_list:
if vals.get('list_ids') and vals.get('subscription_list_ids'):
raise UserError(_('You should give either list_ids, either subscription_list_ids to create new contacts.'))
if default_list_ids:
for vals in vals_list:
if vals.get('list_ids'):
continue
current_list_ids = []
subscription_ids = vals.get('subscription_list_ids') or []
for subscription in subscription_ids: