도움말

0

Making a user read only, application wise

Avatar
Abdullah

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)])})
아바타
작성취소
1 응답
1
Avatar
Waleed Mohsen
최고의 답변

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
1 코멘트
아바타
작성취소
Avatar
Abdullah
-

Hey thanks this is working.