2016-02-29 132 views
2

目前我正在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) 

回答

3

你想要使用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) 
2

聽說你可以直接去以下方式

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

我希望我的回答可以幫助你:)

1

要存檔這一點,你必須使用SUPERUSER_ID,

,您還可以通過使用ID「1」,防止因爲在我們的系統管理員的用戶有1號,但SUPERUSER_ID是很好的解決方案。

from openerp import SUPERUSER_ID