如何检查管理员或用户是否登录odoo
问题描述:
目前我正在odoo中开发一个模块。在我的模块中,用户只能编辑自己的数据,但是管理员可以做任何事情。但与我的代码管理员也无法编辑。如果我知道管理员已登录,那么我可以绕过管理员帐户。那么如何知道管理员何时登录?如何检查管理员或用户是否登录odoo
def write(self, vals):
//if admin is logged in i need to bypass the below code//
if self.create_uid != self.env.user:
raise Warning('You can not able to edit this document as this is not your record')
return super(request_room, self).write(vals)
答
你想要使用super_user(admin)id。 可能是id = 1 下面的代码可以做到这一点。
from openerp import SUPERUSER_ID
def write(self, vals):
//if admin is logged in i need to bypass the below code//
if self.create_uid != self.env.user and self.create_uid != SUPERUSER_ID:
raise Warning('You can not able to edit this document as this is not your record')
return super(request_room, self).write(vals)
答
听说你可以直接去以下方式
from openerp import SUPERUSER_ID
def write(self, vals):
//if admin is logged in i need to bypass the below code//
if self.env.user.id != SUPERUSER_ID:
raise Warning('You can not able to edit this document as this is not your record')
return super(request_room, self).write(vals)
SUPERUSER_ID:这给了我们:admin用户
self.env.user静态硬编码ID为自我实例的当前用户ID
我希望我的回答可以帮助你:)
答
要存档这一点,你必须使用SUPERUSER_ID,
,您还可以通过使用ID“1”,防止因为在我们的系统管理员的用户有1号,但SUPERUSER_ID是很好的解决方案。
from openerp import SUPERUSER_ID