How to hide a button in Odoo 15 POS based on user? | Odoo 15 Point of Sale
Odoo 15 has brought about many changes in the Point of Sale module in Odoo. In Odoo 14, we saw the OWL framework being implemented in POS. Odoo 15 implemented more features like refund options etc., in the POS view itself. Today, we will look at how to hide buttons like Refund, Discount, etc., based on the user security access in POS.
Let us take the case of the Discount button itself. In order for the discount button to appear in the POS view. One needs to enable the discount option and select a discount product in the configuration of the POS shop. So we can look at how the discount button is defined in order to get the idea about hiding a button based on a condition.
Discount functionality for POS in Odoo is implemented in the ‘pos_discount’ module. And we can check the JavaScript file in the same module. In the ‘DiscountButton.js’ file in the pos_discount module. We can see the ‘DiscountButton’ being added to the ‘ProductScreen’ aka the POS Screen.
Let us look at the code below
ProductScreen.addControlButton({ component: DiscountButton, condition: function() { return this.env.pos.config.module_pos_discount && this.env.pos.config.discount_product_id; }, });
In the above code fragment, we can see an argument called condition being called. Basically, what it does is that it will only display the button if all the conditions defined in that argument are true. For example, the POS Discount button enables the option in POS config and selecting a discount product. If an option is not true, then it will be hidden.
Hide the button based on user security.
Now we have looked at how a Control button is hidden based on a condition in Odoo 15 Point of Sale in Odoo. Our next task is to hide the button based on user security. The easiest method to test this is to add a new Many2many field in the Point of Sale config linking to ‘hr. employee’. Then, enable login by the employee in POS config and select the employees who will have access to the discount button. Finally, let us change the code of the discount button to accommodate our security changes as well.
In this write-up, we have learned how to hide a Control button in the Point of Sale in Odoo based on a condition. It can extend this to various other conditions based on your ideas and can help you a long way in the customization of the Odoo 15 Point Of Sale module.
ProductScreen.addControlButton({ component: DiscountButton, condition: function() { var cashier = this.env.pos.get('cashier') || this.env.pos.get_cashier(); has_discount = false; if (this.env.pos.config.discount_employee_ids.includes(cashier.id)) { has_discount = true; } return this.env.pos.config.module_pos_discount && this.env.pos.config.discount_product_id && has_discount; }, position: ['replace', 'DiscountButton'], });
We are replacing the discount button and also adding an extra condition. So now onwards, the user using POS will only see the discount button if he has access to the same. This will ensure that the normal users are not applying Discounts to orders. And hid the discount option behind a wall for normal users.
If you plan a new ERP Software implementation and you have heard about Odoo and got attracted by the Odoo ERP platform, used it but don’t have time, resources, or knowledge to manage this yourself, looking for professional help, then you have come to a right place. Bassam Infotech has implemented scores of Odoo ERP all around the world. In addition, we have also developed and delivered our own customized Odoo applications with minimal Odoo implementation costs.
DOWNLOAD odo0 15 point of sale
Bassam Infotech is a company of Official Odoo Certified Experts with 24 years of expertise. We are a one-stop shop for all your business needs, including Odoo Implementation, customization, integration, and support. We’re available by phone or email, with a 24-hour response time in case you need immediate Odoo ERP support. For more details, Call us on +91 88912 49995 or +91 70250 75566 email us at [email protected], or fill out the form to get a free consultation
"Unlock the Full Potential of Your Business with Odoo ERP!"
"Get a Cost Estimate for Your ERP Project, Absolutely FREE!"
Get a Free Quote