Skip to Content
Menu
This question has been flagged

Hey i am trying to make a particular user for purchase app only . I know ow to do it in a generic way but anyone can help me with how to do it for a particular app. Here is the code for generic read only

def set_read_only_user(self):
read_only_grp_id = self.env['ir.model.data'].get_object_reference('generic_read_only_user_app', 'group_read_only_user')[1]
if not self.read_only:
self.read_only = True
group_list = []
for group in self.groups_id:
group_list.append(group.id)
group_list.append(read_only_grp_id)
result= self.write({'groups_id':([(6,0,group_list)])})
Avatar
Discard
Best Answer

Hello,

If you want to make particular user readonly for some applications or models, or whole project then this module is helpful.

https://apps.odoo.com/apps/modules/15.0/read_only_user_rights/

Avatar
Discard
Best Answer

As I can see you are using generic_read_only_user_app module which do it a generic read only for all models. To do it only for one model you will modify the code of check method of ir.model.access which already exists in the generic_read_only_user_app module as below:

class IrModelAccess(models.Model):
    _inherit = 'ir.model.access'
    @api.model
    @tools.ormcache_context('self._uid', 'model', 'mode', 'raise_exception', keys=('lang',))
    def check(self, model, mode='read', raise_exception=True):
        result = super(IrModelAccess, self).check(model, mode, raise_exception=raise_exception)
        if self.env.user.has_group('generic_read_only_user_app.group_read_only_user'):
            if mode != 'read' and model=='purchase.order'
                return False
        return result
Avatar
Discard
Author

Hey thanks this is working.

Related Posts Replies Views Activity
3
Dec 21
14374
23
Apr 23
46611
1
Jun 23
1978
1
Apr 22
3351
3
Oct 20
1789