[IMP]:stock module sql queries to parameterized query

bzr revid: nch@tinyerp.com-20091124090610-uin098njqilg9wpe
This commit is contained in:
nch@tinyerp.com
2009-11-24 14:36:10 +05:30
parent 966d3091f3
commit 8bd969b134
4 changed files with 36 additions and 54 deletions
+10 -14
View File
@@ -73,16 +73,12 @@ class product_product(osv.osv):
else:
location_ids= location_ids
states_str = ','.join(map(lambda s: "'%s'" % s, states))
uoms_o = {}
product2uom = {}
for product in self.browse(cr, uid, ids, context=context):
product2uom[product.id] = product.uom_id.id
uoms_o[product.uom_id.id] = product.uom_id
prod_ids_str = ','.join(map(str, ids))
location_ids_str = ','.join(map(str, location_ids))
results = []
results2 = []
@@ -101,11 +97,11 @@ class product_product(osv.osv):
cr.execute(
'select sum(product_qty), product_id, product_uom '\
'from stock_move '\
'where location_id not in ('+location_ids_str+') '\
'and location_dest_id in ('+location_ids_str+') '\
'and product_id in ('+prod_ids_str+') '\
'and state in ('+states_str+') '+ (date_str and 'and '+date_str+' ' or '') +''\
'group by product_id,product_uom'
'where location_id <> ANY(%s)'\
'and location_dest_id =ANY(%s)'\
'and product_id =ANY(%s)'\
'and state in %s' + (date_str and 'and '+date_str+' ' or '') +''\
'group by product_id,product_uom',(location_ids,location_ids,ids,states,)
)
results = cr.fetchall()
if 'out' in what:
@@ -113,11 +109,11 @@ class product_product(osv.osv):
cr.execute(
'select sum(product_qty), product_id, product_uom '\
'from stock_move '\
'where location_id in ('+location_ids_str+') '\
'and location_dest_id not in ('+location_ids_str+') '\
'and product_id in ('+prod_ids_str+') '\
'and state in ('+states_str+') '+ (date_str and 'and '+date_str+' ' or '') + ''\
'group by product_id,product_uom'
'where location_id = ANY(%s)'\
'and location_dest_id <> ANY(%s) '\
'and product_id =ANY(%s)'\
'and state in %s' + (date_str and 'and '+date_str+' ' or '') + ''\
'group by product_id,product_uom',(location_ids,location_ids,ids,states,)
)
results2 = cr.fetchall()
uom_obj = self.pool.get('product.uom')
+11 -17
View File
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
##############################################################################
#
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
#
@@ -15,7 +15,7 @@
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
@@ -35,7 +35,7 @@ class external_pdf(render):
render.__init__(self)
self.pdf = pdf
self.output_type='pdf'
def _render(self):
return self.pdf
@@ -66,17 +66,12 @@ class report_stock(report_int):
if not loc_ids or not product_ids:
return (False, 'pdf')
loc_ids_s = ",".join(['%s']*len(loc_ids))
prod_ids_s = ",".join(['%s']*len(product_ids))
cr.execute("select sum(r.product_qty * u.factor), r.date_planned, r.product_id "
"from stock_move r left join product_uom u on (r.product_uom=u.id) "
"where state in ('confirmed','assigned','waiting') "
"and location_id in (%s) "
"and product_id in (%s) "
"group by date_planned,product_id" % (loc_ids_s, prod_ids_s),
loc_ids + product_ids)
"where state =ANY(%s)"
"and location_id=ANY(%s)"
"and product_id=ANY(%s)"
"group by date_planned,product_id",(['confirmed','assigned','waiting'],loc_ids ,product_ids,))
for (qty, dt, prod_id) in cr.fetchall():
if dt<=dt_from:
dt= (DateTime.now() + DateTime.RelativeDateTime(days=1)).strftime('%Y-%m-%d')
@@ -87,11 +82,10 @@ class report_stock(report_int):
cr.execute("select sum(r.product_qty * u.factor), r.date_planned, r.product_id "
"from stock_move r left join product_uom u on (r.product_uom=u.id) "
"where state in ('confirmed','assigned','waiting') "
"and location_dest_id in (%s) "
"and product_id in (%s) "
"group by date_planned,product_id" % (loc_ids_s, prod_ids_s),
loc_ids + product_ids)
"where state=ANY(%s)"
"and location_dest_id=ANY(%s)"
"and product_id=ANY(%s)"
"group by date_planned,product_id",(['confirmed','assigned','waiting'],loc_ids ,product_ids,))
for (qty, dt, prod_id) in cr.fetchall():
if dt<=dt_from:
+12 -20
View File
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
##############################################################################
#
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
#
@@ -15,7 +15,7 @@
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
@@ -419,9 +419,9 @@ class stock_picking(osv.osv):
from
stock_move
where
picking_id in (""" + ','.join(map(str, ids)) + """)
picking_id=ANY(%s)
group by
picking_id""")
picking_id""",(ids,))
for pick, dt1, dt2 in cr.fetchall():
res[pick]['min_date'] = dt1
res[pick]['max_date'] = dt2
@@ -707,7 +707,7 @@ class stock_picking(osv.osv):
'name': (invoice.name or '') + ', ' + (picking.name or ''),
'origin': (invoice.origin or '') + ', ' + (picking.name or '') + (picking.origin and (':' + picking.origin) or ''),
'comment': (comment and (invoice.comment and invoice.comment+"\n"+comment or comment)) or (invoice.comment and invoice.comment or ''),
'date_invoice':context.get('date_inv',False)
'date_invoice':context.get('date_inv',False)
}
invoice_obj.write(cursor, user, [invoice_id], invoice_vals, context=context)
else:
@@ -768,7 +768,7 @@ class stock_picking(osv.osv):
notes = move_line.sale_line_id.notes
elif move_line.purchase_line_id:
notes = move_line.purchase_line_id.notes
invoice_line_id = invoice_line_obj.create(cursor, user, {
'name': name,
'origin': origin,
@@ -781,7 +781,7 @@ class stock_picking(osv.osv):
'quantity': move_line.product_uos_qty or move_line.product_qty,
'invoice_line_tax_id': [(6, 0, tax_ids)],
'account_analytic_id': account_analytic_id,
'note': notes,
'note': notes,
}, context=context)
self._invoice_line_hook(cursor, user, move_line, invoice_line_id)
@@ -834,7 +834,6 @@ class stock_production_lot(osv.osv):
ids = [ids]
res = {}.fromkeys(ids, 0.0)
if locations:
cr.execute('''select
prodlot_id,
@@ -842,11 +841,7 @@ class stock_production_lot(osv.osv):
from
stock_report_prodlots
where
location_id in ('''+','.join(map(str, locations))+''') and
prodlot_id in ('''+','.join(map(str, ids))+''')
group by
prodlot_id
''')
location_id =ANY(%s) and prodlot_id =ANY(%s) group by prodlot_id''',(locations,ids,))
res.update(dict(cr.fetchall()))
return res
@@ -858,11 +853,8 @@ class stock_production_lot(osv.osv):
from
stock_report_prodlots
where
location_id in ('''+','.join(map(str, locations)) + ''')
group by
prodlot_id
having sum(name) ''' + str(args[0][1]) + ''' ''' + str(args[0][2])
)
location_id =ANY(%s) group by prodlot_id
having sum(name) '''+ str(args[0][1]) + str(args[0][2]),(locations,))
res = cr.fetchall()
ids = [('id', 'in', map(lambda x: x[0], res))]
return ids
@@ -1163,8 +1155,8 @@ class stock_move(osv.osv):
if res:
#_product_available_test depends on the next status for correct functioning
#the test does not work correctly if the same product occurs multiple times
#in the same order. This is e.g. the case when using the button 'split in two' of
#the stock outgoing form
#in the same order. This is e.g. the case when using the button 'split in two' of
#the stock outgoing form
self.write(cr, uid, move.id, {'state':'assigned'})
done.append(move.id)
pickings[move.picking_id.id] = 1
+3 -3
View File
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
##############################################################################
#
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
#
@@ -15,7 +15,7 @@
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
@@ -56,7 +56,7 @@ 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='+loc+') or (location_id='+loc+')')
cr.execute('select distinct product_id from stock_move where location_dest_id=%s or location_id=%s',(loc,loc,))
stock = cr.fetchall()
for s in stock:
if (loc,s[0]) not in inv: