Skip to Content
Menu
This question has been flagged
5 Replies
259 Views

I’m trying to customize the Sales module so that the "Create" button is hidden only in the Sale Orders view, but it should remain visible for Quotations.

What I’ve tried:

  • Adding a domain/context check in the XML view.
  • Overriding the can_create method (no effect).
  • Applying security rules — but it hides the button in both views.

My use case:

I want users to only be able to create Quotations, not direct Sale Orders.

💡 Question:

What is the best way to achieve this? Can we apply a condition in XML or through context in action_orders to hide the "Create" button?

Thanks in advance!

Avatar
Discard
Best Answer

This

Best Practice Approach

Odoo lets you control the visibility of the "Create" button by setting the context in the action with the flag:

'context': {'hide_create_button': True}

Then, in the XML view, you check that context and hide the button accordingly.

Step 1: Inherit the "Sales Orders" action and set the context

<odoo> <record id="action_orders_hide_create" model="ir.actions.act_window"> <field name="name">Sales Orders (No Create)</field> <field name="type">ir.actions.act_window</field> <field name="res_model">sale.order</field> <field name="view_mode">tree,form</field> <field name="domain">[('state', 'not in', ('draft',))]</field> <field name="context">{'hide_create_button': True}</field> </record> <!-- Override menu to point to the new action --> <menuitem id="sale.menu_sale_order" action="action_orders_hide_create"/> </odoo>

This keeps "Quotations" untouched (default behavior), and applies the modified context only in the Sales Orders view.

Step 2: Inherit the tree/form view and hide the "Create" button based on context

<record id="view_order_tree_inherit_hide_create" model="ir.ui.view"> <field name="name">sale.order.tree.hide.create</field> <field name="model">sale.order</field> <field name="inherit_id" ref="sale.view_order_tree"/> <field name="arch" type="xml"> <xpath expr="//tree" position="attributes"> <attribute name="create">not context.get('hide_create_button')</attribute> </xpath> </field> </record>

You can repeat the same for the form view if needed, though usually the button only appears in the list.


i hope it is use full

Avatar
Discard
Best Answer

Use Record Rules or Access Rights

  • Go to Settings → Users & Companies → Groups
  • Select the group (e.g., Sales / User: Own Documents Only)
  • In the “Access Rights” tab, remove “create” access from the sale.order model.

👉 This disables the button and also prevents backend creation.

Avatar
Discard
Author Best Answer

Thank you For Response, But This Is The Way To Remove Create In Lines As It Applies In One2Many 

Avatar
Discard
Best Answer

Hi,

How to Hide the “Create” Button in Sale Orders View Only


Enable Developer Mode

Go to Settings → Activate Developer Mode.


Navigate to Sale Orders

Open Sales → Orders → Sale Orders.


Access the View Editor

Click the Debug icon (top-right), then choose “Edit View: List” (not “Edit Action”).


Update the View Architecture

In the XML code, find the <tree> tag and modify it like this:



<tree ............. create="false">

Save Your Changes


That’s it! The “Create” button will now be hidden only in the Sale Orders list view, your Quotations view remains untouched.


Hope it helps

Avatar
Discard
Author

Thank You, But This Hides The List View Create But When A Form Opens The Create Button still Visible

Author

Have Found The Solution Used def fields_view_get Function In Odoo 15 To Achieve this, Thank You For The Help!

@api.model
def fields_view_get(self, view_id=None, view_type="form", toolbar=True, submenu=False, **kwargs):
res = super(SaleOrder, self).fields_view_get(
view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu, **kwargs
)
if view_type == 'form':
doc = etree.XML(res['arch'])
context = self.env.context
allow_create = context.get("default_order_sequence") or context.get("order_sequence")
doc.attrib['create'] = 'false' if allow_create else 'true'
res['arch'] = etree.tostring(doc, encoding='unicode')

return res

Related Posts Replies Views Activity
1
Feb 25
1395
1
Oct 24
825
0
Jul 24
671
0
Jul 24
708
1
Jun 25
1204