summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSébastien Theys <seb@odoo.com>2018-11-07 14:30:06 +0000
committerSébastien Theys <seb@odoo.com>2018-11-07 14:30:06 +0000
commit45dec698ee2b113c19277dbc39abcb4f0897da16 (patch)
treebc3bf0d57e6dd23befcd02e43da07140548048d7
parent0662a1948b71ebd46313cbe40774553594f1c9e0 (diff)
[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
-rw-r--r--addons/product/models/product_pricelist.py9
1 files 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',