Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
4955 Lượt xem

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)])})
Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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/

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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
Ảnh đại diện
Huỷ bỏ
Tác giả

Hey thanks this is working.

Bài viết liên quan Trả lời Lượt xem Hoạt động
3
thg 12 21
15629
23
thg 4 23
48129
1
thg 6 23
2943
1
thg 4 22
4233
3
thg 10 20
2407