[英]Use of domain in search of One2many field in List view in Odoo-9
我在product.template和值字段One2many場product_attributes在product.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="['&',('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.