Skip to Content
Odoo Menú
  • Registra entrada
  • Prova-ho gratis
  • Aplicacions
    Finances
    • Comptabilitat
    • Facturació
    • Despeses
    • Full de càlcul (IA)
    • Documents
    • Signatura
    Vendes
    • CRM
    • Vendes
    • Punt de venda per a botigues
    • Punt de venda per a restaurants
    • Subscripcions
    • Lloguer
    Imatges de llocs web
    • Creació de llocs web
    • Comerç electrònic
    • Blog
    • Fòrum
    • Xat en directe
    • Aprenentatge en línia
    Cadena de subministrament
    • Inventari
    • Fabricació
    • PLM
    • Compres
    • Manteniment
    • Qualitat
    Recursos humans
    • Empleats
    • Reclutament
    • Absències
    • Avaluacions
    • Recomanacions
    • Flota
    Màrqueting
    • Màrqueting Social
    • Màrqueting per correu electrònic
    • Màrqueting per SMS
    • Esdeveniments
    • Automatització del màrqueting
    • Enquestes
    Serveis
    • Projectes
    • Fulls d'hores
    • Servei de camp
    • Suport
    • Planificació
    • Cites
    Productivitat
    • Converses
    • Validacions
    • IoT
    • VoIP
    • Coneixements
    • WhatsApp
    Aplicacions de tercers Odoo Studio Plataforma d'Odoo al núvol
  • Sectors
    Comerç al detall
    • Llibreria
    • Botiga de roba
    • Botiga de mobles
    • Botiga d'ultramarins
    • Ferreteria
    • Botiga de joguines
    Food & Hospitality
    • Bar i pub
    • Restaurant
    • Menjar ràpid
    • Guest House
    • Distribuïdor de begudes
    • Hotel
    Immobiliari
    • Agència immobiliària
    • Estudi d'arquitectura
    • Construcció
    • Gestió immobiliària
    • Jardineria
    • Associació de propietaris de béns immobles
    Consultoria
    • Empresa comptable
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Mobles
    • Menjar
    • Brewery
    • Regals corporatius
    Salut i fitness
    • Club d'esport
    • Òptica
    • Centre de fitness
    • Especialistes en benestar
    • Farmàcia
    • Perruqueria
    Trades
    • Servei de manteniment
    • Hardware i suport informàtic
    • Sistemes d'energia solar
    • Shoe Maker
    • Serveis de neteja
    • Instal·lacions HVAC
    Altres
    • Nonprofit Organization
    • Agència del medi ambient
    • Lloguer de panells publicitaris
    • Fotografia
    • Lloguer de bicicletes
    • Distribuïdors de programari
    Browse all Industries
  • Comunitat
    Aprèn
    • Tutorials
    • Documentació
    • Certificacions
    • Formació
    • Blog
    • Pòdcast
    Potenciar l'educació
    • Programa educatiu
    • Scale-Up! El joc empresarial
    • Visita Odoo
    Obtindre el programari
    • Descarregar
    • Comparar edicions
    • Novetats de les versions
    Col·laborar
    • GitHub
    • Fòrum
    • Esdeveniments
    • Traduccions
    • Converteix-te en partner
    • Services for Partners
    • Registra la teva empresa comptable
    Obtindre els serveis
    • Troba un partner
    • Troba un comptable
    • Contacta amb un expert
    • Serveis d'implementació
    • Referències del client
    • Suport
    • Actualitzacions
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Programar una demo
  • Preus
  • Ajuda

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Comptabilitat
  • Inventari
  • PoS
  • Projectes
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
Ajuda

Dynamic Links

Subscriure's

Get notified when there's activity on this post

This question has been flagged
dynamicemail_templatev18CommunityEditiondynamic fielddynamicPlaceholderdynamicLink
1 Respondre
1715 Vistes
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
Descartar
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
Descartar
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Registrar-se
Related Posts Respostes Vistes Activitat
Modify Pivot View
Pivot v18 CommunityEdition
Avatar
Avatar
1
de juny 25
1764
Unable to send email notifications through write
notifications v18 CommunityEdition
Avatar
Avatar
1
de juny 25
1825
Hide Records based on user group only in a particular view
views record_rule v18 CommunityEdition
Avatar
Avatar
Avatar
2
de set. 25
1479
Unable to pass context to an action
context server_action v18 CommunityEdition
Avatar
Avatar
1
de jul. 25
1638
Hide menus in user_menuitems from specific users
visibility v18 CommunityEdition user_menuitem
Avatar
Avatar
Avatar
3
de jul. 25
2134
Community
  • Tutorials
  • Documentació
  • Fòrum
Codi obert
  • Descarregar
  • GitHub
  • Runbot
  • Traduccions
Serveis
  • Allotjament a Odoo.sh
  • Suport
  • Actualització
  • Desenvolupaments personalitzats
  • Educació
  • Troba un comptable
  • Troba un partner
  • Converteix-te en partner
Sobre nosaltres
  • La nostra empresa
  • Actius de marca
  • Contacta amb nosaltres
  • Llocs de treball
  • Esdeveniments
  • Pòdcast
  • Blog
  • Clients
  • Informació legal • Privacitat
  • Seguretat
الْعَرَبيّة 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 és un conjunt d'aplicacions empresarials de codi obert que cobreix totes les necessitats de la teva empresa: CRM, comerç electrònic, comptabilitat, inventari, punt de venda, gestió de projectes, etc.

La proposta única de valor d'Odoo és ser molt fàcil d'utilitzar i estar totalment integrat, ambdues alhora.

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