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:
- 客户关系管理
- e-Commerce
- 会计
- 库存
- PoS
- Project
- MRP
此问题已终结
2
回复
2461
查看
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.")
相关帖文 | 回复 | 查看 | 活动 | |
---|---|---|---|---|
|
2
10月 24
|
49 | ||
|
1
5月 18
|
6177 | ||
|
3
12月 23
|
9161 | ||
|
1
1月 25
|
3488 | ||
|
2
1月 24
|
13239 |