【问题标题】:Get the current User's employee's ID in XML File odoo 10在 XML File odoo 10 中获取当前用户的员工 ID
【发布时间】:2017-08-12 12:38:57
【问题描述】:

我是我的模型,我有一个字段“mentor_id”,定义为:

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

在我的 SearchView 中,我需要添加一个过滤器,该过滤器仅显示具有指导者 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'”。 任何帮助将不胜感激。

【问题讨论】:

    标签: xml filter openerp searchview odoo-10


    【解决方案1】:

    在视图中,您只能通过user.id 获取当前用户 ID 我还没有测试过,但您可能会在视图中的user 变量中获得当前用户对象。您可以在域中使用user.employee_id

    如果没有发生这种情况,你可以做的是:

    • 使用指向函数的计算属性创建与 res.users 的 Many2one 关系。
    • 在函数内写入self.*feild_name* = self.env.user。您将在视图中获得当前用户对象。

    谢谢

    【讨论】:

      【解决方案2】:

      您应该在员工本身上写下导师的用户 ID。它会更容易。只需添加一个相关字段(您不需要设置/显示它,只需在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)]"/>
      

      【讨论】:

      • @CherifOdoo 谢谢。
      【解决方案3】:

      再次查看您收到的错误。

      对象没有属性employee_ids

      这表明您尚未将 employee_ids 字段添加到 res.users 模型中(这是 uid 拉起的)。

      您能否发布您的完整模型,以便我们更好地了解正在发生的关系?

      【讨论】:

        猜你喜欢
        • 2015-05-14
        • 2019-12-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-01-22
        • 1970-01-01
        相关资源
        最近更新 更多