FUNCTIONALITY:
I would like to notify users in a discussion channel every time a new lead is created, including the link to the newly created record. I am doing this for a client who has Odoo SAAS (so, no access to source code on a deployment I control)
METHOD:
To do so, I am triggering a python code from an automated action in the CRM.LEAD. I would like to do this for leads, but I can't quite find a trigger that triggers when a new lead is created. (I can't see On Create available for leads) so I am doing this when the stage is NEW.
PROBLEM:
With that said, the issue is that I don't seem to be able to include the URL in the text body that resolves to the record.
PYTHON CODE Associated to Action:
#Find the channel by name channel = env['discuss.channel'].search([('name', '=', 'biz-dev')], limit=1) # Post the message to the found channel if channel: for lead in records: lead_url = f'/web#id={lead.id}&view_type=form&model=crm.lead' notification = f'' # Build the message content with the link message_content = ( f"New lead created: {lead.name}\n" f"Contact Name: {lead.contact_name}\n" f"Phone: {lead.phone}\n" f"Description: {lead.description}\n\n{notification}" ) # Post the message to the discussion channel channel.message_post( body=message_content, subtype_xmlid='mail.mt_comment' ) else: # Handle the case where the channel is not found print(f"Channel with name 'biz-dev' not found.")
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Accounting
- Inventory
- PoS
- Project
- MRP
This question has been flagged
2
Replies
1971
Views
First, use On save as the Trigger and Created on in When updating
Next, use the following code as a guide:
I can't seem to be able to get it to work, I have the following now, but get a error when putting in a form on the website.
Could you please let me know what could be wrong?
This is added in the automated actions,
#Find the channel by name
channel = env['discuss.channel'].search([('name', '=', 'algemeen')], limit=1)
# Post the message to the found channel
if channel:
for lead in records:
lead_url = f'lead.id} ">View Lead'
notification = f'View Lead: {lead.name}'
# Build the message content with the link
message_content = (
f"New lead created: {lead.name}\n"
f"Contact Name: {lead.contact_name}\n"
f"Phone: {lead.phone}\n"
f"Description: {lead.description}\n\n{notification}"
f"{lead_url}\n"
)
# Post the message to the discussion channel
channel.message_post(
body=message_content,
message_type= 'comment',
subtype_xmlid='mail.mt_comment',
body_is_html=True
)
else:
# Handle the case where the channel is not found
print(f"Channel with name 'algemeen' not found.")
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign upRelated Posts | Replies | Views | Activity | |
---|---|---|---|---|
|
2
Oct 24
|
49 | ||
|
1
May 18
|
5843 | ||
|
3
Dec 23
|
8871 | ||
|
1
Jan 25
|
2721 | ||
|
2
Jan 24
|
12721 |