Reputation: 1659
In my module user can save records of their own and edit records of their own. And also can view the records of other users. A user cant edit the details of other user but can view. What i want is, i want to open the record of another user in read only mode. But user's own record should be in normal mode. Most importantly, for admin it should be in normal mode (editable mode). How can i do this in odoo?
Upvotes: 0
Views: 917
Reputation: 1659
This can be done by using a Boolean field.
is_belongs = fields.Boolean('Own record',default=True)
Add a Boolean field in your model.
Write a function like this..
def make_readonly(self):
if self.pool['res.users'].has_group(self._cr, self.env.user.id, 'base.group_manager'):
is_belongs = True //This will work if admin is logged in//
elif self.create_uid == self.env.user:
is_belongs = True
elif self.create_uid != self.env.user:
is_belongs = False
Here create_uid is a reserved field by odoo.
Reserved fields Odoo creates a few fields in all models. These fields are managed by the system and shouldn't be written to. They can be read if useful or necessary:
This field gives the user who created the record. The value of this field is the user who created the record. So when the admin and the owner of the record login the value of is_belongs will be True. For other user its value will be False
Then add a filter in view as
{'readonly':[('is_belongs','=',False)]}
Then the form view will be read only for those users who is not the owner of the record, but will be in normal mode for admin and owner of the record.
Upvotes: 0