如何授予用户创建字段但不更改字段的权限?
How can I give a user the permission to create a field but not to change it?
我想让用户创建一条记录,但后来却没有授予它更改该字段值的权利。我应该通过覆盖创建和写入方法来实现吗?是否可以写这样的代码:
field1: fields.float(string='Field',write=['base.GROUP_ID']),
这可能会创建一个状态字段,当它为真时,该字段是一个计算字段,field1 将是只读的。因为我在 phone 我不会写漏洞代码只是试着理解这个想法
status = field.Boolean(compute='compute_status')
def compute_status(self):
for rec in self:
# first check of the use belong to the group that have full acces
if self.env.user.has_group('group_id') :
rec.status = False
# then check if the record is saved in databse
# unsaved records There id is instance of NewId it's a dummy class used for this
elif instanceOf(NewId ,rec.id) :
rec.status = False # here all users can fill the field when the record is not created yet but cannot edit
else :
rec.status = True # if record is saved and user is not in group_id make field readonly or invisible as you want
现在创建您的字段并使用状态 属性 使其在状态字段为 True 时只读。
如您所见,我的回答不仅仅是一个代码,对系统错误感到抱歉
我认为更好的方法是创建一个用户所属的组,然后在 ir.model.access
中为该特定组设置一个具有您想要的权限的规则。
询问您是否需要更多帮助。
编辑
您可以定义一个视图,该视图继承自原始视图,但仅供用户组访问,例如:
<field name="groups_id" eval="[(6, 0, [ref(' < your group > ')])]"/>
然后您重新定义了该字段,使其成为只读的。就是这样。
我想让用户创建一条记录,但后来却没有授予它更改该字段值的权利。我应该通过覆盖创建和写入方法来实现吗?是否可以写这样的代码:
field1: fields.float(string='Field',write=['base.GROUP_ID']),
这可能会创建一个状态字段,当它为真时,该字段是一个计算字段,field1 将是只读的。因为我在 phone 我不会写漏洞代码只是试着理解这个想法
status = field.Boolean(compute='compute_status')
def compute_status(self):
for rec in self:
# first check of the use belong to the group that have full acces
if self.env.user.has_group('group_id') :
rec.status = False
# then check if the record is saved in databse
# unsaved records There id is instance of NewId it's a dummy class used for this
elif instanceOf(NewId ,rec.id) :
rec.status = False # here all users can fill the field when the record is not created yet but cannot edit
else :
rec.status = True # if record is saved and user is not in group_id make field readonly or invisible as you want
现在创建您的字段并使用状态 属性 使其在状态字段为 True 时只读。 如您所见,我的回答不仅仅是一个代码,对系统错误感到抱歉
我认为更好的方法是创建一个用户所属的组,然后在 ir.model.access
中为该特定组设置一个具有您想要的权限的规则。
询问您是否需要更多帮助。
编辑
您可以定义一个视图,该视图继承自原始视图,但仅供用户组访问,例如:
<field name="groups_id" eval="[(6, 0, [ref(' < your group > ')])]"/>
然后您重新定义了该字段,使其成为只读的。就是这样。