[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
This commit is contained in:
Cédric Pigeon 2017-03-30 10:58:39 +02:00 committed by Nicolas Martinelli
parent 794c9f5118
commit a1aada9f76
1 changed files with 5 additions and 6 deletions

View File

@ -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 {}