Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
1201 Vistas

As a salesrep, I need to track which opportunity got referred by which of my contacts for my referral program. 

The field needs to show in Lead form view, as well in Opportunity form view.

The field needs to be set to connected user as default value (which is achieved at the model level).

An internal user must be able to change that value (already working in Leads).


I created a inherited view based on crm.lead.form with the following Arch (with a lower seq.) :

<data inherit_id="crm.lead.form">

    <xpath expr="//field[@name='referred']" position="replace">

        <field name="x_ref_by"/>

    </xpath>

</data>


This part works just fine.

But I can't do it for the crm.lead.oppor.inherited.crm part.


I'm tried to create another inherited view which is a duplicate of crm.lead.oppor.inherited.crm (again with lower seq.) to which I added :

    <xpath expr="//field[@name='referred']" position="replace">

        <field name="x_ref_by"/>

    </xpath>


But the original Referred By field is not replaced. That seems pretty straight forward but I can figure where I'm wrong.


Any help would be appreciated. Thanks in advance.

Avatar
Descartar
Mejor respuesta

Hi,

The issue arose because the "referred" field appears in two different locations in the view:

  • For leads: Under the Marketing group on the "Extra Info" page.
  • For opportunities: Under the Marketing group on the "Extra Information" page.

To fix this, ensure your model inheritance is correct:


Python:

class CRMLead(models.Model):

_inherit = 'crm.lead'

x_ref_by = fields.Many2one('res.users', string='Referred By', default=lambda self: self.env.user)


XML:

<odoo>

<record id="crm_lead_view_form_inherit" model="ir.ui.view">

<field name="name">crm.lead.form.inherit.referred</field>

<field name="model">crm.lead</field>

<field name="inherit_id" ref="crm.crm_lead_view_form"/>

<field name="arch" type="xml">

<!-- Replace the "referred" field in the Extra Info page (for leads) -->

<xpath expr="//page[@name='extra']//field[@name='referred']" position="replace">

<field name="x_ref_by"/>

</xpath>

<!-- Replace the "referred" field in the Extra Information page (for opportunities) -->

<xpath expr="//page[@name='lead']//field[@name='referred']" position="replace">

<field name="x_ref_by"/>

</xpath>

</field>

</record>

</odoo>


Hope it helps

Avatar
Descartar
Autor

Thanks! My mistake was actually trying to create 2 separates inherited views, when I only need to set it in a single one.

So it goes:

Python:
for record in self:
record['x_ref_by'] = record.env.user.partner_id.id

XML:
<data inherit_id="crm.lead.form">
<xpath expr="//page[@name='extra']//field[@name='referred']" position="replace">
<field name="x_ref_by" readonly="False"/>
</xpath>

<xpath expr="//page[@name='lead']//field[@name='referred']" position="replace">
<field name="x_ref_by" readonly="False"/>
</xpath>
</data>

Thanks again!

Publicaciones relacionadas Respuestas Vistas Actividad
2
jul 17
7314
3
may 24
3490
3
dic 22
23885
0
jul 18
3359
2
abr 16
11085