From c13ca999d842fb87eff3fc3c080ac2f82f3ef833 Mon Sep 17 00:00:00 2001 From: "nch@tinyerp.com" <> Date: Tue, 24 Nov 2009 18:40:45 +0530 Subject: [PATCH] [IMP]:MRP module sql queries to parameterized query bzr revid: nch@tinyerp.com-20091124131045-cl53el8bke3o1py2 --- addons/mrp/mrp.py | 12 ++++++------ addons/mrp/report/workcenter_load.py | 19 +++++++++---------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index 5ba9d487400..b9ccc10bec2 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2009 Tiny SPRL (). # @@ -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 . +# along with this program. If not, see . # ############################################################################## @@ -215,9 +215,9 @@ class mrp_bom(osv.osv): ] def _check_recursion(self, cr, uid, ids): - level = 500 + level = 100 while len(ids): - cr.execute('select distinct bom_id from mrp_bom where id in ('+','.join(map(str, ids))+')') + cr.execute('select distinct bom_id from mrp_bom where id =ANY(%s)',(ids,)) ids = filter(None, map(lambda x:x[0], cr.fetchall())) if not level: return False @@ -363,7 +363,7 @@ class mrp_production(osv.osv): parent_move_line=get_parent_move(production['move_prod_id'][0]) if parent_move_line: move = move_obj.browse(cr,uid,parent_move_line) - #TODO: fix me sale module can not be used here, + #TODO: fix me sale module can not be used here, #as may be mrp can be installed without sale module if field_name=='name': res[production['id']]=move.sale_line_id and move.sale_line_id.order_id.name or False @@ -782,7 +782,7 @@ mrp_production_product_line() class mrp_procurement(osv.osv): _name = "mrp.procurement" _description = "Procurement" - _order = 'priority,date_planned' + _order = 'priority,date_planned' _columns = { 'name': fields.char('Name', size=64, required=True), 'origin': fields.char('Origin', size=64, diff --git a/addons/mrp/report/workcenter_load.py b/addons/mrp/report/workcenter_load.py index 4ec95f0d289..1d02dbfa4f7 100644 --- a/addons/mrp/report/workcenter_load.py +++ b/addons/mrp/report/workcenter_load.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2009 Tiny SPRL (). # @@ -15,11 +15,11 @@ # 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 . +# along with this program. If not, see . # ############################################################################## -from report.render import render +from report.render import render from report.interface import report_int from pychart import * from mx.DateTime import * @@ -42,7 +42,7 @@ class external_pdf(render): render.__init__(self) self.pdf = pdf self.output_type='pdf' - + def _render(self): return self.pdf @@ -98,14 +98,13 @@ class report_custom(report_int): def create(self, cr, uid, ids, datas, context={}): assert len(ids), 'You should provide some ids!' colors = choice_colors(len(ids)) - ids_str = ','.join(map(str, ids)) cr.execute( "SELECT MAX(mrp_production.date_planned) AS stop,MIN(mrp_production.date_planned) AS start "\ "FROM mrp_workcenter, mrp_production, mrp_production_workcenter_line "\ "WHERE mrp_production_workcenter_line.production_id=mrp_production.id "\ "AND mrp_production_workcenter_line.workcenter_id=mrp_workcenter.id "\ "AND mrp_production.state NOT IN ('cancel','done') "\ - "AND mrp_workcenter.id IN (%s)" % ids_str) + "AND mrp_workcenter.id =ANY(%s)",(ids,)) res = cr.dictfetchone() if not res['stop']: res['stop'] = time.strftime('%Y-%m-%d %H:%M:%S') @@ -136,8 +135,8 @@ class report_custom(report_int): # select workcenters cr.execute( "SELECT id, name FROM mrp_workcenter " \ - "WHERE id in (%s) "\ - "ORDER BY mrp_workcenter.id" % ids_str) + "WHERE id=ANY(%s)" \ + "ORDER BY mrp_workcenter.id" ,(ids,)) workcenters = cr.dictfetchall() data = [] @@ -161,7 +160,7 @@ class report_custom(report_int): vals.append(res[0]['cycles'] or 0.0) else: vals.append(res[0]['hours'] or 0.0) - + toto = [dates[date]['name']] for val in vals: toto.append(val) @@ -184,7 +183,7 @@ class report_custom(report_int): self.obj.render() pdf_string.close() return (self.obj.pdf, 'pdf') - + def _empty_graph(self, date): data = [[date, 0]] ar = area.T(x_coord = category_coord.T(data, 0), y_range = (0, None),