From a1aada9f76510510bcd085d29cb56633f129c642 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Pigeon?= Date: Thu, 30 Mar 2017 10:58:39 +0200 Subject: [PATCH] [FIX] stock: new cursor for orderpoint On large databases, the orderpoint calculation can fail due to the huge cache used diring the process. Instead of using one cursor for the transaction, we create a new cursor every 100 orderpoints, to limit the cache size and speed up the performances. opw-726711 Closes #16158 --- addons/stock/procurement.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/addons/stock/procurement.py b/addons/stock/procurement.py index 61737fd80c3..48c929deb48 100644 --- a/addons/stock/procurement.py +++ b/addons/stock/procurement.py @@ -331,13 +331,12 @@ class procurement_order(osv.osv): ''' Create procurement based on Orderpoint - :param bool use_new_cursor: if set, use a dedicated cursor and auto-commit after processing each procurement. + :param bool use_new_cursor: if set, use dedicated cursors and auto-commit after processing + 100 orderpoints. This is appropriate for batch jobs only. ''' if context is None: context = {} - if use_new_cursor: - cr = openerp.registry(cr.dbname).cursor() orderpoint_obj = self.pool.get('stock.warehouse.orderpoint') procurement_obj = self.pool.get('procurement.order') @@ -347,6 +346,8 @@ class procurement_order(osv.osv): while orderpoint_ids: ids = orderpoint_ids[:100] del orderpoint_ids[:100] + if use_new_cursor: + cr = openerp.registry(cr.dbname).cursor() for op in orderpoint_obj.browse(cr, uid, ids, context=context): try: prods = self._product_virtual_get(cr, uid, op) @@ -381,12 +382,10 @@ class procurement_order(osv.osv): raise if use_new_cursor: cr.commit() + cr.close() if prev_ids == ids: break else: prev_ids = ids - if use_new_cursor: - cr.commit() - cr.close() return {}