[英]Use of domain in search of One2many field in List view in Odoo-9
i have One2many field product_attributes in
product.template and
value field in
product.attributes.custom
我在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')
Product 1 product_attributes contains 2 values:
产品1 product_attributes包含2个值:
value= 'color: red'
value= 'others: red'
product 2 product_attributes contains 2 values:
产品2 product_attributes包含2个值:
value= 'color: white'
value= 'others: red'
I did like below in search xml: 我在搜索xml中确实喜欢以下内容:
<field
name="product_attributes" string="Color"
filter_domain="['&',('product_attributes.value','ilike','color'),('product_attributes.value','ilike',self)]"
/>
So if red is searched, only product 1 containing both
color and
red should be shown.
因此,如果搜索红色 ,则仅应显示同时包含
颜色和
红色的产品1。 But I am unable to get result.
但是我无法获得结果。 I am getting both products.
我同时获得两种产品。
Is there any solution for this? 有什么解决办法吗?
AFAIK search_domain
means nothing here. AFAIK
search_domain
在这里毫无意义。 You should use domain
instead. 您应该改用
domain
。
There are a few types of domain for field in the search view: 搜索视图中的字段域类型有几种:
domain
- just like the domain on the field declaration in the python class, limits the records got from the database; domain
-就像python类中字段声明上的域一样,限制从数据库获取的记录; filter_domain
- overrides the name_search
method which would normally have only ('name', 'ilike', self)
. filter_domain
覆盖通常仅具有('name', 'ilike', self)
的name_search
方法。 In your case, I believe, you need the filter_domain
. 我认为,就您而言,您需要
filter_domain
。
Just a suggestion, you could add the :
after the attribute name to differentiate between the attribute and its value, given that you use the same convention for all your attributes: ('product_attributes.value', 'ilike', 'color: ')
只是一个建议,您可以在属性名称后添加
:
来区分属性及其值,前提是您对所有属性都使用相同的约定:( ('product_attributes.value', 'ilike', 'color: ')
The default operator between domains is &
and in this case can be omitted. 域之间的默认运算符为
&
,在这种情况下可以省略。
For solving my problem I used search function to get product ids which have selected attribute name and value only and included that in arguments in search function as 为了解决我的问题,我使用搜索功能获取仅选择了属性名称和值并将其包含在搜索功能的参数中的产品ID。
args += [['id', 'in', productids]]
I don't know if it was a right approach to do it. 我不知道这样做是否正确。 But it solved my problem.
但这解决了我的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.