Enable Dark Mode!
By: Raveena V

How to show/hide a Button in Odoo 15 Pos Based on the User

Technical Odoo 15

In Odoo POS, everything is defined in terms of screens. When coming to Odoo version 15, there are a lot of new features implemented like Limited Partner Loading, Customer, Ship Later, Refund, Open Product Info, etc. In this blog, we can check how to show or hide any button on the POS product screen based on the user’s access rights.

The POS ProductScreen is nothing but the screen where we can see the buttons like Discount, Info, Refund, Reward, etc. We can check how to hide any of these buttons for a specific user. For that, we can check how a button is defined on the product screen. For example, we can check how the RefundButton is defined in the ‘point_of_sale’ module’s RefundButton.js file. It is defined by extending the POS component and then it is added to the product screen as below:

   component: RefundButton,
   condition: function () {
       return true;
From this code, we can understand that the RefundButton is added as a control button on the product screen. Then there is a condition function is added, which returns true. That means it depends on the condition defined, and it will show the button only when the condition returns true.
Here, no condition is defined, and true is directly returned without checking any condition. So it will return every time we open the screen.
Now we can check how to add our condition inside it. For that, we have to add a field in pos.config for adding the users who can see the Refund button like the below:
Inherit pos.config model and add the field
refund_employee_ids = fields.Many2many('hr.employee', string='Refund Employees')
It is a many2many field, so we can add more than one employee. Then we have to enable the login by employee feature in the point of sale configuration and fill in the Refund Employees field. Now the employees can log in to the system. The next is to set the condition for the refund button based on the current login user.
  component: RefundButton,
  condition: function () {
       var cashier = this.env.pos.get('cashier') || this.env.pos.get_cashier();
       has_refund = false;
       if (this.env.pos.config.refund_employee_ids.includes(cashier.id)) {
           has_refund = true;
       return  has_refund;
Now, we added a condition to check whether the cashier or the user has been included in the refund employees list or not. If the user is one among the users who have access to the refund button, the condition returns true. Thus the security condition for the Refund button is added. So the button will be hidden from normal users.
Like the above can set the security conditions on every button on the product screen, also known as the POS screen.

If you need any assistance in odoo, we are online, please chat with us.



I am very thankful to Cybrosys, you are really making the useful content available. I always found your blogs helpful when stuck in any problem.




reply REPLY


Thank You! Shekhar, For your valuable comments


will have to add : position: ['replace', 'RefundButton'], after the condition to work! Thanks!





Hi, thank you for your post. I'm trying to apply it without success. I'm guessing the code you suggested should be placed into a custom module and extends original component but I have'nt been able to make it work. I have been looking for examples in source code but no luck. The problem is basically how to modify the original condition in addControlButton through inheritance or extension. The code you suggested works if I modify the original code in point of sale module.




Leave a comment




Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635



Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.



Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message