如何在自定义模块中隐藏Odoo商机视图的两个继承按钮
Got it, let's solve this. Since those two buttons are injected into the CRM lead form via XPath from the sale_crm module, we can override them using Odoo's XML view inheritance in your custom module. Here are two straightforward approaches:
Approach 1: Force Hide the Buttons (Recommended if you might need them later)
This method modifies the buttons' visibility attribute to make them always invisible, without removing them entirely. Add this XML code to your custom module:
<record id="crm_lead_form_hide_quotation_buttons" model="ir.ui.view"> <field name="name">crm.lead.form.hide.quotation.buttons</field> <field name="model">crm.lead</field> <field name="inherit_id" ref="crm.crm_lead_form_view"/> <field name="arch" type="xml"> <!-- Target and hide "Create Quotation" button --> <xpath expr="//button[@string='Create Quotation' and @name='618']" position="attributes"> <attribute name="invisible">1</attribute> </xpath> <!-- Target and hide "Convert to Quotation" button --> <xpath expr="//button[@string='Convert to Quotation' and @name='618']" position="attributes"> <attribute name="invisible">1</attribute> </xpath> </field> </record>
Key Notes:
- We use the button's
stringandnameattributes to precisely target them (since both share the samename="618"value). - Setting
invisible="1"overrides the originalattrscondition, making the buttons hidden in all cases.
Approach 2: Remove the Buttons Entirely
If you're sure you'll never need these buttons, you can remove them from the view completely:
<record id="crm_lead_form_remove_quotation_buttons" model="ir.ui.view"> <field name="name">crm.lead.form.remove.quotation.buttons</field> <field name="model">crm.lead</field> <field name="inherit_id" ref="crm.crm_lead_form_view"/> <field name="arch" type="xml"> <!-- Remove "Create Quotation" button --> <xpath expr="//button[@string='Create Quotation' and @name='618']" position="replace"/> <!-- Remove "Convert to Quotation" button --> <xpath expr="//button[@string='Convert to Quotation' and @name='618']" position="replace"/> </field> </record>
Critical Setup Step:
Don't forget to add sale_crm as a dependency in your custom module's __manifest__.py file. This ensures Odoo loads the original sale_crm view before your inherited view:
'depends': ['base', 'crm', 'sale_crm'],
After adding this code, install/update your custom module, and the buttons will be hidden/removed from the CRM lead form view.
内容的提问来源于stack exchange,提问作者Nebil Aydi

