Merge lp:~yann-papouin/openobject-addons/6.1-bug-1169074-pricelist-category-depth into lp:openobject-addons/6.1

Proposed by Yann Papouin
Status: Needs review
Proposed branch: lp:~yann-papouin/openobject-addons/6.1-bug-1169074-pricelist-category-depth
Merge into: lp:openobject-addons/6.1
Diff against target: 76 lines (+38/-14)
1 file modified
product/pricelist.py (+38/-14)
To merge this branch: bzr merge lp:~yann-papouin/openobject-addons/6.1-bug-1169074-pricelist-category-depth
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+184046@code.launchpad.net
To post a comment you must log in.

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 2012-01-31 13:36:57 +0000
+++ product/pricelist.py 2013-09-05 09:24:23 +0000
@@ -199,8 +199,10 @@
199 categ_ids = _create_parent_category_list(categ_id, [categ_id])199 categ_ids = _create_parent_category_list(categ_id, [categ_id])
200 if categ_ids:200 if categ_ids:
201 categ_where = '(categ_id IN (' + ','.join(map(str, categ_ids)) + '))'201 categ_where = '(categ_id IN (' + ','.join(map(str, categ_ids)) + '))'
202 categ_where_i = '(i.categ_id IN (' + ','.join(map(str, categ_ids)) + '))'
202 else:203 else:
203 categ_where = '(categ_id IS NULL)'204 categ_where = '(categ_id IS NULL)'
205 categ_where_i = '(i.categ_id IS NULL)'
204206
205 if partner:207 if partner:
206 partner_where = 'base <> -2 OR %s IN (SELECT name FROM product_supplierinfo WHERE product_id = %s) '208 partner_where = 'base <> -2 OR %s IN (SELECT name FROM product_supplierinfo WHERE product_id = %s) '
@@ -208,20 +210,41 @@
208 else:210 else:
209 partner_where = 'base <> -2 '211 partner_where = 'base <> -2 '
210 partner_args = ()212 partner_args = ()
211213
212 cr.execute(214 query = (
213 'SELECT i.*, pl.currency_id '215 'SELECT '
214 'FROM product_pricelist_item AS i, '216 'i.*, pl.currency_id , p.* '
215 'product_pricelist_version AS v, product_pricelist AS pl '217 'FROM '
216 'WHERE (product_tmpl_id IS NULL OR product_tmpl_id = %s) '218 'product_pricelist_item AS i '
217 'AND (product_id IS NULL OR product_id = %s) '219 'JOIN product_pricelist_version AS v '
218 'AND (' + categ_where + ' OR (categ_id IS NULL)) '220 'ON i.price_version_id = v.id '
219 'AND (' + partner_where + ') '221 'JOIN product_pricelist AS pl '
220 'AND price_version_id = %s '222 'ON v.pricelist_id = pl.id '
221 'AND (min_quantity IS NULL OR min_quantity <= %s) '223 'LEFT OUTER JOIN ( '
222 'AND i.price_version_id = v.id AND v.pricelist_id = pl.id '224 'WITH RECURSIVE subtree(depth, categ_id, parent_id, name) AS ( '
223 'ORDER BY sequence',225 'SELECT 0, id, parent_id, name FROM product_category WHERE parent_id is NULL '
224 (tmpl_id, product_id) + partner_args + (pricelist_version_ids[0], qty))226 'UNION '
227 'SELECT depth+1, m.id, m.parent_id, m.name '
228 'FROM subtree t, product_category m '
229 'WHERE m.parent_id = t.categ_id '
230 ') '
231 'SELECT * '
232 'FROM subtree '
233 'WHERE (' + categ_where + ' OR (categ_id IS NULL)) '
234 ') AS p '
235 'on i.categ_id = p.categ_id '
236 'WHERE '
237 '(product_tmpl_id IS NULL OR product_tmpl_id = %s) '
238 'AND (product_id IS NULL OR product_id = %s) '
239 'AND (' + categ_where_i + ' OR (i.categ_id IS NULL)) '
240 'AND (' + partner_where + ') '
241 'AND price_version_id = %s '
242 'AND (min_quantity IS NULL OR min_quantity <= %s) '
243 'ORDER BY '
244 'sequence, depth desc '
245 ) % ((tmpl_id, product_id) + partner_args + (pricelist_version_ids[0], qty))
246
247 cr.execute(query)
225 res1 = cr.dictfetchall()248 res1 = cr.dictfetchall()
226 uom_price_already_computed = False249 uom_price_already_computed = False
227 for res in res1:250 for res in res1:
@@ -304,6 +327,7 @@
304 res.update({'item_id': {ids[-1]: res_multi.get('item_id', ids[-1])}})327 res.update({'item_id': {ids[-1]: res_multi.get('item_id', ids[-1])}})
305 return res328 return res
306329
330
307product_pricelist()331product_pricelist()
308332
309333