2017-08-12 712 views
-1

我我的模型,我有一個字段「mentor_id」被定義爲:獲取當前用戶的員工ID在XML文件odoo 10

mentor_id = fields.Many2one('hr.employee', string='Mentor') 

在我搜索查看我需要添加一個過濾器,只顯示記錄與mentor_id =當前用戶的EMPLOYEE_ID 所以我說:

<filter string="My :" name="my" domain="[('mentor_id','in',uid.employee_ids)]"/> 

但它似乎並沒有工作,我得到這個錯誤:

Uncaught Error: Failed to evaluate search criterions: 
{"code":400,"message":"Evaluation Error","data":{"type":"local_exception","debug":"Local evaluation failure\nAttributeError: object has no attribute 'employee_ids'\n\n{\"domains\":[[],\"[('mentor_id','in',uid.employee_ids)]\"],\"contexts\":[{\"lang\":\"en_US\",\"tz\":false,\"uid\":1,\"params\":{\"action\":324}},{}],\"group_by_seq\":[]}"}} 

uid是指當前用戶是不是?那麼爲什麼錯誤說:「該對象沒有屬性'employee_ids'」。 任何幫助,將不勝感激。

回答

0

xml中的UID不是一個對象,它只是id值。嘗試使用用戶而不是用戶名,但我不認爲它的工作。

1

在視圖中,你只能通過user.id 獲取當前用戶ID我沒有測試過,但它可能發生,你將獲得當前用戶對象在視圖中的user變量。您可以在域中使用user.employee_id

如果沒有發生,你可以做的是:

  • 創建res.users一個Many2one關係與計算屬性指向功能。
  • self.*feild_name* = self.env.user裏面的函數。您將在視圖中獲取當前用戶對象。

謝謝你遇到的錯誤再次

0

看。

對象沒有屬性employee_ids

這表明你還沒有加入您的employee_ids字段拖到res.users模型(這是什麼uid拉)。

你可以發佈你的完整模型,以便我們可以更好地瞭解這種關係嗎?

1

你應該在僱員身上寫下導師的用戶名。它會更容易。只需添加相關領域(你不需要設置/表露出來,只添加Python代碼領域,它的完成):

mentor_id = fields.Many2one('hr.employee', string='Mentor') 
mentor_user_id = fields.Many2one(
    related='mentor_id.user_id', store=True, readonly=True) 

,只是使用此過濾器,而不是

<filter string="My :" name="my" domain="[('mentor_user_id', '=', uid)]"/> 
+0

這是一個這裏的答案很好。好的想法 – Cherif

+0

@CherifOdoo謝謝。 – Majikat