From fcc2852a27998d4d566b6ede33fe71686ea0a4e9 Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Tue, 30 Jun 2015 18:32:45 +0200 Subject: [PATCH] [FIX] stock, jit: run isn't supposed to be called without jit This is related to ddfc07a6a2e8c399639c6cb8fde2a579b33cd6b0. If procurement_jit_stock is not installed, the method `run` of `procurement.order` is not supposed to be called --- .../procurement_jit_stock.py | 8 ++++++++ addons/stock/stock.py | 18 +++++++++++------- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/addons/procurement_jit_stock/procurement_jit_stock.py b/addons/procurement_jit_stock/procurement_jit_stock.py index 61fac0efd78..2f4de3e5754 100644 --- a/addons/procurement_jit_stock/procurement_jit_stock.py +++ b/addons/procurement_jit_stock/procurement_jit_stock.py @@ -35,4 +35,12 @@ class procurement_order(osv.osv): return self.run(cr, uid, procurement_ids, context=context) return res +class stock_move(osv.osv): + _inherit = "stock.move" + + def _create_procurements(self, cr, uid, moves, context=None): + res = super(stock_move, self)._create_procurements(cr, uid, moves, context=dict(context or {}, procurement_autorun_defer=True)) + self.pool['procurement.order'].run(cr, uid, res, context=context) + return res + # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/stock/stock.py b/addons/stock/stock.py index 47976153b62..ca89424a544 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -1956,6 +1956,12 @@ class stock_move(osv.osv): """ This will create a procurement order """ return self.pool.get("procurement.order").create(cr, uid, self._prepare_procurement_from_move(cr, uid, move, context=context), context=context) + def _create_procurements(self, cr, uid, moves, context=None): + res = [] + for move in moves: + res.append(self._create_procurement(cr, uid, move, context=context)) + return res + def write(self, cr, uid, ids, vals, context=None): if context is None: context = {} @@ -2197,13 +2203,11 @@ class stock_move(osv.osv): if key not in to_assign: to_assign[key] = [] to_assign[key].append(move.id) - proc_ids = [] - for move in self.browse(cr, uid, states['confirmed'], context=context): - if move.procure_method == 'make_to_order': - proc_ids.append(self._create_procurement(cr, uid, move, context=dict(context, procurement_autorun_defer=True))) - states['waiting'].append(move.id) - states['confirmed'].remove(move.id) - self.pool['procurement.order'].run(cr, uid, proc_ids, context=context) + moves = [move for move in self.browse(cr, uid, states['confirmed'], context=context) if move.procure_method == 'make_to_order'] + self._create_procurements(cr, uid, moves, context=context) + for move in moves: + states['waiting'].append(move.id) + states['confirmed'].remove(move.id) for state, write_ids in states.items(): if len(write_ids):