Skip to Content
Menu
This question has been flagged
1 Reply
2698 Views

I have a user who has “User” access to inventory.  I don’t want this user editing products so this group setup works very well.

I do want them to start updating the base sales price so this user needs to have access to edit JUST a single field on the product, but still be unable to modify/edit/change anything else.

How can I give this user the additional permission to edit JUST the sales price (list_price field)?

Avatar
Discard
Best Answer

You can do this via module customization.

1. Give the User permission to write (modify) the Product Template model, by modifying the Access Rights to an existing Odoo group, or create a new group with read and write permission and add the User to that group instead.

2. Define a function that lists the field or fields that you want them to be able to edit:

def _writable_fields_for_user_group(self):     
return ['list_price']

3. Override the WRITE function of the model, to check if the field being modified is in the list:

def write(self, vals):
if not self.env.user.has_group('stock.group_stock_manager'):
vals = {field_name: vals.get(field_name) for field_name in self._writable_fields_for_user_group() if vals.get(field_name, False)}
return super().write(vals) 

Note that in this example, you would change the Access Rights of the existing Odoo group "Inventory User" to allow write (edit) but if you opted instead to create your own group, you would check for membership of it instead. 

The code will prevent any User who has permission to edit products and is not a member of the Inventory Manager group from changing any field value except the list_price field.  

It does this by inspecting the dictionary "vals" that has the list of fields the User has changed, and removes all fields that are not listed in the function defined in the first step, before returning control back to the regular write method.

This is a scalable method to enable field level security. If you wish to implement field level security based on membership of multiple groups, you can define multiple "_writable_fields_for_user_group_x" functions and use them with multiple "if-then" statements in the write method override

To be more User friendly, you could combine this approach with XML changes that mirror these restrictions by disallowing Users in the Inventory User group from being able to change the value of fields apart from list_price from the Form View, or by creating a multi_edit List View that is readonly for other fields but allows editing of the Sales Price field.




Avatar
Discard
Related Posts Replies Views Activity
0
Jun 25
297
0
Feb 25
1249
0
Jan 25
1397
0
Jan 25
1085
0
Jan 25
1402