Merge lp:~yann-papouin/ocb-addons/7.0-bug-1169074-pricelist-category-depth into lp:ocb-addons

Proposed by Yann Papouin
Status: Rejected
Rejected by: Holger Brunn (Therp)
Proposed branch: lp:~yann-papouin/ocb-addons/7.0-bug-1169074-pricelist-category-depth
Merge into: lp:ocb-addons
Diff against target: 70 lines (+37/-14)
1 file modified
product/pricelist.py (+37/-14)
To merge this branch: bzr merge lp:~yann-papouin/ocb-addons/7.0-bug-1169074-pricelist-category-depth
Reviewer Review Type Date Requested Status
Holger Brunn (Therp) Disapprove
Guewen Baconnier @ Camptocamp Needs Information
Yannick Vaucher @ Camptocamp code review, no test Approve
Review via email: mp+210163@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Holger Brunn (Therp) (hbrunn) wrote :

same as 6.1-ocb

review: Approve (code review)
Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :
review: Approve (code review, no test)
Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

As you needed to rewrite the query, isn't in an opportunity to remove the injection of the ids in the query and use params in execute()? Even though categ_ids are supposed to be safe here, the correct way is to use the query parameters.

review: Needs Information
Revision history for this message
Yann Papouin (yann-papouin) wrote :

It does not seems to be simple to parameterize this query.
Maybe this change could be made in another proposal and this one could be merged now ?

Revision history for this message
Holger Brunn (Therp) (hbrunn) wrote :

Development for 7.0 has moved to github on https://github.com/OCA/ocb - please move your merge proposal there if it is still valid.

(I close and reject this in order to have a cleaner overview for 6.1 MPs which indeed have to be done on launchpad)

review: Disapprove

Unmerged revisions

9986. By Yann Papouin

[FIX] Pricelist doesn't take category depth into account

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'product/pricelist.py'
--- product/pricelist.py 2014-03-06 19:09:06 +0000
+++ product/pricelist.py 2014-03-10 09:56:21 +0000
@@ -219,8 +219,10 @@
219 categ_ids = _create_parent_category_list(categ_id, [categ_id])219 categ_ids = _create_parent_category_list(categ_id, [categ_id])
220 if categ_ids:220 if categ_ids:
221 categ_where = '(categ_id IN (' + ','.join(map(str, categ_ids)) + '))'221 categ_where = '(categ_id IN (' + ','.join(map(str, categ_ids)) + '))'
222 categ_where_i = '(i.categ_id IN (' + ','.join(map(str, categ_ids)) + '))'
222 else:223 else:
223 categ_where = '(categ_id IS NULL)'224 categ_where = '(categ_id IS NULL)'
225 categ_where_i = '(i.categ_id IS NULL)'
224226
225 if partner:227 if partner:
226 partner_where = 'base <> -2 OR %s IN (SELECT name FROM product_supplierinfo WHERE product_id = %s) '228 partner_where = 'base <> -2 OR %s IN (SELECT name FROM product_supplierinfo WHERE product_id = %s) '
@@ -228,20 +230,41 @@
228 else:230 else:
229 partner_where = 'base <> -2 '231 partner_where = 'base <> -2 '
230 partner_args = ()232 partner_args = ()
231233
232 cr.execute(234 query = (
233 'SELECT i.*, pl.currency_id '235 'SELECT '
234 'FROM product_pricelist_item AS i, '236 'i.*, pl.currency_id , p.* '
235 'product_pricelist_version AS v, product_pricelist AS pl '237 'FROM '
236 'WHERE (product_tmpl_id IS NULL OR product_tmpl_id = %s) '238 'product_pricelist_item AS i '
237 'AND (product_id IS NULL OR product_id = %s) '239 'JOIN product_pricelist_version AS v '
238 'AND (' + categ_where + ' OR (categ_id IS NULL)) '240 'ON i.price_version_id = v.id '
239 'AND (' + partner_where + ') '241 'JOIN product_pricelist AS pl '
240 'AND price_version_id = %s '242 'ON v.pricelist_id = pl.id '
241 'AND (min_quantity IS NULL OR min_quantity <= %s) '243 'LEFT OUTER JOIN ( '
242 'AND i.price_version_id = v.id AND v.pricelist_id = pl.id '244 'WITH RECURSIVE subtree(depth, categ_id, parent_id, name) AS ( '
243 'ORDER BY sequence',245 'SELECT 0, id, parent_id, name FROM product_category WHERE parent_id is NULL '
244 (tmpl_id, product_id) + partner_args + (pricelist_version_ids[0], qty))246 'UNION '
247 'SELECT depth+1, m.id, m.parent_id, m.name '
248 'FROM subtree t, product_category m '
249 'WHERE m.parent_id = t.categ_id '
250 ') '
251 'SELECT * '
252 'FROM subtree '
253 'WHERE (' + categ_where + ' OR (categ_id IS NULL)) '
254 ') AS p '
255 'on i.categ_id = p.categ_id '
256 'WHERE '
257 '(product_tmpl_id IS NULL OR product_tmpl_id = %s) '
258 'AND (product_id IS NULL OR product_id = %s) '
259 'AND (' + categ_where_i + ' OR (i.categ_id IS NULL)) '
260 'AND (' + partner_where + ') '
261 'AND price_version_id = %s '
262 'AND (min_quantity IS NULL OR min_quantity <= %s) '
263 'ORDER BY '
264 'sequence, depth desc '
265 ) % ((tmpl_id, product_id) + partner_args + (pricelist_version_ids[0], qty))
266
267 cr.execute(query)
245 res1 = cr.dictfetchall()268 res1 = cr.dictfetchall()
246 uom_price_already_computed = False269 uom_price_already_computed = False
247 for res in res1:270 for res in res1: