I want to search records of one2many field that depends on another fields.
here my code,
Parent class:
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')
Child class:
class SaleOrderLine(models.Model):
_inherit = 'sale.order.line'
order_id = fields.Many2one('sale.order')
product_id = fields.Many2one('product.product')
View
<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>
By default, a customer can see all the products defined.
In my case, I need to filter the products depends on customer selected.
Each customer can have different list products or if they didn't categorize they can see all the products.
I tried the code above but got error:
Uncaught Error: Expected "]", got "(name)"
I guess the error come from this code:
<attribute name="domain">[('id', 'in', [rec.id for rec in parent.partner_product_ids])]</attribute>
my question,
is it possible to do python loop comprehension like the code above (within view)?
Thank you.