Odoo 10 - 搜索条件

Odoo 10 - Search condition

我正在尝试根据以下条件进行搜索:

.search([("product_id", "=", int(product_id)), ("language", "=", language), ['|', ("type", "=", "data"), ("type", "=", "translation")], ])

基本上在给定模型(自定义模型)中搜索:

  1. 给定 product_id AND
  2. 给定 language AND
  3. type 列是 "data""translation"

但我得到:

File "/usr/lib/python2.ion = distribute_not(normalize_domain(domain))\n  
File "/usr/lib/python2.7/dist-packages/odoo/osv/ex
GATION:\nTypeError: unhashable type: \'list\'\n'>

是否正确定义了 search 条件?

您定义搜索条件的方式不正确。

试试这个

.search(['|', ("type", "=", "data"), ("type", "=", "translation"), ("product_id", "=", int(product_id)), ("language", "=", language)])

根据documentation"&"(默认)和"!" 是 2 个元数,所以你可以这样做:

[("product_id", "=", int(product_id)),("language", "=", language),
'|', ("type", "=", "data"), ("type", "=", "translation")]