0

我正在使用Odoo Studio创建一个模型,其中包含一个 m2o 字段到员工模型,我需要将它的域设置为特定类别。

  1. 我创建了一个员工并分配了“Operario”类别 在此处输入图像描述

  2. 我在 Odoo Studio 中为 hr.employee 模型创建了一个带有 m2o 字段的新模型,并添加了下一个域:[["category_ids.name","in","Operario"]] 在此处输入图像描述

  3. 我尝试在新模型中创建一个新注册表,但是当我单击 o2m 字段时,如果我不是 HR 安全组的成员,则会收到此错误:

ValueError:无效字段 hr.employee。叶中的公共.category_ids ('category_ids.name', 'in', 'Operario')

整个代码:

Traceback (most recent call last):

  File "/home/odoo/src/odoo/14.0/odoo/addons/base/models/ir_http.py", line 237, in _dispatch

    result = request.dispatch()

  File "/home/odoo/src/odoo/14.0/odoo/http.py", line 683, in dispatch

    result = self._call_function(**self.params)

  File "/home/odoo/src/odoo/14.0/odoo/http.py", line 359, in _call_function

    return checked_call(self.db, *args, **kwargs)

  File "/home/odoo/src/odoo/14.0/odoo/service/model.py", line 94, in wrapper

    return f(dbname, *args, **kwargs)

  File "/home/odoo/src/odoo/14.0/odoo/http.py", line 347, in checked_call

    result = self.endpoint(*a, **kw)

  File "/home/odoo/src/odoo/14.0/odoo/http.py", line 912, in __call__

    return self.method(*args, **kw)

  File "/home/odoo/src/odoo/14.0/odoo/http.py", line 531, in response_wrap

    response = f(*args, **kw)

  File "/home/odoo/src/odoo/14.0/addons/web/controllers/main.py", line 1377, in call_kw

    return self._call_kw(model, method, args, kwargs)

  File "/home/odoo/src/odoo/14.0/addons/web/controllers/main.py", line 1369, in _call_kw

    return call_kw(request.env[model], method, args, kwargs)

  File "/home/odoo/src/odoo/14.0/odoo/api.py", line 392, in call_kw

    result = _call_kw_model(method, model, args, kwargs)

  File "/home/odoo/src/odoo/14.0/odoo/api.py", line 365, in _call_kw_model

    result = method(recs, *args, **kwargs)

  File "/home/odoo/src/odoo/14.0/odoo/models.py", line 1796, in name_search

    ids = self._name_search(name, args, operator, limit=limit)

  File "/home/odoo/src/odoo/14.0/odoo/models.py", line 1812, in _name_search

    return self._search(args, limit=limit, access_rights_uid=name_get_uid)

  File "/home/odoo/src/odoo/14.0/addons/hr/models/hr_employee.py", line 166, in _search

    ids = self.env['hr.employee.public']._search(args, offset=offset, limit=limit, order=order, count=count, access_rights_uid=access_rights_uid)

  File "/home/odoo/src/odoo/14.0/odoo/models.py", line 4492, in _search

    query = self._where_calc(args)

  File "/home/odoo/src/odoo/14.0/odoo/models.py", line 4248, in _where_calc

    return expression.expression(domain, self).query

  File "/home/odoo/src/odoo/14.0/odoo/osv/expression.py", line 438, in __init__

    self.parse()

  File "/home/odoo/src/odoo/14.0/odoo/osv/expression.py", line 640, in parse

    raise ValueError("Invalid field %s.%s in leaf %s" % (model._name, path[0], str(leaf)))

Exception



The above exception was the direct cause of the following exception:



Traceback (most recent call last):

  File "/home/odoo/src/odoo/14.0/odoo/http.py", line 639, in _handle_exception

    return super(JsonRequest, self)._handle_exception(exception)

  File "/home/odoo/src/odoo/14.0/odoo/http.py", line 315, in _handle_exception

    raise exception.with_traceback(None) from new_cause

ValueError: Invalid field hr.employee.public.category_ids in leaf ('category_ids.name', 'in', 'Operario')

在错误详细信息的最后一行,我看到了 public 这个词,我不确定这是否是一个子模型,无论如何我不知道在哪里为非 HR 成员设置这些权限。

4

1 回答 1

0

First you need to use employee_id instead of category_ids in the beginning. Because it is present in hr.employee table, not in hr.employee.public table.

Try this way,

[["employee_id.category_ids.name","=","Operario"]]

Also instead of in operator, use =, like, ilike for better integration with string type of value.

于 2021-02-12T20:47:32.037 回答