Merge lp:~openerp-dev/openobject-addons/7.0-opw-601797-msh into lp:openobject-addons/7.0

Proposed by Mohammed Shekha(Open ERP)
Status: Approved
Approved by: Vinay Rana (OpenERP)
Approved revision: 9702
Proposed branch: lp:~openerp-dev/openobject-addons/7.0-opw-601797-msh
Merge into: lp:openobject-addons/7.0
Diff against target: 57 lines (+22/-18)
1 file modified
product/pricelist.py (+22/-18)
To merge this branch: bzr merge lp:~openerp-dev/openobject-addons/7.0-opw-601797-msh
Reviewer Review Type Date Requested Status
Vinay Rana (OpenERP) (community) Approve
Martin Trigaux (OpenERP) Pending
Naresh(OpenERP) Pending
Review via email: mp+199386@code.launchpad.net

Description of the change

Hello,

Fixed the issue of price_get, it should consider other items if it fails in following scenario. Create a pricelist with two items, Item A and Item B, Item A: product=null, category=null, sequence=1, base=Supplier Prices on the product form, Item B: product=null, category=null, sequence=5, base=Cost Price, now edit any product and set supplier with any price rule in Supplier Information tab of product and then create a purchase order with same supplier and add a purchasse order line with same product which we changed and you will find price=0 because no price rules are defined in supplier form of product, when this is the case then we should consider other pricelist items.

Demo:-
Take any existing product
Cost price = $10
Supplier exists (product_supplierinfo)
no Supplier price exists (pricelist_partnerinfo)
create new purchase pricelist with the following:

pricelist item A:
Product is null
Product Category is null
Sequence = 1
Based On = Supplier Prices on the product form (value = -2)
remaining fields = 0

pricelist item B:
Product is null
Product Category is null
Sequence = 5
Based On = Cost Price (value = 2)
remaining fields = 0

Steps to face:
create new Purchase Order
Supplier is same as defined in product setup above
select pricelist created from above setup
select part from above setup
RESULT: price_unit = $0
EXPECTED: price_unit = $10

If there are no price rule defined in supplier information then those pricelist items must be skipped from initial query, what is current behavior we search for supplier information i.e product_supplierinfo then we iterate through those items which matches criteria then again check if base==-2 then tries to fetch price based on min_quantity but if there is no rule then second query to fetch price will return no record and we by default set price=0.0 and then we break the loop if price other than False.

We should filter those items which has base == -2 and there is no supplier price rule defined and we should consider other items to calculate price.

The fix will considers pricelist items in sequence if first pricelist(according to sequence) have configuration like based on supplier information of product form and product has supplier without price rule then code will skip that item and considers next item.

Thanks.

To post a comment you must log in.
Revision history for this message
Vinay Rana (OpenERP) (vra-openerp) wrote :

I am agree with the solution as the partner section price is not assigned then system will return another sequence rule instead of zero value.
The propose fix will fixes this issue.

review: Approve

Unmerged revisions

9702. By Mohammed Shekha(OpenERP)<email address hidden>

[FIX]Fixed the issue of price_get, it should consider other items if it fails in following scenario. Create a pricelist with two items, Item A and Item B, Item A: product=null, category=null, sequence=1, base=Supplier Prices on the product form, Item B: product=null, category=null, sequence=5, base=Cost Price, now edit any product and set supplier with any price rule in Supplier Information tab of product and then create a purchase order with same supplier and add a purchasse order line with same product which we changed and you will find price=0 because no price rules are defined in supplier form of product, when this is the case then we should consider other pricelist items.

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 2013-09-20 14:45:29 +0000
3+++ product/pricelist.py 2013-12-18 05:43:13 +0000
4@@ -223,9 +223,28 @@
5 else:
6 categ_where = '(categ_id IS NULL)'
7
8- if partner:
9- partner_where = 'base <> -2 OR %s IN (SELECT name FROM product_supplierinfo WHERE product_id = %s) '
10- partner_args = (partner, tmpl_id)
11+ where = []
12+ if partner:
13+ where = [('name', '=', partner) ]
14+ sinfo = supplierinfo_obj.search(cr, uid,
15+ [('product_id', '=', tmpl_id)] + where)
16+ qty_in_product_uom = qty
17+ if sinfo:
18+ product_default_uom = product_obj.read(cr, uid, [product_id], ['uom_id'])[0]['uom_id'][0]
19+ supplier = supplierinfo_obj.browse(cr, uid, sinfo, context=context)[0]
20+ seller_uom = supplier.product_uom and supplier.product_uom.id or False
21+ if seller_uom and product_default_uom and product_default_uom != seller_uom:
22+ uom_price_already_computed = True
23+ qty_in_product_uom = product_uom_obj._compute_qty(cr, uid, product_default_uom, qty, to_uom_id=seller_uom)
24+
25+ if partner:
26+ partner_where = 'base <> -2 OR %s IN (SELECT product_supplierinfo.name FROM product_supplierinfo, pricelist_partnerinfo ' \
27+ 'WHERE product_supplierinfo.product_id = %s ' \
28+ 'AND product_supplierinfo.id = pricelist_partnerinfo.suppinfo_id ' \
29+ 'AND pricelist_partnerinfo.min_quantity <= %s ' \
30+ 'ORDER BY pricelist_partnerinfo.min_quantity DESC LIMIT 1) '
31+ partner_args = (partner, tmpl_id, qty_in_product_uom)
32+
33 else:
34 partner_where = 'base <> -2 '
35 partner_args = ()
36@@ -261,21 +280,6 @@
37 price_tmp, round=False,
38 context=context)
39 elif res['base'] == -2:
40- # this section could be improved by moving the queries outside the loop:
41- where = []
42- if partner:
43- where = [('name', '=', partner) ]
44- sinfo = supplierinfo_obj.search(cr, uid,
45- [('product_id', '=', tmpl_id)] + where)
46- price = 0.0
47- if sinfo:
48- qty_in_product_uom = qty
49- product_default_uom = product_obj.read(cr, uid, [product_id], ['uom_id'])[0]['uom_id'][0]
50- supplier = supplierinfo_obj.browse(cr, uid, sinfo, context=context)[0]
51- seller_uom = supplier.product_uom and supplier.product_uom.id or False
52- if seller_uom and product_default_uom and product_default_uom != seller_uom:
53- uom_price_already_computed = True
54- qty_in_product_uom = product_uom_obj._compute_qty(cr, uid, product_default_uom, qty, to_uom_id=seller_uom)
55 cr.execute('SELECT * ' \
56 'FROM pricelist_partnerinfo ' \
57 'WHERE suppinfo_id IN %s' \