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
- Contabilidad
- Inventario
- PoS
- Project
- MRP
Se marcó esta pregunta
2
Respuestas
2081
Vistas
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.")
¿Le interesa esta conversación? ¡Participe en ella!
Cree una cuenta para poder utilizar funciones exclusivas e interactuar con la comunidad.
InscribirsePublicaciones relacionadas | Respuestas | Vistas | Actividad | |
---|---|---|---|---|
|
2
oct 24
|
49 | ||
Gitlab integration with discuss
Resuelto
|
|
1
may 18
|
5907 | |
|
3
dic 23
|
8946 | ||
|
1
ene 25
|
2895 | ||
|
2
ene 24
|
12861 |