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
=== modified file 'product/product.py'
--- product/product.py 2012-03-30 08:53:02 +0000
+++ product/product.py 2014-01-29 12:28:47 +0000
@@ -579,7 +579,7 @@
579 #579 #
580 # Could be overrided for variants matrices prices580 # Could be overrided for variants matrices prices
581 #581 #
582 def price_get(self, cr, uid, ids, ptype='list_price', context=None):582 def price_get(self, cr, uid, ids, ptype='list_price', context=None,round=True):
583 if context is None:583 if context is None:
584 context = {}584 context = {}
585585
@@ -604,7 +604,7 @@
604 # Take the price_type currency from the product field604 # Take the price_type currency from the product field
605 # This is right cause a field cannot be in more than one currency605 # This is right cause a field cannot be in more than one currency
606 res[product.id] = self.pool.get('res.currency').compute(cr, uid, price_type_currency_id,606 res[product.id] = self.pool.get('res.currency').compute(cr, uid, price_type_currency_id,
607 context['currency_id'], res[product.id],context=context)607 context['currency_id'], res[product.id],round=round,context=context)
608608
609 return res609 return res
610610
611611
=== modified file 'stock/stock.py'
--- stock/stock.py 2013-04-24 21:59:10 +0000
+++ stock/stock.py 2014-01-29 12:28:47 +0000
@@ -302,7 +302,7 @@
302302
303 # Compute based on pricetype303 # Compute based on pricetype
304 # Choose the right filed standard_price to read304 # Choose the right filed standard_price to read
305 amount_unit = product.price_get('standard_price', context)[product.id]305 amount_unit = product.price_get('standard_price', context,round=False)[product.id]
306 price = qty[product_id] * amount_unit306 price = qty[product_id] * amount_unit
307307
308 total_price += price308 total_price += price
@@ -904,7 +904,7 @@
904 if type in ('in_invoice', 'in_refund'):904 if type in ('in_invoice', 'in_refund'):
905 # Take the user company and pricetype905 # Take the user company and pricetype
906 context['currency_id'] = move_line.company_id.currency_id.id906 context['currency_id'] = move_line.company_id.currency_id.id
907 amount_unit = move_line.product_id.price_get('standard_price', context)[move_line.product_id.id]907 amount_unit = move_line.product_id.price_get('standard_price', context,round=False)[move_line.product_id.id]
908 return amount_unit908 return amount_unit
909 else:909 else:
910 return move_line.product_id.list_price910 return move_line.product_id.list_price
@@ -1214,18 +1214,22 @@
1214 if product.id in product_avail:1214 if product.id in product_avail:
1215 product_avail[product.id] += qty1215 product_avail[product.id] += qty
1216 else:1216 else:
1217 ctx = context.copy()
1218 location_ids = self.pool.get('stock.location').search(cr, uid, [('usage', '=', 'internal')], context=context)
1219 ctx.update({'location': location_ids})
1220 product = product.browse(context=ctx)[0]
1217 product_avail[product.id] = product.qty_available1221 product_avail[product.id] = product.qty_available
12181222
1219 if qty > 0:1223 if qty > 0:
1220 new_price = currency_obj.compute(cr, uid, product_currency,1224 new_price = currency_obj.compute(cr, uid, product_currency,
1221 move_currency_id, product_price)1225 move_currency_id, product_price,round=False)
1222 new_price = uom_obj._compute_price(cr, uid, product_uom, new_price,1226 new_price = uom_obj._compute_price(cr, uid, product_uom, new_price,
1223 product.uom_id.id)1227 product.uom_id.id)
1224 if product.qty_available <= 0:1228 if product.qty_available <= 0:
1225 new_std_price = new_price1229 new_std_price = new_price
1226 else:1230 else:
1227 # Get the standard price1231 # Get the standard price
1228 amount_unit = product.price_get('standard_price', context)[product.id]1232 amount_unit = product.price_get('standard_price', context,round=False)[product.id]
1229 new_std_price = ((amount_unit * product_avail[product.id])\1233 new_std_price = ((amount_unit * product_avail[product.id])\
1230 + (new_price * qty))/(product_avail[product.id] + qty)1234 + (new_price * qty))/(product_avail[product.id] + qty)
1231 # Write the field according to price type field1235 # Write the field according to price type field
@@ -2069,7 +2073,7 @@
2069 if context is None:2073 if context is None:
2070 context = {}2074 context = {}
2071 currency_ctx = dict(context, currency_id = move.company_id.currency_id.id)2075 currency_ctx = dict(context, currency_id = move.company_id.currency_id.id)
2072 amount_unit = move.product_id.price_get('standard_price', currency_ctx)[move.product_id.id]2076 amount_unit = move.product_id.price_get('standard_price', currency_ctx,round=False)[move.product_id.id]
2073 reference_amount = amount_unit * qty2077 reference_amount = amount_unit * qty
20742078
2075 return reference_amount, reference_currency_id2079 return reference_amount, reference_currency_id
@@ -2458,14 +2462,18 @@
2458 qty = uom_obj._compute_qty(cr, uid, product_uom, product_qty, product.uom_id.id)2462 qty = uom_obj._compute_qty(cr, uid, product_uom, product_qty, product.uom_id.id)
2459 if qty > 0:2463 if qty > 0:
2460 new_price = currency_obj.compute(cr, uid, product_currency,2464 new_price = currency_obj.compute(cr, uid, product_currency,
2461 move_currency_id, product_price)2465 move_currency_id, product_price,round=False)
2462 new_price = uom_obj._compute_price(cr, uid, product_uom, new_price,2466 new_price = uom_obj._compute_price(cr, uid, product_uom, new_price,
2463 product.uom_id.id)2467 product.uom_id.id)
2464 if product.qty_available <= 0:2468 if product.qty_available <= 0:
2465 new_std_price = new_price2469 new_std_price = new_price
2466 else:2470 else:
2471 ctx = context.copy()
2472 location_ids = self.pool.get('stock.location').search(cr, uid, [('usage', '=', 'internal')], context=context)
2473 ctx.update({'location': location_ids})
2474 product = product.browse(context=ctx)[0]
2467 # Get the standard price2475 # Get the standard price
2468 amount_unit = product.price_get('standard_price', context)[product.id]2476 amount_unit = product.price_get('standard_price', context,round=False)[product.id]
2469 new_std_price = ((amount_unit * product.qty_available)\2477 new_std_price = ((amount_unit * product.qty_available)\
2470 + (new_price * qty))/(product.qty_available + qty)2478 + (new_price * qty))/(product.qty_available + qty)
24712479

Subscribers

People subscribed via source and target branches

to all changes: