How to Restrict Users from Creating and Editing Products in Odoo 18

AMEERA
February 4, 2025
limit-user-access-product-creation-editing-odoo18

In odoo18, we have product master where we can create and update products and product details Product management is an important responsibilty. In most of the companies, it is assigned to some people to create and edit products. Odoo does’nt have that feature by default
So in this blog we discuss How to restrict users to create and edit product in Odoo18, for that first we need to make a security group.

How to Make a Security Group

<odoo>

<record id=”product_access_group” model=”res.groups”>
<field name=”name”>Access Product Edit</field>
</record>
</odoo>
how-restrict-users-create-edit-product-odoo18

Then you need to use get_view()

@api.model 

def get_views(self, views, options=None):
res = super().get_views(views, options=options)
#for form view
if "form" in res["views"]:
arch = res["views"]["form"]["arch"]
doc = etree.fromstring(arch)
if not self.env.user.has_groups('bi_product_access.product_access_group'):
for node in doc.xpath("//form"):
node.set('create', 'false') # Disable creation
node.set('edit', 'false')
arch = etree.tostring(doc, encoding="unicode")
res["views"]["form"]["arch"] = arch
#for list view
if "list" in res["views"]:
arch = res["views"]["list"]["arch"]
doc = etree.fromstring(arch)
if not self.env.user.has_groups('bi_product_access.product_access_group'):
for node in doc.xpath("//list"):
node.set('create', 'false') # Disable creation
node.set('edit', 'false')
arch = etree.tostring(doc, encoding="unicode")
res["views"]["list"]["arch"] = arch
#for kanban view
if "kanban" in res["views"]:
arch = res["views"]["kanban"]["arch"]
doc = etree.fromstring(arch)
if not self.env.user.has_groups('bi_product_access.product_access_group'):
for node in doc.xpath("//kanban"):
node.set('create', 'false') # Disable creation
node.set('edit', 'false') #Disable editing
arch = etree.tostring(doc, encoding="unicode")
res["views"]["kanban"]["arch"] = arch
return res

How to Restrict Users to Create and Edit Product in Odoo18

In this code we have restricted create and edit in Form view, List view and Kanban view. and We can do changes to adapt to the needed requirements.

Here when the user has the security group, They can create and edit products.

new-products

For others, it is only a view of products and cannot create products.

products

Managing product access efficiently is important for maintaining data integrity and simplifying business operations by implementing the above code in Odoo18, you can effectively restrict unauthorized users from creating or editing products while allowing specified users with the correct security group to manage product data and the get_views() method ensures that these restrictions apply seamlessly across different views, including Form, List, and Kanban, enhancing control over product management.

This method helps businesses maintain consistency, prevent unauthorized modifications, and ensure better workflow management in Odoo. With proper access control, your team can work more efficiently while safeguarding critical business data and looking for expert Odoo customization and implementation. Need help optimizing your business processes with Odoo?
At Bassam Infotech, we specialize in Odoo development, customization, and custom ERP solutions to help businesses like yours achieve operational excellence. Contact us today to enhance your Odoo experience and take your business management to the next level.

"Unlock the Full Potential of Your Business with Odoo ERP!"

"Get a Cost Estimate for Your ERP Project, Absolutely FREE!"

Get a Free Quote

Leave a Reply

Your email address will not be published. Required fields are marked *