From a9ddac89a6b4c71bd23c7a285e127de59272d27b Mon Sep 17 00:00:00 2001 From: Olivier Laurent Date: Mon, 15 Dec 2008 13:41:13 +0100 Subject: [PATCH] Fixed: bad sql query if no inventory location was chosen when trying to set stock to 0. Now a warning dialog appear asking to choose at least one inventory location bzr revid: olt@tinyerp.com-20081215124113-v4omh9enhed60ek4 --- addons/stock/wizard/inventory_merge_zero.py | 32 ++++++++++++--------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/addons/stock/wizard/inventory_merge_zero.py b/addons/stock/wizard/inventory_merge_zero.py index f0ce60b4c22..19648d25dde 100644 --- a/addons/stock/wizard/inventory_merge_zero.py +++ b/addons/stock/wizard/inventory_merge_zero.py @@ -40,7 +40,7 @@ def do_merge(self, cr, uid, data, context): if len(data['ids']) <> 1: raise wizard.except_wizard("Warning", - "Please select one and only one inventory!") + "Please select one and only one inventory !") cr.execute('select distinct location_id from stock_inventory_line where inventory_id=%s', (data['ids'][0],)) loc_ids = map(lambda x: x[0], cr.fetchall()) @@ -49,19 +49,23 @@ def do_merge(self, cr, uid, data, context): cr.execute('select distinct location_id,product_id from stock_inventory_line where inventory_id=%s', (data['ids'][0],)) inv = cr.fetchall() - cr.execute('select distinct product_id from stock_move where (location_dest_id in ('+locs+')) or (location_id in ('+locs+'))') - stock = cr.fetchall() - for s in stock: - for loc in loc_ids: - if (loc,s[0]) not in inv: - p = prod_obj.browse(cr, uid, s[0]) - invent_line_obj.create(cr, uid, { - 'inventory_id': data['ids'][0], - 'location_id': loc, - 'product_id': s[0], - 'product_uom': p.uom_id.id, - 'product_qty': 0.0, - }) + if not inv: + raise wizard.except_wizard("Warning", + "Please select at least one inventory location !") + else: + cr.execute('select distinct product_id from stock_move where (location_dest_id in ('+locs+')) or (location_id in ('+locs+'))') + stock = cr.fetchall() + for s in stock: + for loc in loc_ids: + if (loc,s[0]) not in inv: + p = prod_obj.browse(cr, uid, s[0]) + invent_line_obj.create(cr, uid, { + 'inventory_id': data['ids'][0], + 'location_id': loc, + 'product_id': s[0], + 'product_uom': p.uom_id.id, + 'product_qty': 0.0, + }) return {}