Skip to Content
Menu
This question has been flagged
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.")


Avatar
Discard
Best Answer

First, use On save as the Trigger and Created on in When updating ​

Next, use the following code as a guide:




Avatar
Discard
Best Answer

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.")
Avatar
Discard
Related Posts Replies Views Activity
2
Oct 24
49
1
May 18
5843
3
Dec 23
8871
1
Jan 25
2721
2
Jan 24
12721