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