如果记录不属于odoo中的用户,如何使字段只读
How to make fields read only if the record does not belongs to the user in odoo
在我的模块中用户可以保存自己的记录和编辑自己的记录。并且还可以查看其他用户的记录。用户无法编辑其他用户的详细信息,但可以查看。我想要的是,我想以只读模式打开另一个用户的记录。但是用户自己的记录应该是普通模式。最重要的是,对于管理员来说,它应该处于正常模式(可编辑模式)。我如何在 odoo 中执行此操作?
这可以通过使用布尔字段来完成。
is_belongs = fields.Boolean('Own record',default=True)
在您的模型中添加一个布尔字段。
像这样写一个函数..
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
这里create_uid是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:
此字段提供创建记录的用户。该字段的值是创建记录的用户。因此,当管理员和记录所有者登录时,is_belongs 的值将为 True。对于其他用户,其值为 False
然后在视图中添加过滤器
{'readonly':[('is_belongs','=',False)]}
然后表单视图将仅供非记录所有者的用户读取,但管理员和记录所有者将处于正常模式。
在我的模块中用户可以保存自己的记录和编辑自己的记录。并且还可以查看其他用户的记录。用户无法编辑其他用户的详细信息,但可以查看。我想要的是,我想以只读模式打开另一个用户的记录。但是用户自己的记录应该是普通模式。最重要的是,对于管理员来说,它应该处于正常模式(可编辑模式)。我如何在 odoo 中执行此操作?
这可以通过使用布尔字段来完成。
is_belongs = fields.Boolean('Own record',default=True)
在您的模型中添加一个布尔字段。
像这样写一个函数..
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
这里create_uid是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:
此字段提供创建记录的用户。该字段的值是创建记录的用户。因此,当管理员和记录所有者登录时,is_belongs 的值将为 True。对于其他用户,其值为 False
然后在视图中添加过滤器
{'readonly':[('is_belongs','=',False)]}
然后表单视图将仅供非记录所有者的用户读取,但管理员和记录所有者将处于正常模式。