[IMP] product: allow to inherit items search
Create hook method closes odoo/odoo#32526 Signed-off-by: Martin Trigaux (mat) <mat@odoo.com>
This commit is contained in:
committed by
Martin Trigaux
parent
8d64971e99
commit
defbb16835
@@ -98,6 +98,33 @@ class Pricelist(models.Model):
|
||||
results[product_id][pricelist.id] = price
|
||||
return results
|
||||
|
||||
def _compute_price_rule_get_items(self, products_qty_partner, date, uom_id, prod_tmpl_ids, prod_ids, categ_ids):
|
||||
self.ensure_one()
|
||||
# Load all rules
|
||||
self.env.cr.execute(
|
||||
"""
|
||||
SELECT
|
||||
item.id
|
||||
FROM
|
||||
product_pricelist_item AS item
|
||||
LEFT JOIN product_category AS categ ON item.categ_id = categ.id
|
||||
WHERE
|
||||
(item.product_tmpl_id IS NULL OR item.product_tmpl_id = any(%s))
|
||||
AND (item.product_id IS NULL OR item.product_id = any(%s))
|
||||
AND (item.categ_id IS NULL OR item.categ_id = any(%s))
|
||||
AND (item.pricelist_id = %s)
|
||||
AND (item.date_start IS NULL OR item.date_start<=%s)
|
||||
AND (item.date_end IS NULL OR item.date_end>=%s)
|
||||
ORDER BY
|
||||
item.applied_on, item.min_quantity desc, categ.complete_name desc, item.id desc
|
||||
""",
|
||||
(prod_tmpl_ids, prod_ids, categ_ids, self.id, date, date))
|
||||
# NOTE: if you change `order by` on that query, make sure it matches
|
||||
# _order from model to avoid inconstencies and undeterministic issues.
|
||||
|
||||
item_ids = [x[0] for x in self.env.cr.fetchall()]
|
||||
return self.env['product.pricelist.item'].browse(item_ids)
|
||||
|
||||
@api.multi
|
||||
def _compute_price_rule(self, products_qty_partner, date=False, uom_id=False):
|
||||
""" Low-level method - Mono pricelist, multi products
|
||||
@@ -142,25 +169,8 @@ class Pricelist(models.Model):
|
||||
prod_ids = [product.id for product in products]
|
||||
prod_tmpl_ids = [product.product_tmpl_id.id for product in products]
|
||||
|
||||
# Load all rules
|
||||
self._cr.execute(
|
||||
'SELECT item.id '
|
||||
'FROM product_pricelist_item AS item '
|
||||
'LEFT JOIN product_category AS categ '
|
||||
'ON item.categ_id = categ.id '
|
||||
'WHERE (item.product_tmpl_id IS NULL OR item.product_tmpl_id = any(%s))'
|
||||
'AND (item.product_id IS NULL OR item.product_id = any(%s))'
|
||||
'AND (item.categ_id IS NULL OR item.categ_id = any(%s)) '
|
||||
'AND (item.pricelist_id = %s) '
|
||||
'AND (item.date_start IS NULL OR item.date_start<=%s) '
|
||||
'AND (item.date_end IS NULL OR item.date_end>=%s)'
|
||||
'ORDER BY item.applied_on, item.min_quantity desc, categ.complete_name desc, item.id desc',
|
||||
(prod_tmpl_ids, prod_ids, categ_ids, self.id, date, date))
|
||||
# NOTE: if you change `order by` on that query, make sure it matches
|
||||
# _order from model to avoid inconstencies and undeterministic issues.
|
||||
items = self._compute_price_rule_get_items(products_qty_partner, date, uom_id, prod_tmpl_ids, prod_ids, categ_ids)
|
||||
|
||||
item_ids = [x[0] for x in self._cr.fetchall()]
|
||||
items = self.env['product.pricelist.item'].browse(item_ids)
|
||||
results = {}
|
||||
for product, qty, partner in products_qty_partner:
|
||||
results[product.id] = 0.0
|
||||
|
||||
Reference in New Issue
Block a user