diff --git a/addons/mrp/models/stock_move.py b/addons/mrp/models/stock_move.py
index 868bd08d1219e0aa05a787ecaf6c47f8d2fe71b2..2e0b4ce374c7a4796faffde83b7b43e0339cd050 100644
--- a/addons/mrp/models/stock_move.py
+++ b/addons/mrp/models/stock_move.py
@@ -116,9 +116,24 @@ class StockMove(models.Model):
     @api.multi
     @api.depends('move_lot_ids', 'move_lot_ids.quantity_done', 'quantity_done_store')
     def _qty_done_compute(self):
+        move_lot_ids = self.env['stock.move.lots'].sudo().read_group(
+            [('move_id', 'in', self.ids), ('lot_id', '!=', False)],
+            ['move_id'],
+            ['move_id']
+        )
+        move_lot_count = {x['move_id'][0]: x['move_id_count'] for x in move_lot_ids}
+        move_qty_ids = self.env['stock.move.lots'].sudo().read_group(
+            [
+                ('move_id', 'in', self.ids),
+                ('done_wo', '!=', False)
+            ],
+            ['move_id', 'quantity_done'],
+            ['move_id']
+        )
+        move_qty = {x['move_id'][0]: x['quantity_done'] for x in move_qty_ids}
         for move in self:
-            if move.has_tracking != 'none' or move.sudo().move_lot_ids.mapped('lot_id'):
-                move.quantity_done = sum(move.move_lot_ids.filtered(lambda x: x.done_wo).mapped('quantity_done')) #TODO: change with active_move_lot_ids?
+            if move.has_tracking != 'none' or move_lot_count.get(move.id, 0) > 0:
+                move.quantity_done = move_qty.get(move.id, 0)
             else:
                 move.quantity_done = move.quantity_done_store
 
@@ -162,9 +177,8 @@ class StockMove(models.Model):
     @api.multi
     def create_lots(self):
         lots = self.env['stock.move.lots']
+        lots.search([('move_id', 'in', self.ids), ('done_wo', '=', True), ('quantity_done', '=', 0)]).sudo().unlink()
         for move in self:
-            unlink_move_lots = move.move_lot_ids.filtered(lambda x : (x.quantity_done == 0) and x.done_wo)
-            unlink_move_lots.sudo().unlink()
             group_new_quant = {}
             old_move_lot = {}
             for movelot in move.move_lot_ids:
diff --git a/addons/stock_account/models/stock.py b/addons/stock_account/models/stock.py
index 0ba1f76102a6eb55a2fd58ff8ae1081656b16496..d2a853f2253fac4a04de4a73197f3332b9f57336 100644
--- a/addons/stock_account/models/stock.py
+++ b/addons/stock_account/models/stock.py
@@ -150,7 +150,7 @@ class StockQuant(models.Model):
     def _quant_create_from_move(self, qty, move, lot_id=False, owner_id=False, src_package_id=False, dest_package_id=False, force_location_from=False, force_location_to=False):
         quant = super(StockQuant, self)._quant_create_from_move(qty, move, lot_id=lot_id, owner_id=owner_id, src_package_id=src_package_id, dest_package_id=dest_package_id, force_location_from=force_location_from, force_location_to=force_location_to)
         quant._account_entry_move(move)
-        if move.product_id.valuation == 'real_time':
+        if move.product_id.product_tmpl_id.valuation == 'real_time':
             # If the precision required for the variable quant cost is larger than the accounting
             # precision, inconsistencies between the stock valuation and the accounting entries
             # may arise.