summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Seinlet <nse@openerp.com>2019-01-16 14:08:18 +0100
committerSEINLET Nicolas <nicolas@seinlet.com>2019-01-23 10:30:49 +0100
commit3f4d1e1fbe2da53112d2791c71c6cfb4033c29a4 (patch)
treed87fe90f3d6793f506333e8983b27e83cb4b4392
parent17adccd95c9deb692e738a72fa38b85173ef9b7a (diff)
[IMP] mrp,stock_account: faster computation
Use read_group is faster than the python equivalent, and then don't push ids in ORM cache, which makes the ORM faster later in the process. Also unlink in batch.
-rw-r--r--addons/mrp/models/stock_move.py22
-rw-r--r--addons/stock_account/models/stock.py2
2 files changed, 19 insertions, 5 deletions
diff --git a/addons/mrp/models/stock_move.py b/addons/mrp/models/stock_move.py
index 868bd08d121..2e0b4ce374c 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 0ba1f76102a..d2a853f2253 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.