Merge lp:~credativ/openobject-addons/6.0-internal-stock-average-cost into lp:~credativ/openobject-addons/6.0

Proposed by Jacob Hicks (credativ)
Status: Merged
Merged at revision: 5226
Proposed branch: lp:~credativ/openobject-addons/6.0-internal-stock-average-cost
Merge into: lp:~credativ/openobject-addons/6.0
Diff against target: 97 lines (+17/-9)
2 files modified
product/product.py (+2/-2)
stock/stock.py (+15/-7)
To merge this branch: bzr merge lp:~credativ/openobject-addons/6.0-internal-stock-average-cost
Reviewer Review Type Date Requested Status
Jacob Hicks (credativ) Approve
Review via email: mp+203725@code.launchpad.net

Description of the change

Merge request to fix average price to take all internal locations in to account

To post a comment you must log in.
Revision history for this message
Jacob Hicks (credativ) (jah256) wrote :

Tested by Kinner

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'product/product.py'
2--- product/product.py 2012-03-30 08:53:02 +0000
3+++ product/product.py 2014-01-29 12:28:47 +0000
4@@ -579,7 +579,7 @@
5 #
6 # Could be overrided for variants matrices prices
7 #
8- def price_get(self, cr, uid, ids, ptype='list_price', context=None):
9+ def price_get(self, cr, uid, ids, ptype='list_price', context=None,round=True):
10 if context is None:
11 context = {}
12
13@@ -604,7 +604,7 @@
14 # Take the price_type currency from the product field
15 # This is right cause a field cannot be in more than one currency
16 res[product.id] = self.pool.get('res.currency').compute(cr, uid, price_type_currency_id,
17- context['currency_id'], res[product.id],context=context)
18+ context['currency_id'], res[product.id],round=round,context=context)
19
20 return res
21
22
23=== modified file 'stock/stock.py'
24--- stock/stock.py 2013-04-24 21:59:10 +0000
25+++ stock/stock.py 2014-01-29 12:28:47 +0000
26@@ -302,7 +302,7 @@
27
28 # Compute based on pricetype
29 # Choose the right filed standard_price to read
30- amount_unit = product.price_get('standard_price', context)[product.id]
31+ amount_unit = product.price_get('standard_price', context,round=False)[product.id]
32 price = qty[product_id] * amount_unit
33
34 total_price += price
35@@ -904,7 +904,7 @@
36 if type in ('in_invoice', 'in_refund'):
37 # Take the user company and pricetype
38 context['currency_id'] = move_line.company_id.currency_id.id
39- amount_unit = move_line.product_id.price_get('standard_price', context)[move_line.product_id.id]
40+ amount_unit = move_line.product_id.price_get('standard_price', context,round=False)[move_line.product_id.id]
41 return amount_unit
42 else:
43 return move_line.product_id.list_price
44@@ -1214,18 +1214,22 @@
45 if product.id in product_avail:
46 product_avail[product.id] += qty
47 else:
48+ ctx = context.copy()
49+ location_ids = self.pool.get('stock.location').search(cr, uid, [('usage', '=', 'internal')], context=context)
50+ ctx.update({'location': location_ids})
51+ product = product.browse(context=ctx)[0]
52 product_avail[product.id] = product.qty_available
53
54 if qty > 0:
55 new_price = currency_obj.compute(cr, uid, product_currency,
56- move_currency_id, product_price)
57+ move_currency_id, product_price,round=False)
58 new_price = uom_obj._compute_price(cr, uid, product_uom, new_price,
59 product.uom_id.id)
60 if product.qty_available <= 0:
61 new_std_price = new_price
62 else:
63 # Get the standard price
64- amount_unit = product.price_get('standard_price', context)[product.id]
65+ amount_unit = product.price_get('standard_price', context,round=False)[product.id]
66 new_std_price = ((amount_unit * product_avail[product.id])\
67 + (new_price * qty))/(product_avail[product.id] + qty)
68 # Write the field according to price type field
69@@ -2069,7 +2073,7 @@
70 if context is None:
71 context = {}
72 currency_ctx = dict(context, currency_id = move.company_id.currency_id.id)
73- amount_unit = move.product_id.price_get('standard_price', currency_ctx)[move.product_id.id]
74+ amount_unit = move.product_id.price_get('standard_price', currency_ctx,round=False)[move.product_id.id]
75 reference_amount = amount_unit * qty
76
77 return reference_amount, reference_currency_id
78@@ -2458,14 +2462,18 @@
79 qty = uom_obj._compute_qty(cr, uid, product_uom, product_qty, product.uom_id.id)
80 if qty > 0:
81 new_price = currency_obj.compute(cr, uid, product_currency,
82- move_currency_id, product_price)
83+ move_currency_id, product_price,round=False)
84 new_price = uom_obj._compute_price(cr, uid, product_uom, new_price,
85 product.uom_id.id)
86 if product.qty_available <= 0:
87 new_std_price = new_price
88 else:
89+ ctx = context.copy()
90+ location_ids = self.pool.get('stock.location').search(cr, uid, [('usage', '=', 'internal')], context=context)
91+ ctx.update({'location': location_ids})
92+ product = product.browse(context=ctx)[0]
93 # Get the standard price
94- amount_unit = product.price_get('standard_price', context)[product.id]
95+ amount_unit = product.price_get('standard_price', context,round=False)[product.id]
96 new_std_price = ((amount_unit * product.qty_available)\
97 + (new_price * qty))/(product.qty_available + qty)
98

Subscribers

People subscribed via source and target branches

to all changes: