【发布时间】:2015-12-08 06:53:56
【问题描述】:
我想搜索依赖于其他字段的 one2many 字段的记录。
这是我的代码,
父类:
class SaleOrder(models.Model):
_inherit = 'sale.order'
customer_product_ids = fields.One2many('product.product',
compute='_get_partner_products')
order_line = fields.One2many('sale.order.line', 'order_id')
儿童班:
class SaleOrderLine(models.Model):
_inherit = 'sale.order.line'
order_id = fields.Many2one('sale.order')
product_id = fields.Many2one('product.product')
查看
<record id="view_ata_sale_order_form_inherit" model="ir.ui.view">
<field name="name">view.ata.sale.order.form.inherit</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<field name="partner_id" position="after">
<field name="partner_channel_id" invisible="1"/>
<field name="customer_product_ids"/>
</field>
<xpath expr="//tree/field[@name='product_id']" position="attributes">
<attribute name="domain">[('id', 'in', [rec.id for rec in parent.customer_product_ids])]</attribute>
</xpath>
</field>
</record>
默认情况下,客户可以看到所有定义的产品。
就我而言,我需要根据选择的客户过滤产品。
每个客户可以有不同的列表产品,或者如果他们没有分类,他们可以看到所有产品。
我尝试了上面的代码但出现错误:
Uncaught Error: Expected "]", got "(name)"
我猜错误来自这段代码:
<attribute name="domain">[('id', 'in', [rec.id for rec in parent.partner_product_ids])]</attribute>
我的问题,
是否可以像上面的代码(在视图内)那样做 python 循环理解?
谢谢。
【问题讨论】: