From 81418ec14eda89b0d6036bdbc6c7731b56972aff Mon Sep 17 00:00:00 2001 From: Humberto Arocha Date: Sat, 10 Oct 2015 04:17:24 -0430 Subject: [PATCH] [FIX] stock_landed_costs: avoid useless multiple writes Initialise quant_dict inside for loop as doing outside loops renders to be a quadratic write of quant object due to the fact that previous quants are kept each time a new valuation line is read. In case of posting a Landed Cost record with a huge amount of cost_lines and huge amount of stock_move having several quants would result in a extra overhead. Closes #9005 --- addons/stock_landed_costs/stock_landed_costs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/stock_landed_costs/stock_landed_costs.py b/addons/stock_landed_costs/stock_landed_costs.py index 618df110e29..a7f2b4b4586 100644 --- a/addons/stock_landed_costs/stock_landed_costs.py +++ b/addons/stock_landed_costs/stock_landed_costs.py @@ -202,13 +202,13 @@ class stock_landed_cost(osv.osv): if not cost.valuation_adjustment_lines or not self._check_sum(cr, uid, cost, context=context): raise osv.except_osv(_('Error!'), _('You cannot validate a landed cost which has no valid valuation lines.')) move_id = self._create_account_move(cr, uid, cost, context=context) - quant_dict = {} for line in cost.valuation_adjustment_lines: if not line.move_id: continue per_unit = line.final_cost / line.quantity diff = per_unit - line.former_cost_per_unit quants = [quant for quant in line.move_id.quant_ids] + quant_dict = {} for quant in quants: if quant.id not in quant_dict: quant_dict[quant.id] = quant.cost + diff