From c5dc1288c2653caf9d55c63fc766c4edcc93d54c Mon Sep 17 00:00:00 2001 From: Josse Colpaert Date: Mon, 2 Mar 2015 10:12:53 +0100 Subject: [PATCH] [IMP] To optimize procurement_jit, we let it depend on stock. Runs can be done in batch that way. Optimizations from work of api [IMP] Simplify to single search [IMP] Make sure procurements are run in the original order --- addons/procurement_jit/__openerp__.py | 2 +- addons/procurement_jit/procurement_jit.py | 11 +++++++++++ addons/stock/stock.py | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/addons/procurement_jit/__openerp__.py b/addons/procurement_jit/__openerp__.py index e98ad222509..45d34aabdee 100644 --- a/addons/procurement_jit/__openerp__.py +++ b/addons/procurement_jit/__openerp__.py @@ -40,7 +40,7 @@ In that case, you can not use priorities any more on the different picking. """, 'author': 'OpenERP SA', 'website': 'https://www.odoo.com/page/manufacturing', - 'depends': ['procurement'], + 'depends': ['procurement', 'stock'], 'data': [], 'demo': [], 'test': ['test/procurement_jit.yml'], diff --git a/addons/procurement_jit/procurement_jit.py b/addons/procurement_jit/procurement_jit.py index c7b36ebed98..40360b0aa3a 100644 --- a/addons/procurement_jit/procurement_jit.py +++ b/addons/procurement_jit/procurement_jit.py @@ -32,3 +32,14 @@ class procurement_order(osv.osv): self.run(cr, uid, [procurement_id], context=context) self.check(cr, uid, [procurement_id], context=context) return procurement_id + + def run(self, cr, uid, ids, context=None): + context = context or {} + context['procurement_autorun_defer'] = True + res = super(procurement_order, self).run(cr, uid, ids, context=context) + + procurement_ids = self.search(cr, uid, [('move_dest_id.procurement_id', 'in', ids)], order='id', context=context) + + if procurement_ids: + return self.run(cr, uid, procurement_ids, context=context) + return res diff --git a/addons/stock/stock.py b/addons/stock/stock.py index ddfde0a3f75..82cdf67d32b 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -1950,7 +1950,7 @@ class stock_move(osv.osv): def _create_procurement(self, cr, uid, move, context=None): """ 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)) + return self.pool.get("procurement.order").create(cr, uid, self._prepare_procurement_from_move(cr, uid, move, context=context), context=context) def write(self, cr, uid, ids, vals, context=None): if context is None: