From 45dec698ee2b113c19277dbc39abcb4f0897da16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Theys?= Date: Wed, 7 Nov 2018 14:30:06 +0000 Subject: [PATCH] [FIX] product: pricelist item deterministic order Following commit b43151c11c07fc41293beac447a5cb8a0ce77149 The order of the pricelist items on the interface was made deterministic, but there was still a problem with the actual computation because the SQL was created manually and used a different order than the _order of the model. Moreover, it is better to use id DESC instead of ASC to make sure the automatically created default rule matching everything is actually applied last. PR: #28476 --- addons/product/models/product_pricelist.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/addons/product/models/product_pricelist.py b/addons/product/models/product_pricelist.py index 958d5823c50..44461a789d1 100644 --- a/addons/product/models/product_pricelist.py +++ b/addons/product/models/product_pricelist.py @@ -151,8 +151,10 @@ class Pricelist(models.Model): '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', + '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._cr.fetchall()] items = self.env['product.pricelist.item'].browse(item_ids) @@ -360,7 +362,10 @@ class ResCountryGroup(models.Model): class PricelistItem(models.Model): _name = "product.pricelist.item" _description = "Pricelist Item" - _order = "applied_on, min_quantity desc, categ_id desc, id" + _order = "applied_on, min_quantity desc, categ_id desc, id desc" + # NOTE: if you change _order on this model, make sure it matches the SQL + # query built in _compute_price_rule() above in this file to avoid + # inconstencies and undeterministic issues. product_tmpl_id = fields.Many2one( 'product.template', 'Product Template', ondelete='cascade',