Help

欢迎!

该社区面向专业人士和我们产品和服务的爱好者。
分享和讨论最好的内容和新的营销理念,建立您的专业形象,一起成为更好的营销人员。


0

Unable to add a custom field to Opportunity Form View (but OK in Leads)

Avatar
odoo
Avatar
Discard
1 Answer
0
Avatar
odoo
Best Answer

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

1 Comment
Avatar
Discard
Avatar
odoo
-

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!