代码之家  ›  专栏  ›  技术社区  ›  M.E.

Odoo 10-搜索条件

  •  0
  • M.E.  · 技术社区  · 6 年前

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

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

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

    1. a给定 product_id
    2. a给定 language
    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 是否正确定义了条件?

    2 回复  |  直到 6 年前
        1
  •  2
  •   Sanaullah Khan    6 年前

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

    试试这个

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

        2
  •  2
  •   jahmia    6 年前

    根据 documentation ,则, “&” (默认)和 “!” 是2 arity,所以可以这样做:

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