openerp-dev-web team mailing list archive
-
openerp-dev-web team
-
Mailing list archive
-
Message #05765
[Merge] lp:~openerp-dev/openobject-addons/6.0-bug-767275-xrg into lp:openobject-addons/6.0
xrg has proposed merging lp:~openerp-dev/openobject-addons/6.0-bug-767275-xrg into lp:openobject-addons/6.0.
Requested reviews:
OpenERP Core Team (openerp)
Related bugs:
Bug #767275 in OpenERP Addons: "stock: fix, cleanup at product.py for previous commit"
https://bugs.launchpad.net/openobject-addons/+bug/767275
For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/6.0-bug-767275-xrg/+merge/58520
--
https://code.launchpad.net/~openerp-dev/openobject-addons/6.0-bug-767275-xrg/+merge/58520
Your team OpenERP R&D Team is subscribed to branch lp:~openerp-dev/openobject-addons/6.0-bug-767275-xrg.
=== modified file 'stock/product.py'
--- stock/product.py 2011-04-08 13:32:12 +0000
+++ stock/product.py 2011-04-20 15:26:33 +0000
@@ -190,7 +190,6 @@
if not ids:
return res
- # TODO: write in more ORM way, less queries, more pg84 magic
if context.get('shop', False):
cr.execute('select warehouse_id from sale_shop where id=%s', (int(context['shop']),))
res2 = cr.fetchone()
@@ -234,48 +233,45 @@
from_date = context.get('from_date',False)
to_date = context.get('to_date',False)
- date_str = False
- date_values = False
+ date_str = ''
where = [tuple(location_ids),tuple(location_ids),tuple(ids),tuple(states)]
if from_date and to_date:
- date_str = "date>=%s and date<=%s"
+ date_str = "AND date>=%s AND date<=%s "
where.append(tuple([from_date]))
where.append(tuple([to_date]))
elif from_date:
- date_str = "date>=%s"
- date_values = [from_date]
+ date_str = "AND date>=%s "
+ where.append(from_date)
elif to_date:
- date_str = "date<=%s"
- date_values = [to_date]
-
- prodlot_id = context.get('prodlot_id', False)
-
- # TODO: perhaps merge in one query.
- if date_values:
- where.append(tuple(date_values))
+ date_str = "AND date<=%s "
+ where.append(to_date)
+
+ prodlot_str = ''
+ if context.get('prodlot_id', False):
+ prodlot_str = 'AND prodlot_id = %s'
+ where.append(context['prodlot_id'])
+
if 'in' in what:
# all moves from a location out of the set to a location in the set
cr.execute(
- 'select sum(product_qty), product_id, product_uom '\
- 'from stock_move '\
- 'where location_id NOT IN %s '\
- 'and location_dest_id IN %s '\
- 'and product_id IN %s '\
- '' + (prodlot_id and ('and prodlot_id = ' + str(prodlot_id)) or '') + ' '\
- 'and state IN %s ' + (date_str and 'and '+date_str+' ' or '') +' '\
- 'group by product_id,product_uom',tuple(where))
+ 'SELECT sum(product_qty), product_id, product_uom '\
+ 'FROM stock_move '\
+ 'WHERE location_id NOT IN %s '\
+ 'AND location_dest_id IN %s '\
+ 'AND product_id IN %s '\
+ 'AND state IN %s ' + date_str + prodlot_str + ' '\
+ 'GROUP BY product_id,product_uom',tuple(where))
results = cr.fetchall()
if 'out' in what:
# all moves from a location in the set to a location out of the set
cr.execute(
- 'select sum(product_qty), product_id, product_uom '\
- 'from stock_move '\
- 'where location_id IN %s '\
- 'and location_dest_id NOT IN %s '\
- 'and product_id IN %s '\
- '' + (prodlot_id and ('and prodlot_id = ' + str(prodlot_id)) or '') + ' '\
- 'and state in %s ' + (date_str and 'and '+date_str+' ' or '') + ' '\
- 'group by product_id,product_uom',tuple(where))
+ 'SELECT sum(product_qty), product_id, product_uom '\
+ 'FROM stock_move '\
+ 'WHERE location_id IN %s '\
+ 'AND location_dest_id NOT IN %s '\
+ 'AND product_id IN %s '\
+ 'AND state IN %s ' + date_str + prodlot_str + ' '\
+ 'GROUP BY product_id,product_uom',tuple(where))
results2 = cr.fetchall()
uom_obj = self.pool.get('product.uom')
uoms = map(lambda x: x[2], results) + map(lambda x: x[2], results2)