This question has been flagged

i want to get the list of products whose price will be affected by the pricelist i made

ex 

if i apply pricelist for 10 products

then i want to get the details of these 10 products only

or if i apply pricelist for some product category

then i want to get the details of all products whose price will be affected by the pricelist

Avatar
Discard
Best Answer

You've got three rules that could affect the price of the product:

1) by product itself

2) by category

3) globally

So, you need to analyze these 3 situations to get the list of products that could be affected by the rules.

This is just and idea on how you could do some kind of search or creation of a new model containing the data. At the end of this, the idea is that you can construct a domain to search for the products.

if the rule is global, affects all products (thats why the domain is ([])

if there are rules for products and categories, you need an 'or' condition. Thats why you add '|' to the domain.

pricelist = self.env['product.pricelist'].browse(your_list_id)
product_obj = self.env['product.product']
product_domain = []
if pricelist.item_ids.filtered(lambda r: r.applied_on == '1_product'):
product_domain.append(('product_id', 'in', pricelist.item_ids.filtered(lambda r: r.applied_on == '1_product').ids))
if pricelist.item_ids.filtered(lambda r: r.applied_on == '2_product_category'):
product_domain.append(('categ_id', 'in', pricelist.item_ids.filtered(lambda r: r.applied_on == '2_product_category').mapped('categ_ids').ids
if pricelist.item_ids.filtered(lambda r: r.applied_on == '3_global':
product_domain = []
if len(product_domain) == 2:
product_domain = ['|'] + product_domain
product_ids = product_obj.search(product_domain)





Avatar
Discard
Author

Thanks for information ℹ️