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.

Unmerged revisions

7246. 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
1=== modified file 'product/pricelist.py'
2--- product/pricelist.py 2012-01-31 13:36:57 +0000
3+++ product/pricelist.py 2013-09-05 09:24:23 +0000
4@@ -199,8 +199,10 @@
5 categ_ids = _create_parent_category_list(categ_id, [categ_id])
6 if categ_ids:
7 categ_where = '(categ_id IN (' + ','.join(map(str, categ_ids)) + '))'
8+ categ_where_i = '(i.categ_id IN (' + ','.join(map(str, categ_ids)) + '))'
9 else:
10 categ_where = '(categ_id IS NULL)'
11+ categ_where_i = '(i.categ_id IS NULL)'
12
13 if partner:
14 partner_where = 'base <> -2 OR %s IN (SELECT name FROM product_supplierinfo WHERE product_id = %s) '
15@@ -208,20 +210,41 @@
16 else:
17 partner_where = 'base <> -2 '
18 partner_args = ()
19-
20- cr.execute(
21- 'SELECT i.*, pl.currency_id '
22- 'FROM product_pricelist_item AS i, '
23- 'product_pricelist_version AS v, product_pricelist AS pl '
24- 'WHERE (product_tmpl_id IS NULL OR product_tmpl_id = %s) '
25- 'AND (product_id IS NULL OR product_id = %s) '
26- 'AND (' + categ_where + ' OR (categ_id IS NULL)) '
27- 'AND (' + partner_where + ') '
28- 'AND price_version_id = %s '
29- 'AND (min_quantity IS NULL OR min_quantity <= %s) '
30- 'AND i.price_version_id = v.id AND v.pricelist_id = pl.id '
31- 'ORDER BY sequence',
32- (tmpl_id, product_id) + partner_args + (pricelist_version_ids[0], qty))
33+
34+ query = (
35+ 'SELECT '
36+ 'i.*, pl.currency_id , p.* '
37+ 'FROM '
38+ 'product_pricelist_item AS i '
39+ 'JOIN product_pricelist_version AS v '
40+ 'ON i.price_version_id = v.id '
41+ 'JOIN product_pricelist AS pl '
42+ 'ON v.pricelist_id = pl.id '
43+ 'LEFT OUTER JOIN ( '
44+ 'WITH RECURSIVE subtree(depth, categ_id, parent_id, name) AS ( '
45+ 'SELECT 0, id, parent_id, name FROM product_category WHERE parent_id is NULL '
46+ 'UNION '
47+ 'SELECT depth+1, m.id, m.parent_id, m.name '
48+ 'FROM subtree t, product_category m '
49+ 'WHERE m.parent_id = t.categ_id '
50+ ') '
51+ 'SELECT * '
52+ 'FROM subtree '
53+ 'WHERE (' + categ_where + ' OR (categ_id IS NULL)) '
54+ ') AS p '
55+ 'on i.categ_id = p.categ_id '
56+ 'WHERE '
57+ '(product_tmpl_id IS NULL OR product_tmpl_id = %s) '
58+ 'AND (product_id IS NULL OR product_id = %s) '
59+ 'AND (' + categ_where_i + ' OR (i.categ_id IS NULL)) '
60+ 'AND (' + partner_where + ') '
61+ 'AND price_version_id = %s '
62+ 'AND (min_quantity IS NULL OR min_quantity <= %s) '
63+ 'ORDER BY '
64+ 'sequence, depth desc '
65+ ) % ((tmpl_id, product_id) + partner_args + (pricelist_version_ids[0], qty))
66+
67+ cr.execute(query)
68 res1 = cr.dictfetchall()
69 uom_price_already_computed = False
70 for res in res1:
71@@ -304,6 +327,7 @@
72 res.update({'item_id': {ids[-1]: res_multi.get('item_id', ids[-1])}})
73 return res
74
75+
76 product_pricelist()
77
78