Hello, let's say you are trying to filter products based on the price list.
You can create a new field:
products_pricelist = fields.One2many('product.product', 'id', 'Pricelist Products', compute='_calc_price_list_products')
and then use a compute function to bring all the products from that price list:
# To filter the domain of products based on price list
@api.depends('pricelist_id')
def _calc_price_list_products(self):
product_ids = []
price_list_line = self.env['product.pricelist.item'].search([('pricelist_id', '=', self.pricelist_id.id)])
if price_list_line:
price_list_lines_product_id = self.env['product.pricelist.item'].search([('pricelist_id', '=', self.pricelist_id.id)]).mapped("product_tmpl_id").ids
if price_list_lines_product_id:
product_ids = self.env['product.product'].search([('product_tmpl_id', 'in', price_list_lines_product_id)]).ids
else:
self.products_pricelist = False
return
for price_line in price_list_line:
if price_line.base == 'pricelist':
if price_line.applied_on == '3_global':
base_lines_product_id = self.env['product.pricelist.item'].search([('pricelist_id', '=', price_line.base_pricelist_id.id)]).mapped("product_tmpl_id").ids
product_line_ids = self.env['product.product'].search(['&',('product_tmpl_id', 'in', base_lines_product_id),('id','not in', product_ids)]).ids
product_ids = product_ids + product_line_ids
if price_line.applied_on == '2_product_category':
base_lines_product_id = self.env['product.pricelist.item'].search([('pricelist_id', '=', price_line.base_pricelist_id.id)]).mapped("product_tmpl_id").ids
product_line_ids = self.env['product.product'].search(['&', '&', ('product_tmpl_id', 'in', base_lines_product_id), ('categ_id', '=', price_line.categ_id.id), ('id','not in', product_ids)]).ids
product_ids = product_ids + product_line_ids
if product_ids:
self.products_pricelist = product_ids
So after that you can filter in the other field:
<xpath expr="//tree/field[@name='product_id']" position="attributes">
<attribute name="domain">[('id', 'in', products_pricelist )]</attribute>
</xpath>
Hope it helps.
Regards.