Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

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
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

Dynamic Links

Subscribe

Get notified when there's activity on this post

This question has been flagged
dynamicemail_templatev18CommunityEditiondynamic fielddynamicPlaceholderdynamicLink
1 Reply
1679 Views
Avatar
Shreya Doodipala

How to add a dynamic hyperlink to a lead in the CRM in an email template?

  1. I have an email sent when a new lead is created, and I want to a link to the lead.
  2. I have a One2many secondary_sales_ids field and I want to send an email (from the secondary sales model) with the lead's link when a new secondary salesperson is added.

Odoo v18 Community edition

0
Avatar
Discard
Avatar
DataInteger Consultancy Services LLP
Best Answer

To add a dynamic hyperlink to a lead in the CRM in Odoo 18 Community Edition , and send it via email from the secondary sales model (when a new secondary salesperson is added) , follow these  steps :


STEP 1: Construct the Lead Link in the Email Template

Odoo dynamically renders links using templating language ( ${object.field} , t-esc , t-href , etc.). Here's how to insert a dynamic link to a lead:


Option A: If you're sending the email via a QWeb Email Template

Use this in your email body:

<p>
    View the Lead:
    <a t-attf-href="${object.lead_id.get_base_url()}/web#id=${object.lead_id.id}&model=crm.lead&view_type=form">
        ${object.lead_id.name}
    </a>
</p>
  • object.lead_id is the Many2one field in your secondary.salesperson model linking to crm.lead .
  • get_base_url() returns the base domain, eg, http://localhost:8069 .

Option B: If you're writing the email content manually in Python (from code)

Use this approach when sending email via code (eg, message_post , mail.template triggered by Python):

lead_url = f"{lead_id.get_base_url()}/web#id={lead_id.id}&model=crm.lead&view_type=form"
body = f"""
<p>Hello,</p>
<p>A new lead has been assigned to you.</p>
<p>Click here to view it: <a href="{lead_url}">{lead_id.name}</a></p>
"""
# Now send this body via mail.template or message_post

STEP 2: Add Email Sending Logic in create() of secondary.salesperson

In your secondary.salesperson model ( secondary_sales_ids ), override the create method to send the email when a record is added:

from odoo import models, fields, api

class SecondarySalesperson(models.Model):
    _name = 'your.secondary.salesperson.model'

    lead_id = fields.Many2one('crm.lead', string='Lead')
    user_id = fields.Many2one('res.users', string='Secondary Salesperson')

    @api.model
    def create(self, vals):
        record = super().create(vals)
        if record.lead_id:
            template = self.env.ref('your_module_name.email_template_secondary_sales_lead_link')
            template.send_mail(record.id, force_send=True)
        return record
STEP 3: Define the Email Template (in XML)
<record id="email_template_secondary_sales_lead_link" model="mail.template">
    <field name="name">Lead Assigned to Secondary Salesperson</field>
    <field name="model_id" ref="your_module.model_your_secondary_salesperson_model"/>
    <field name="subject">New Lead Assigned: ${object.lead_id.name}</field>
    <field name="email_from">${(user.email or 'noreply@example.com')|safe}</field>
    <field name="email_to">${object.user_id.email|safe}</field>
    <field name="body_html" type="html">
        <![CDATA[
        <p>Hello ${object.user_id.name},</p>
        <p>You have been assigned to a new lead.</p>
        <p>Lead: <strong>${object.lead_id.name}</strong></p>
        <p>
            Click here to open the lead:
            <a t-attf-href="${object.lead_id.get_base_url()}/web#id=${object.lead_id.id}&model=crm.lead&view_type=form">
                ${object.lead_id.name}
            </a>
        </p>
        ]]>
    </field>
</record>
Final Notes:
  • Replace your.secondary.salesperson.model with your actual model name (like crm.lead.secondary.salesperson ).
  • Replace your_module_name with the name of your custom module.


Thanks & Regards,

Email: contact@datainteger.com

0
Avatar
Discard
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
Modify Pivot View
Pivot v18 CommunityEdition
Avatar
Avatar
1
Jun 25
1748
Unable to send email notifications through write
notifications v18 CommunityEdition
Avatar
Avatar
1
Jun 25
1799
Hide Records based on user group only in a particular view
views record_rule v18 CommunityEdition
Avatar
Avatar
Avatar
2
Sep 25
1473
Unable to pass context to an action
context server_action v18 CommunityEdition
Avatar
Avatar
1
Jul 25
1626
Hide menus in user_menuitems from specific users
visibility v18 CommunityEdition user_menuitem
Avatar
Avatar
Avatar
3
Jul 25
2118
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now