簡體   English   中英

在Odoo-9的列表視圖中使用域搜索One2many字段

[英]Use of domain in search of One2many field in List view in Odoo-9

我在product.template字段One2many場product_attributesproduct.attributes.custom

class ProductTemplateCus(models.Model):
    _inherit = 'product.template'
    product_attributes = fields.One2many('product.attributes.custom','product_id')

class ProductAttributes(models.Model):
    _name = 'product.attributes.custom'
    value = fields.Char(string='Value')
    product_id = fields.Many2one('product.template',string='Product')

產品1 product_attributes包含2個值:

value= 'color: red'
value= 'others: red'

產品2 product_attributes包含2個值:

value= 'color: white'
value= 'others: red'

我在搜索xml中確實喜歡以下內容:

<field 
name="product_attributes" string="Color"
filter_domain="['&amp;',('product_attributes.value','ilike','color'),('product_attributes.value','ilike',self)]"
/>

因此,如果搜索紅色 ,則僅應顯示同時包含顏色紅色的產品1。 但是我無法獲得結果。 我同時獲得兩種產品。

有什么解決辦法嗎?

AFAIK search_domain在這里毫無意義。 您應該改用domain

搜索視圖中的字段域類型有幾種:

  • domain -就像python類中字段聲明上的域一樣,限制從數據庫獲取的記錄;
  • filter_domain覆蓋通常僅具有('name', 'ilike', self)name_search方法。

我認為,就您而言,您需要filter_domain


只是一個建議,您可以在屬性名稱后添加:來區分屬性及其值,前提是您對所有屬性都使用相同的約定:( ('product_attributes.value', 'ilike', 'color: ')

域之間的默認運算符為& ,在這種情況下可以省略。

為了解決我的問題,我使用搜索功能獲取僅選擇了屬性名稱和值並將其包含在搜索功能的參數中的產品ID。

args += [['id', 'in', productids]]

我不知道這樣做是否正確。 但這解決了我的問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM