我在 product.template 中的One2many字段 product_attributes 和 product.attributes.custom <中的值字段/ p>
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。但我无法得到结果。我正在买两种产品。
有没有解决方案?
答案 0 :(得分:1)
AFAIK search_domain
在这里没有任何意义。您应该使用domain
代替。
答案 1 :(得分:1)
搜索视图中的字段有几种类型:
domain
- 就像python类中字段声明中的域一样,限制从数据库中获取的记录; filter_domain
- 覆盖通常只有name_search
的{{1}}方法。在您的情况下,我相信您需要('name', 'ilike', self)
。
只是一个建议,您可以在属性名称后添加filter_domain
以区分属性及其值,前提是您对所有属性使用相同的约定:
:
域之间的默认运算符为('product_attributes.value', 'ilike', 'color: ')
,在这种情况下可以省略。
答案 2 :(得分:0)
为解决我的问题,我使用搜索功能来获取仅选择了属性名称和值的产品ID,并将其包含在搜索功能的参数中
{{1}}
我不知道这是否是一种正确的做法。但它解决了我的问题。