[FIX] Cost method / price of reception of picking is company dependent

bzr revid: jco@openerp.com-20130419151845-37umcsr03rpnew89
This commit is contained in:
Josse Colpaert
2013-04-19 17:18:45 +02:00
parent 2509bb8708
commit 9531c2cd1c
+29 -12
View File
@@ -1243,14 +1243,28 @@ class stock_picking(osv.osv):
too_few.append(move)
else:
too_many.append(move)
#Change cost price according to
user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
product = product_obj.browse(cr, uid, move.product_id.id, context=context)
company_id = move.company_id.id
ctx = context.copy()
if company_id != user.company_id.id:
#test if I could do this with a read instead
ctx['force_company'] = move.company_id.id
product = product_obj.browse(cr, uid, move.product_id.id, context=ctx)
cost_method = product.cost_method
product_price = product.standard_price
else:
cost_method = move.product_id.cost_method
# Average price computation
if (pick.type == 'in') and (move.product_id.cost_method == 'average'):
product = product_obj.browse(cr, uid, move.product_id.id)
if (pick.type == 'in') and (cost_method == 'average'):
move_currency_id = move.company_id.currency_id.id
context['currency_id'] = move_currency_id
qty = uom_obj._compute_qty(cr, uid, product_uom, product_qty, product.uom_id.id)
if product.id in product_avail:
product_avail[product.id] += qty
else:
@@ -1264,12 +1278,12 @@ class stock_picking(osv.osv):
if product.qty_available <= 0:
new_std_price = new_price
else:
# Get the standard price
# Get the standard price -> This should be company_dependent
amount_unit = product.price_get('standard_price', context=context)[product.id]
new_std_price = ((amount_unit * product_avail[product.id])\
+ (new_price * qty))/(product_avail[product.id] + qty)
# Write the field according to price type field
product_obj.write(cr, uid, [product.id], {'standard_price': new_std_price})
# Write the field according to price type field, company dependence in ctx
product_obj.write(cr, uid, [product.id], {'standard_price': new_std_price}, context=ctx)
# Record the values that were chosen in the wizard, so they can be
# used for inventory valuation if real-time valuation is enabled.
@@ -1278,7 +1292,7 @@ class stock_picking(osv.osv):
'price_currency_id': product_currency})
#Average price computation when returning products
if (pick.type == 'out') and (move.product_id.cost_method == 'average'):
if (pick.type == 'out') and (cost_method == 'average'):
orig_move_id = move_obj.search(cr, uid, [('move_history_ids2', 'in', [move.id])], context=context)
if len(orig_move_id) == 1:
#Is it ok to repeat code here?
@@ -1292,6 +1306,7 @@ class stock_picking(osv.osv):
product_avail[product.id] += qty
else:
product_avail[product.id] = product.qty_available
if qty > 0:
new_price = currency_obj.compute(cr, uid, product_currency,
move_currency_id, move_orig.price_unit)
@@ -1299,10 +1314,12 @@ class stock_picking(osv.osv):
product.uom_id.id)
# Get the standard price
amount_unit = product.price_get('standard_price', context=context)[product.id]
new_std_price = ((amount_unit * product_avail[product.id])\
- (new_price * qty))/(product_avail[product.id] - qty)
# Write the field according to price type field
product_obj.write(cr, uid, [product.id], {'standard_price': new_std_price})
#Check new stock is not zero or negative:
if (product_avail[product.id]- qty) > 0:
new_std_price = ((amount_unit * product_avail[product.id])\
- (new_price * qty))/(product_avail[product.id] - qty)
# Write the field according to price type field
product_obj.write(cr, uid, [product.id], {'standard_price': new_std_price})
# Record the values that were chosen in the wizard, so they can be
# used for inventory valuation if real-time valuation is enabled.