Odoo separates ‘contacts’ from ‘mailing list contacts,’ and in different use cases, it is necessary to add contacts to mailing lists.
Welcome!
human made "AI" (advises & inputs) forum by Odoo professionals, experts and enthusiasts challenging real use cases with standard solutions!
-> solutions should be applicable for Odoo community or online (at the limit with Studio), all without custom modules.
This question has been flagged
2
Replies
199
Views
compact version tested on Odoo 19.0:
MAILING_LIST_ID = 1 # malinglist ID
for p in records.filtered('email'):
if env['mailing.contact'].search([('email', '=', p.email), ('list_ids', 'in', MAILING_LIST_ID)], limit=1):
continue
env['mailing.contact'].create({
'name': p.name,
'email': p.email,
'country_id': p.country_id.id or False,
'list_ids': [(4, MAILING_LIST_ID)]
})
- activate the developer mode and go to settings->technical-> server actions
- create the following action and contextual action (using button) to make it available under actions from the contact app (use list view to select several/all contacts):

Code:
# Define the target mailing list, as an action should be created per mailing list
TARGET_LIST = 'xyz'
target_list = env['mailing.list'].search([('name', '=', TARGET_LIST)], limit=1)
mailing_contacts = env['mailing.contact'].search([('list_ids.name', '=', TARGET_LIST)])
for rec in records:
# Ensure email exists
if rec.email:
# Check if email already exists in the target mailing list
if not any(contact.email == rec.email for contact in mailing_contacts):
# Create new contact if not duplicate
new_contact = env['mailing.contact'].create({
'name': rec.name,
'email': rec.email,
'title_id': rec.title.id if rec.title else False,
'company_name': rec.parent_name if rec.parent_name else False,
'country_id': rec.country_id.id if rec.country_id else False,
'tag_ids': [(6, 0, rec.category_id.ids)] if rec.category_id else False,
})
# Subscribe to the target mailing list (if the list exists)
if target_list:
new_contact.write({'list_ids': [(4, target_list.id)]})
action = {'type': 'ir.actions.act_window_close'}
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign up| Related Posts | Replies | Views | Activity | |
|---|---|---|---|---|
|
|
1
Aug 25
|
138 | ||
|
|
2
Mar 26
|
246 | ||
|
|
1
Sep 25
|
221 | ||
|
|
1
Aug 25
|
150 | ||
|
|
1
Apr 26
|
145 |
