diff --git a/addons/stock/stock.py b/addons/stock/stock.py
index 7a2320298fe..3221dcbd141 100644
--- a/addons/stock/stock.py
+++ b/addons/stock/stock.py
@@ -3815,10 +3815,9 @@ class stock_pack_operation(osv.osv):
new_lot_id = lots[0]
val.update({'name': name})
- if not obj.lot_id:
- if not new_lot_id:
- new_lot_id = self.pool.get('stock.production.lot').create(cr, uid, val, context=context)
- self.write(cr, uid, id, {'lot_id': new_lot_id}, context=context)
+ if not new_lot_id:
+ new_lot_id = self.pool.get('stock.production.lot').create(cr, uid, val, context=context)
+ self.write(cr, uid, id, {'lot_id': new_lot_id}, context=context)
def _search_and_increment(self, cr, uid, picking_id, domain, filter_visible=False, visible_op_ids=False, increment=True, context=None):
'''Search for an operation with given 'domain' in a picking, if it exists increment the qty (+1) otherwise create it
diff --git a/addons/stock_account/stock_account.py b/addons/stock_account/stock_account.py
index faa699f6d46..7e14ea860b7 100644
--- a/addons/stock_account/stock_account.py
+++ b/addons/stock_account/stock_account.py
@@ -191,7 +191,10 @@ class stock_quant(osv.osv):
if context.get('force_valuation_amount'):
valuation_amount = context.get('force_valuation_amount')
else:
- valuation_amount = move.product_id.cost_method == 'real' and cost or move.product_id.standard_price
+ if move.product_id.cost_method == 'average':
+ valuation_amount = move.location_id.usage != 'internal' and move.location_dest_id.usage == 'internal' and cost or move.product_id.standard_price
+ else:
+ valuation_amount = move.product_id.cost_method == 'real' and cost or move.product_id.standard_price
#the standard_price of the product may be in another decimal precision, or not compatible with the coinage of
#the company currency... so we need to use round() before creating the accounting entries.
valuation_amount = currency_obj.round(cr, uid, move.company_id.currency_id, valuation_amount * qty)