This question has been flagged
4 Replies
40081 Views

i have a button and i want to make it available for specific users only

Avatar
Discard
Best Answer

Hi Ahmed,

I prefer to create a group and add your users to it and then you can assign the group to your button in two ways:

 Using Odoo GUI:  

  •  Edit the view and then add groups attribute to your button as below:

    <button name="print_quotation" string="Print" type="object" states="draft" groups="YOUR GROUP" class="btn-primary"/>

Using XML: You will create your module and add a view to inherit your view and add groups attribute to your button and specify the created group.   

 You will use Xpath to determine the path of  the button and you can get it from the original view

Below is example to inherit "sale.view_order_form" view and then add groups attribute to "Print" button so the button will be shown for the added group only.

By the way: I added [1] to xpath cause the sales order form has 2 buttons with the same name "print_quotation" and the groups will be applied for the first one only.

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

<field name="model">sale.order</field>

<field name="inherit_id" ref="sale.view_order_form"/>

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

<xpath expr="//button[@name='print_quotation'][1]" position="attributes">

<attribute name="groups">YOUR GROUP HERE</attribute>

</xpath>

</field>

</record>

Avatar
Discard

Hello Waleed,

+1 from me

Your answer help full me.

This solution help me, the key is add index [1] or [2], etc.. if we have multiple button with same name.

this is the related question that I ask, I get help from your answer:
https://www.odoo.com/id_ID/forum/help-1/how-to-hide-button-for-specific-user-192858

Thanks,
Tri Nanda

Best Answer

There are different ways to visible/invisible buttons for a specific group of users.

The first way is to add group attribute in button element, its mean that show the button only specific groups of user.

<button name="button_name" string="You Button Name Goes Here"  type="object" class="oe_highlight" groups="group_name1,group_name2"/>

The other way is to show buttons to specific user dynamically (on the basis of some condition). To do so we use invisible property of "attr" attribute.

<button name="button_name" string="You Button Name Goes Here"  type="object" class="oe_highlight" attrs="{'invisible':[('state','!=','your_state_goes_here')]}"/>

Thanks

Avatar
Discard

Read more about invisible/visible fields, buttons etc in odoo: http://learnopenerp.blogspot.com/2016/10/how-to-visible-and-invisible-fields-in.html

Perform some action (Show/Hide fields, buttons etc) on the basis of login user group:

http://learnopenerp.blogspot.com/2017/10/how-to-check-login-user-group-in-odoo.html

Best Answer

you can do without any coding, in development mode user groups in settings, click on user group and from access rights list you can manupulate buttons

Avatar
Discard
Best Answer

As in my case I want only the user who created the record can see the 'Confirm' button, I have to create a computed field to check if the logged in user is the record creator and put the field on the form view to check.

Avatar
Discard