From 910f12b88ee8e77576dea3552299979d1bceaec2 Mon Sep 17 00:00:00 2001 From: "Lucas Perais (lpe)" Date: Mon, 27 Mar 2017 16:45:52 +0200 Subject: [PATCH] [FIX]: stock_landed_cost: optimization of stock.landed.cost. Only recompute account move line and move fields when everything is created. OPW 725897 Closes #16088 --- addons/stock_landed_costs/stock_landed_costs.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/addons/stock_landed_costs/stock_landed_costs.py b/addons/stock_landed_costs/stock_landed_costs.py index fe793f4ed22..df25ddc0e17 100644 --- a/addons/stock_landed_costs/stock_landed_costs.py +++ b/addons/stock_landed_costs/stock_landed_costs.py @@ -101,6 +101,7 @@ class stock_landed_cost(osv.osv): if context is None: context = {} ctx = context.copy() + ctx['recompute'] = False ctx['check_move_validity'] = False base_line = { 'name': line.name, @@ -120,7 +121,7 @@ class stock_landed_cost(osv.osv): credit_line['debit'] = -diff aml_obj.create(cr, uid, debit_line, context=ctx) aml_obj.create(cr, uid, credit_line, context=ctx) - + #Create account move lines for quants already out of stock if qty_out > 0: debit_line = dict(base_line, @@ -161,8 +162,6 @@ class stock_landed_cost(osv.osv): credit_line['debit'] = -diff aml_obj.create(cr, uid, debit_line, context=ctx) aml_obj.create(cr, uid, credit_line, context=ctx) - - self.pool.get('account.move').assert_balanced(cr, uid, [move_id], context=context) return True def _create_account_move(self, cr, uid, cost, context=None): @@ -251,6 +250,8 @@ class stock_landed_cost(osv.osv): if quant.location_id.usage != 'internal': qty_out += quant.qty self._create_accounting_entries(cr, uid, line, move_id, qty_out, context=context) + self.recompute(cr, uid, context=context) + self.pool.get('account.move').assert_balanced(cr, uid, [move_id], context=context) self.write(cr, uid, cost.id, {'state': 'done', 'account_move_id': move_id}, context=context) self.pool.get('account.move').post(cr, uid, [move_id], context=context) return True