[FIX] speed up with sql query for picking assign

[IMP] Commit and limit query to 1
This commit is contained in:
Josse Colpaert 2015-02-20 12:10:51 +01:00
parent d981f27dc1
commit 4625b5c840
1 changed files with 18 additions and 7 deletions

View File

@ -2074,14 +2074,25 @@ class stock_move(osv.osv):
(and company). Those attributes are also given as parameters. (and company). Those attributes are also given as parameters.
""" """
pick_obj = self.pool.get("stock.picking") pick_obj = self.pool.get("stock.picking")
picks = pick_obj.search(cr, uid, [ # Use a SQL query as doing with the ORM will split it in different queries with id IN (,,)
('group_id', '=', procurement_group), # In the next version, the locations on the picking should be stored again.
('location_id', '=', location_from), query = """
('location_dest_id', '=', location_to), SELECT stock_picking.id FROM stock_picking, stock_move
('state', 'in', ['draft', 'confirmed', 'waiting'])], context=context) WHERE
if picks: stock_picking.state in ('draft', 'confirmed', 'waiting') AND
pick = picks[0] stock_move.picking_id = stock_picking.id AND
stock_move.location_id = %s AND
stock_move.location_dest_id = %s AND
"""
params = (location_from, location_to)
if not procurement_group:
query += "stock_picking.group_id IS NULL LIMIT 1"
else: else:
query += "stock_picking.group_id = %s LIMIT 1"
params += (procurement_group,)
cr.execute(query, params)
pick = cr.fetchone()
if not pick:
move = self.browse(cr, uid, move_ids, context=context)[0] move = self.browse(cr, uid, move_ids, context=context)[0]
values = { values = {
'origin': move.origin, 'origin': move.origin,