From e7d941f0c4bedaca6c2a78a1466020794adc7a37 Mon Sep 17 00:00:00 2001 From: "nch@tinyerp.com" <> Date: Mon, 23 Nov 2009 15:47:47 +0530 Subject: [PATCH 01/53] [IMP]:sale.py sql queries to parameterized query bzr revid: nch@tinyerp.com-20091123101747-y36faeunlz1kdrl3 --- addons/sale/sale.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/addons/sale/sale.py b/addons/sale/sale.py index 794935855a2..4119e393174 100644 --- a/addons/sale/sale.py +++ b/addons/sale/sale.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 . # ############################################################################## @@ -99,8 +99,7 @@ class sale_order(osv.osv): LEFT JOIN stock_picking p on (p.id=m.picking_id) WHERE - p.sale_id in ('''+','.join(map(str, ids))+''') - GROUP BY m.state, p.sale_id''') + p.sale_id in %s GROUP BY m.state, p.sale_id''',(tuple(ids),)) for oid, nbr, state in cr.fetchall(): if state == 'cancel': continue @@ -295,7 +294,7 @@ class sale_order(osv.osv): def action_cancel_draft(self, cr, uid, ids, *args): if not len(ids): return False - cr.execute('select id from sale_order_line where order_id in ('+','.join(map(str, ids))+')', ('draft',)) + cr.execute('select id from sale_order_line where order_id in %s and state=%s',(tuple(ids),'cancel')) line_ids = map(lambda x: x[0], cr.fetchall()) self.write(cr, uid, ids, {'state': 'draft', 'invoice_ids': [], 'shipped': 0}) self.pool.get('sale.order.line').write(cr, uid, line_ids, {'invoiced': False, 'state': 'draft', 'invoice_lines': [(6, 0, [])]}) @@ -395,7 +394,7 @@ class sale_order(osv.osv): invoice_ids = [] context = {} - # If date was specified, use it as date invoiced, usefull when invoices are generated this month and put the + # If date was specified, use it as date invoiced, usefull when invoices are generated this month and put the # last day of the last month as invoice date if date_inv: context['date_inv'] = date_inv @@ -496,7 +495,7 @@ class sale_order(osv.osv): if line.procurement_id: res.append(line.procurement_id.id) return res - + # if mode == 'finished': # returns True if all lines are done, False otherwise # if mode == 'canceled': @@ -510,13 +509,13 @@ class sale_order(osv.osv): write_cancel_ids = [] stock_move_obj = self.pool.get('stock.move') for order in self.browse(cr, uid, ids, context={}): - - #check for pending deliveries + + #check for pending deliveries pending_deliveries = False # check => if order_lines do not exist,don't proceed for any mode. if not order.order_line: return False - for line in order.order_line: + for line in order.order_line: move_ids = stock_move_obj.search(cr, uid, [('sale_line_id','=', line.id)]) for move in stock_move_obj.browse( cr, uid, move_ids ): #if one of the related order lines is in state draft, auto or confirmed From 363c136135a2e86cee1d9c8c8bbfab8355475888 Mon Sep 17 00:00:00 2001 From: "nch@tinyerp.com" <> Date: Mon, 23 Nov 2009 16:02:13 +0530 Subject: [PATCH 02/53] [IMP]:purchase.py sql queries to parameterized query bzr revid: nch@tinyerp.com-20091123103213-xr270qb0ptvjztkx --- addons/purchase/purchase.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/addons/purchase/purchase.py b/addons/purchase/purchase.py index 05128504ed5..32889e20f57 100644 --- a/addons/purchase/purchase.py +++ b/addons/purchase/purchase.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 . # ############################################################################## @@ -111,8 +111,7 @@ class purchase_order(osv.osv): LEFT JOIN stock_picking p on (p.id=m.picking_id) WHERE - p.purchase_id in ('''+','.join(map(str, ids))+''') - GROUP BY m.state, p.purchase_id''') + p.purchase_id in %s GROUP BY m.state, p.purchase_id''',(tuple(ids),)) for oid,nbr,state in cr.fetchall(): if state=='cancel': continue @@ -194,7 +193,7 @@ class purchase_order(osv.osv): }, multi="sums"), 'fiscal_position': fields.many2one('account.fiscal.position', 'Fiscal Position'), 'product_id': fields.related('order_line','product_id', type='many2one', relation='product.product', string='Product'), - 'create_uid': fields.many2one('res.users', 'Responsible'), + 'create_uid': fields.many2one('res.users', 'Responsible'), } _defaults = { 'date_order': lambda *a: time.strftime('%Y-%m-%d'), From 9da3063328622dad36efb2c41d40a5ab3399128e Mon Sep 17 00:00:00 2001 From: "nch@tinyerp.com" <> Date: Mon, 23 Nov 2009 17:19:56 +0530 Subject: [PATCH 03/53] [IMP]:scrum modules sql queries to parameterized query bzr revid: nch@tinyerp.com-20091123114956-lr17g8i6fjp74o4e --- addons/scrum/report/_burndown.py | 11 +++++------ addons/scrum/report/task_burndown.py | 13 +++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/addons/scrum/report/_burndown.py b/addons/scrum/report/_burndown.py index f0ccc51cc95..fc7b60437ae 100644 --- a/addons/scrum/report/_burndown.py +++ b/addons/scrum/report/_burndown.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 . # ############################################################################## @@ -26,14 +26,13 @@ import time def compute_burndown(cr, uid, tasks_id, date_start, date_stop): latest = False if len(tasks_id): - cr.execute('select id,create_date,state,planned_hours from project_task where id in ('+','.join(map(str,tasks_id))+') order by create_date') + cr.execute('select id,create_date,state,planned_hours from project_task where id in %s order by create_date',(tuple(tasks_id),)) tasks = cr.fetchall() - cr.execute('select w.date,w.hours from project_task_work w left join project_task t on (t.id=w.task_id) where t.id in ('+','.join(map(str,tasks_id))+') and t.state in (\'open\',\'progress\') order by date') - + cr.execute('select w.date,w.hours from project_task_work w left join project_task t on (t.id=w.task_id) where t.id in %s and t.state in (%s,%s) order by date',(tuple(tasks_id),'open','progress',)) tasks2 = cr.fetchall() - cr.execute('select date_close,planned_hours from project_task where id in ('+','.join(map(str,tasks_id))+') and state in (\'cancelled\',\'done\') order by date_close') + cr.execute('select date_close,planned_hours from project_task where id in %s and state in (%s,%s) order by date_close' ,(tuple(tasks_id),'cancelled','done',)) tasks2 += cr.fetchall() tasks2.sort() else: diff --git a/addons/scrum/report/task_burndown.py b/addons/scrum/report/task_burndown.py index 977d8fe9e6c..b4c6481ce48 100644 --- a/addons/scrum/report/task_burndown.py +++ b/addons/scrum/report/task_burndown.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 . # ############################################################################## @@ -42,9 +42,10 @@ class external_pdf(render): def burndown_chart(cr, uid, tasks_id, date_start, date_stop): latest = False - cr.execute('select id,date_start,state,planned_hours from project_task where id in ('+','.join(map(str,tasks_id))+') order by date_start') + + cr.execute('select id,date_start,state,planned_hours from project_task where id in %s order by date_start'(tuple(tasks_id),)) tasks = cr.fetchall() - cr.execute('select id,date_close,state,planned_hours*progress/100 from project_task where id in ('+','.join(map(str,tasks_id))+') and state in (%s,%s) order by date_close', ('progress','done')) + cr.execute('select id,date_close,state,planned_hours*progress/100 from project_task where id in %s and state in (%s,%s) order by date_close', (tuple(tasks_id),'progress','done',)) tasks2 = cr.fetchall() current_date = date_start total = 0 @@ -71,14 +72,14 @@ class report_tasks(report_int): io = StringIO.StringIO() if 'date_start' not in datas: - cr.execute('select min(date_start) from project_task where id in ('+','.join(map(str, ids))+')') + cr.execute('select min(date_start) from project_task where id in %s',(tuple(ids),)) dt = cr.fetchone()[0] if dt: datas['date_start'] = dt[:10] else: datas['date_start'] = time.strftime('%Y-%m-%d') if 'date_stop' not in datas: - cr.execute('select max(date_start),max(date_close) from project_task where id in ('+','.join(map(str, ids))+')') + cr.execute('select max(date_start),max(date_close) from project_task where id in %s',(tuple(ids),)) res = cr.fetchone() datas['date_stop'] = (res[0] and res[0][:10]) or time.strftime('%Y-%m-%d') if res[1] and datas['date_stop'] Date: Mon, 23 Nov 2009 17:54:50 +0530 Subject: [PATCH 04/53] [IMP]:wiki module sql queries to parameterized query bzr revid: nch@tinyerp.com-20091123122450-0s2w9g3gj6dzaahs --- addons/wiki/wizard/make_index.py | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/addons/wiki/wizard/make_index.py b/addons/wiki/wizard/make_index.py index b64e6117824..aa408377ca3 100644 --- a/addons/wiki/wizard/make_index.py +++ b/addons/wiki/wizard/make_index.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 . # ############################################################################## @@ -34,10 +34,7 @@ def wiki_do_index(self, cr, uid, data, context): ids = data['ids'] pool = pooler.get_pool(cr.dbname) wiki_pool = pool.get('wiki.wiki') - - iid = ','.join([str(x) for x in ids]) - sSQL = "Select id, section from wiki_wiki where id in (%s) order by section " % (iid) - cr.execute(sSQL) + cr.execute("Select id, section from wiki_wiki where id in %s order by section " ,(tuple(ids),)) lst0 = cr.fetchall() lst = [] ids = {} @@ -52,9 +49,9 @@ def wiki_do_index(self, cr, uid, data, context): return int(x) except: return 1 - + lst = map(lambda x: map(toint, x.split('.')), lst) - + result = [] current = ['0'] current2 = [] @@ -69,7 +66,7 @@ def wiki_do_index(self, cr, uid, data, context): current = current[:pos + 1] if pos == len(l) - 1: break - + key = ('.'.join([str(x) for x in l])) id = ids[key] val = ('.'.join([str(x) for x in current[:]]), id) @@ -77,22 +74,21 @@ def wiki_do_index(self, cr, uid, data, context): if val: result.append(val) current2 = l - + for rs in result: wiki_pool.write(cr, uid, [rs[1]], {'section':rs[0]}) - return {} class make_index(wizard.interface): states = { 'init': { - 'actions': [], + 'actions': [], 'result': {'type':'form', 'arch':section_form, 'fields':{}, 'state':[('end','Cancel'),('yes','Create Index')]} }, 'yes': { - 'actions': [wiki_do_index], + 'actions': [wiki_do_index], 'result': { - 'type':'state', + 'type':'state', 'state':'end' } } From 43288159c28615774c537cc7b63dd298da43dd36 Mon Sep 17 00:00:00 2001 From: "nch@tinyerp.com" <> Date: Mon, 23 Nov 2009 18:26:22 +0530 Subject: [PATCH 05/53] [IMP]:sale.py 'in' to 'ANY' bzr revid: nch@tinyerp.com-20091123125622-k6xkdx29a78pebb7 --- addons/sale/sale.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/sale/sale.py b/addons/sale/sale.py index 4119e393174..5d2c739909f 100644 --- a/addons/sale/sale.py +++ b/addons/sale/sale.py @@ -99,7 +99,7 @@ class sale_order(osv.osv): LEFT JOIN stock_picking p on (p.id=m.picking_id) WHERE - p.sale_id in %s GROUP BY m.state, p.sale_id''',(tuple(ids),)) + p.sale_id = ANY(%s) GROUP BY m.state, p.sale_id''',(ids,)) for oid, nbr, state in cr.fetchall(): if state == 'cancel': continue @@ -294,7 +294,7 @@ class sale_order(osv.osv): def action_cancel_draft(self, cr, uid, ids, *args): if not len(ids): return False - cr.execute('select id from sale_order_line where order_id in %s and state=%s',(tuple(ids),'cancel')) + cr.execute('select id from sale_order_line where order_id = ANY(%s) and state=%s',(ids,'cancel')) line_ids = map(lambda x: x[0], cr.fetchall()) self.write(cr, uid, ids, {'state': 'draft', 'invoice_ids': [], 'shipped': 0}) self.pool.get('sale.order.line').write(cr, uid, line_ids, {'invoiced': False, 'state': 'draft', 'invoice_lines': [(6, 0, [])]}) From e3cdb73b4bdb7885dc9feff0c467ee07ca5f5297 Mon Sep 17 00:00:00 2001 From: "nch@tinyerp.com" <> Date: Mon, 23 Nov 2009 18:33:26 +0530 Subject: [PATCH 06/53] [IMP]:purchase 'in' to 'ANY' bzr revid: nch@tinyerp.com-20091123130326-22dcsx0c2ce00pkm --- addons/purchase/purchase.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/purchase/purchase.py b/addons/purchase/purchase.py index 32889e20f57..8c1eae38239 100644 --- a/addons/purchase/purchase.py +++ b/addons/purchase/purchase.py @@ -111,7 +111,7 @@ class purchase_order(osv.osv): LEFT JOIN stock_picking p on (p.id=m.picking_id) WHERE - p.purchase_id in %s GROUP BY m.state, p.purchase_id''',(tuple(ids),)) + p.purchase_id = ANY(%s) GROUP BY m.state, p.purchase_id''',(ids,)) for oid,nbr,state in cr.fetchall(): if state=='cancel': continue From 9565e0506712e4490ffc654af46544d6b61db58b Mon Sep 17 00:00:00 2001 From: "nch@tinyerp.com" <> Date: Mon, 23 Nov 2009 18:44:01 +0530 Subject: [PATCH 07/53] [IMP]:scrum 'in' to 'ANY' bzr revid: nch@tinyerp.com-20091123131401-gke5m4cq7ccxziqe --- addons/scrum/report/_burndown.py | 6 +++--- addons/scrum/report/task_burndown.py | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/addons/scrum/report/_burndown.py b/addons/scrum/report/_burndown.py index fc7b60437ae..c4e8e67fc91 100644 --- a/addons/scrum/report/_burndown.py +++ b/addons/scrum/report/_burndown.py @@ -26,13 +26,13 @@ import time def compute_burndown(cr, uid, tasks_id, date_start, date_stop): latest = False if len(tasks_id): - cr.execute('select id,create_date,state,planned_hours from project_task where id in %s order by create_date',(tuple(tasks_id),)) + cr.execute('select id,create_date,state,planned_hours from project_task where id = ANY(%s) order by create_date',(tasks_id,)) tasks = cr.fetchall() - cr.execute('select w.date,w.hours from project_task_work w left join project_task t on (t.id=w.task_id) where t.id in %s and t.state in (%s,%s) order by date',(tuple(tasks_id),'open','progress',)) + cr.execute('select w.date,w.hours from project_task_work w left join project_task t on (t.id=w.task_id) where t.id = ANY(%s) and t.state in (%s,%s) order by date',(tasks_id,'open','progress',)) tasks2 = cr.fetchall() - cr.execute('select date_close,planned_hours from project_task where id in %s and state in (%s,%s) order by date_close' ,(tuple(tasks_id),'cancelled','done',)) + cr.execute('select date_close,planned_hours from project_task where id =ANY(%s) and state in (%s,%s) order by date_close' ,(tasks_id,'cancelled','done',)) tasks2 += cr.fetchall() tasks2.sort() else: diff --git a/addons/scrum/report/task_burndown.py b/addons/scrum/report/task_burndown.py index b4c6481ce48..668a746231f 100644 --- a/addons/scrum/report/task_burndown.py +++ b/addons/scrum/report/task_burndown.py @@ -43,9 +43,9 @@ class external_pdf(render): def burndown_chart(cr, uid, tasks_id, date_start, date_stop): latest = False - cr.execute('select id,date_start,state,planned_hours from project_task where id in %s order by date_start'(tuple(tasks_id),)) + cr.execute('select id,date_start,state,planned_hours from project_task where id = ANY(%s) order by date_start'(tasks_id,)) tasks = cr.fetchall() - cr.execute('select id,date_close,state,planned_hours*progress/100 from project_task where id in %s and state in (%s,%s) order by date_close', (tuple(tasks_id),'progress','done',)) + cr.execute('select id,date_close,state,planned_hours*progress/100 from project_task where id =ANY(%s) and state in (%s,%s) order by date_close', (tasks_id,'progress','done',)) tasks2 = cr.fetchall() current_date = date_start total = 0 @@ -72,14 +72,14 @@ class report_tasks(report_int): io = StringIO.StringIO() if 'date_start' not in datas: - cr.execute('select min(date_start) from project_task where id in %s',(tuple(ids),)) + cr.execute('select min(date_start) from project_task where id = ANY(%s)',(ids,)) dt = cr.fetchone()[0] if dt: datas['date_start'] = dt[:10] else: datas['date_start'] = time.strftime('%Y-%m-%d') if 'date_stop' not in datas: - cr.execute('select max(date_start),max(date_close) from project_task where id in %s',(tuple(ids),)) + cr.execute('select max(date_start),max(date_close) from project_task where id = ANY(%s)',(ids,)) res = cr.fetchone() datas['date_stop'] = (res[0] and res[0][:10]) or time.strftime('%Y-%m-%d') if res[1] and datas['date_stop'] Date: Mon, 23 Nov 2009 18:47:35 +0530 Subject: [PATCH 08/53] [IMP]:wiki 'in' to 'ANY' bzr revid: nch@tinyerp.com-20091123131735-mcsxnr7jj27b93k7 --- addons/wiki/wizard/make_index.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/wiki/wizard/make_index.py b/addons/wiki/wizard/make_index.py index aa408377ca3..b37374177e4 100644 --- a/addons/wiki/wizard/make_index.py +++ b/addons/wiki/wizard/make_index.py @@ -34,7 +34,7 @@ def wiki_do_index(self, cr, uid, data, context): ids = data['ids'] pool = pooler.get_pool(cr.dbname) wiki_pool = pool.get('wiki.wiki') - cr.execute("Select id, section from wiki_wiki where id in %s order by section " ,(tuple(ids),)) + cr.execute("Select id, section from wiki_wiki where id = ANY(%s) order by section " ,(ids,)) lst0 = cr.fetchall() lst = [] ids = {} From 8bd969b134fdd91d0616fe6798e2a53b375a9dfa Mon Sep 17 00:00:00 2001 From: "nch@tinyerp.com" <> Date: Tue, 24 Nov 2009 14:36:10 +0530 Subject: [PATCH 09/53] [IMP]:stock module sql queries to parameterized query bzr revid: nch@tinyerp.com-20091124090610-uin098njqilg9wpe --- addons/stock/product.py | 24 +++++++--------- addons/stock/report/product_stock.py | 28 +++++++----------- addons/stock/stock.py | 32 ++++++++------------- addons/stock/wizard/inventory_merge_zero.py | 6 ++-- 4 files changed, 36 insertions(+), 54 deletions(-) diff --git a/addons/stock/product.py b/addons/stock/product.py index 242f7519a5e..def19749503 100644 --- a/addons/stock/product.py +++ b/addons/stock/product.py @@ -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') diff --git a/addons/stock/report/product_stock.py b/addons/stock/report/product_stock.py index e8ee007b173..19742c86786 100644 --- a/addons/stock/report/product_stock.py +++ b/addons/stock/report/product_stock.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 . # ############################################################################## @@ -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: diff --git a/addons/stock/stock.py b/addons/stock/stock.py index 0128fb0a2ed..4ab0e11fe50 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.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 . # ############################################################################## @@ -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 diff --git a/addons/stock/wizard/inventory_merge_zero.py b/addons/stock/wizard/inventory_merge_zero.py index 76091b3a77a..11cc99daf30 100644 --- a/addons/stock/wizard/inventory_merge_zero.py +++ b/addons/stock/wizard/inventory_merge_zero.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 . # ############################################################################## @@ -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: From a90ddbe855ff3ee2919709733becae40769dd276 Mon Sep 17 00:00:00 2001 From: "nch@tinyerp.com" <> Date: Tue, 24 Nov 2009 14:55:48 +0530 Subject: [PATCH 10/53] [IMP]:report_account module sql queries to parameterized query bzr revid: nch@tinyerp.com-20091124092548-exugcm7o1z6ghh7v --- addons/report_account/report_receivable.py | 87 +++++++++++----------- 1 file changed, 43 insertions(+), 44 deletions(-) diff --git a/addons/report_account/report_receivable.py b/addons/report_account/report_receivable.py index 45dc1f5a376..7cf3008c034 100644 --- a/addons/report_account/report_receivable.py +++ b/addons/report_account/report_receivable.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 . # ############################################################################## @@ -46,7 +46,7 @@ class report_account_receivable(osv.osv): 'credit':fields.float('Credit', readonly=True), } _order = 'name desc' - + def init(self, cr): cr.execute(""" create or replace view report_account_receivable as ( @@ -72,55 +72,54 @@ report_account_receivable() class temp_range(osv.osv): _name = 'temp.range' _description = 'A Temporary table used for Dashboard view' - + _columns = { 'name' : fields.char('Range',size=64) } - -temp_range() - + +temp_range() + class report_aged_receivable(osv.osv): _name = "report.aged.receivable" _description = "Aged Receivable Till Today" _auto = False - + def __init__(self, pool, cr): super(report_aged_receivable, self).__init__(pool, cr) self.called = False - + def fields_view_get(self, cr, user, view_id=None, view_type='form', context=None, toolbar=False, submenu=False): """ To call the init() method timely """ if not self.called: self.init(cr, user) self.called = True # To make sure that init doesn't get called multiple times - + res = super(report_aged_receivable, self).fields_view_get(cr, user, view_id, view_type, context, toolbar=toolbar, submenu=submenu) return res - + def _calc_bal(self, cr, uid, ids, name, args, context): res = {} for period in self.read(cr,uid,ids,['name']): date1,date2 = period['name'].split(' to ') - query = "SELECT SUM(credit-debit) FROM account_move_line AS line, account_account as ac \ + cr.execute("SELECT SUM(credit-debit) FROM account_move_line AS line, account_account as ac \ WHERE (line.account_id=ac.id) AND ac.type='receivable' \ - AND (COALESCE(line.date,date) BETWEEN '%s' AND '%s') \ - AND (reconcile_id IS NULL) AND ac.active"%(str(date2),str(date1)) - cr.execute(query) + AND (COALESCE(line.date,date) BETWEEN %s AND %s) \ + AND (reconcile_id IS NULL) AND ac.active",(str(date2),str(date1),)) amount = cr.fetchone() amount = amount[0] or 0.00 res[period['id']] = amount - + return res - + _columns = { 'name': fields.char('Month Range', size=7, readonly=True), 'balance': fields.function(_calc_bal, method=True, string='Balance', readonly=True), } - + def init(self, cr, uid=1): """ This view will be used in dashboard - The reason writing this code here is, we need to check date range from today to first date of fiscal year. + The reason writing this code here is, we need to check date range from today to first date of fiscal year. """ # ranges = _get_ranges(cr) # Gets the ranges for the x axis of the graph (name column values) pool_obj_fy = pooler.get_pool(cr.dbname).get('account.fiscalyear') @@ -136,18 +135,18 @@ class report_aged_receivable(osv.osv): LIST_RANGES.append(today + " to " + last_month_date.strftime('%Y-%m-%d')) today = (last_month_date- 1).strftime('%Y-%m-%d') last_month_date = mx.DateTime.strptime(today, '%Y-%m-%d') - mx.DateTime.RelativeDateTime(months=1) - + LIST_RANGES.append(today +" to " + fy_start_date.strftime('%Y-%m-%d')) cr.execute('delete from temp_range') - + for range in LIST_RANGES: pooler.get_pool(cr.dbname).get('temp.range').create(cr, uid, {'name':range}) - + cr.execute(""" create or replace view report_aged_receivable as ( select id,name from temp_range )""") - + report_aged_receivable() class report_invoice_created(osv.osv): @@ -182,7 +181,7 @@ class report_invoice_created(osv.osv): 'create_date' : fields.datetime('Create Date', readonly=True) } _order = 'create_date' - + def init(self, cr): cr.execute("""create or replace view report_invoice_created as ( select @@ -212,30 +211,30 @@ class report_account_type_sales(osv.osv): 'product_id': fields.many2one('product.product', 'Product',readonly=True), 'quantity': fields.float('Quantity', readonly=True), 'user_type': fields.many2one('account.account.type', 'Account Type', readonly=True), - 'amount_total': fields.float('Total', readonly=True), - 'currency_id': fields.many2one('res.currency', 'Currency', readonly=True), + 'amount_total': fields.float('Total', readonly=True), + 'currency_id': fields.many2one('res.currency', 'Currency', readonly=True), } _order = 'name desc,amount_total desc' - + def init(self, cr): cr.execute("""create or replace view report_account_type_sales as ( select min(inv_line.id) as id, - to_char(inv.date_invoice, 'YYYY-MM-01') as name, - sum(inv_line.price_subtotal) as amount_total, - inv.currency_id as currency_id, + to_char(inv.date_invoice, 'YYYY-MM-01') as name, + sum(inv_line.price_subtotal) as amount_total, + inv.currency_id as currency_id, inv.period_id, - inv_line.product_id, - sum(inv_line.quantity) as quantity, + inv_line.product_id, + sum(inv_line.quantity) as quantity, account.user_type from - account_invoice_line inv_line + account_invoice_line inv_line inner join account_invoice inv on inv.id = inv_line.invoice_id inner join account_account account on account.id = inv_line.account_id where inv.state in ('open','paid') group by - to_char(inv.date_invoice, 'YYYY-MM-01'),inv.currency_id, inv.period_id, inv_line.product_id, account.user_type + to_char(inv.date_invoice, 'YYYY-MM-01'),inv.currency_id, inv.period_id, inv_line.product_id, account.user_type )""") report_account_type_sales() @@ -250,30 +249,30 @@ class report_account_sales(osv.osv): 'product_id': fields.many2one('product.product', 'Product',readonly=True), 'quantity': fields.float('Quantity', readonly=True), 'account_id': fields.many2one('account.account', 'Account', readonly=True), - 'amount_total': fields.float('Total', readonly=True), - 'currency_id': fields.many2one('res.currency', 'Currency', readonly=True), + 'amount_total': fields.float('Total', readonly=True), + 'currency_id': fields.many2one('res.currency', 'Currency', readonly=True), } _order = 'name desc,amount_total desc' - + def init(self, cr): cr.execute("""create or replace view report_account_sales as ( select min(inv_line.id) as id, - to_char(inv.date_invoice, 'YYYY-MM-01') as name, - sum(inv_line.price_subtotal) as amount_total, - inv.currency_id as currency_id, + to_char(inv.date_invoice, 'YYYY-MM-01') as name, + sum(inv_line.price_subtotal) as amount_total, + inv.currency_id as currency_id, inv.period_id, - inv_line.product_id, - sum(inv_line.quantity) as quantity, + inv_line.product_id, + sum(inv_line.quantity) as quantity, account.id as account_id from - account_invoice_line inv_line + account_invoice_line inv_line inner join account_invoice inv on inv.id = inv_line.invoice_id inner join account_account account on account.id = inv_line.account_id where inv.state in ('open','paid') group by - to_char(inv.date_invoice, 'YYYY-MM-01'),inv.currency_id, inv.period_id, inv_line.product_id, account.id + to_char(inv.date_invoice, 'YYYY-MM-01'),inv.currency_id, inv.period_id, inv_line.product_id, account.id )""") report_account_sales() From 046e2aff3e5a804992bea5153d605dea35fef432 Mon Sep 17 00:00:00 2001 From: "nch@tinyerp.com" <> Date: Tue, 24 Nov 2009 15:35:29 +0530 Subject: [PATCH 11/53] [IMP]:report_analytic_planning module sql queries to parameterized query bzr revid: nch@tinyerp.com-20091124100529-q5t3i69can2moe3v --- .../report_analytic_planning.py | 240 +++++++++--------- 1 file changed, 120 insertions(+), 120 deletions(-) diff --git a/addons/report_analytic_planning/report_analytic_planning.py b/addons/report_analytic_planning/report_analytic_planning.py index 509f2250f85..917352ecaa7 100644 --- a/addons/report_analytic_planning/report_analytic_planning.py +++ b/addons/report_analytic_planning/report_analytic_planning.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- ############################################################################## # -# OpenERP, Open Source Management Solution +# OpenERP, Open Source Management Solution # Copyright (C) 2004-2009 Tiny SPRL (). All Rights Reserved # $Id$ # @@ -16,7 +16,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 . # ############################################################################## @@ -47,7 +47,7 @@ class one2many_mod3(fields.one2many): class report_account_analytic_planning(osv.osv): _name = "report_account_analytic.planning" _description = "Planning" - + def _get_total_planned(self, cr, uid, ids, name, args, context): result = {} for plan in self.browse(cr, uid, ids, context): @@ -58,7 +58,7 @@ class report_account_analytic_planning(osv.osv): plan_hrs = plan_hrs + p.plan_open + p.plan_tasks result[plan.id] = plan_hrs return result - + def _get_total_free(self, cr, uid, ids, name, args, context): result = {} for plan in self.browse(cr, uid, ids, context): @@ -68,15 +68,15 @@ class report_account_analytic_planning(osv.osv): total_free = total_free + p.free result[plan.id] = total_free return result - + def _check_planning_responsible(self, cr, uid, ids, context={}): for obj_plan in self.browse(cr,uid,ids): cr.execute(""" - SELECT id FROM report_account_analytic_planning plan + SELECT id FROM report_account_analytic_planning plan WHERE ( (%(date_from)s BETWEEN date_from AND date_to) OR (%(date_to)s BETWEEN date_from AND date_to) OR (%(date_from)s < date_from AND %(date_to)s > date_to) - ) AND user_id = %(uid)s AND id <> %(id)s""", + ) AND user_id = %(uid)s AND id <> %(id)s""", {"date_from": obj_plan.date_from, "date_to": obj_plan.date_to, "uid": obj_plan.user_id.id, @@ -87,31 +87,31 @@ class report_account_analytic_planning(osv.osv): if res: return False return True - + _columns = { - 'name': fields.char('Planning Name', required=True, size=32, states={'done':[('readonly', True)]}), - 'code': fields.char('Code', size=32, states={'done':[('readonly', True)]}), - 'user_id': fields.many2one('res.users', 'Responsible', required=True, states={'done':[('readonly', True)]}), - 'date_from':fields.date('Start Date', required=True, states={'done':[('readonly', True)]}), - 'date_to':fields.date('End Date', required=True, states={'done':[('readonly', True)]}), - 'line_ids': fields.one2many('report_account_analytic.planning.line', 'planning_id', 'Planning lines', states={'done':[('readonly', True)]}), - 'stat_ids': fields.one2many('report_account_analytic.planning.stat', 'planning_id', 'Planning analysis', readonly=True), - 'state': fields.selection([('draft','Draft'),('open', 'Open'), ('done', 'Done'),('cancel','Cancelled')], 'Status', required=True), + 'name': fields.char('Planning Name', required=True, size=32, states={'done':[('readonly', True)]}), + 'code': fields.char('Code', size=32, states={'done':[('readonly', True)]}), + 'user_id': fields.many2one('res.users', 'Responsible', required=True, states={'done':[('readonly', True)]}), + 'date_from':fields.date('Start Date', required=True, states={'done':[('readonly', True)]}), + 'date_to':fields.date('End Date', required=True, states={'done':[('readonly', True)]}), + 'line_ids': fields.one2many('report_account_analytic.planning.line', 'planning_id', 'Planning lines', states={'done':[('readonly', True)]}), + 'stat_ids': fields.one2many('report_account_analytic.planning.stat', 'planning_id', 'Planning analysis', readonly=True), + 'state': fields.selection([('draft','Draft'),('open', 'Open'), ('done', 'Done'),('cancel','Cancelled')], 'Status', required=True), 'business_days' : fields.integer('Business Days', required=True, states={'done':[('readonly', True)]}, help='Set here the number of working days within this planning for one person full time'), 'planning_user_ids': one2many_mod3('report_account_analytic.planning.user', 'planning_id', 'Planning By User'), - 'planning_account': fields.one2many('report_account_analytic.planning.account', 'planning_id', 'Planning By Account'), - 'total_planned' : fields.function(_get_total_planned, method=True, string='Total Planned'), + 'planning_account': fields.one2many('report_account_analytic.planning.account', 'planning_id', 'Planning By Account'), + 'total_planned' : fields.function(_get_total_planned, method=True, string='Total Planned'), 'total_free' : fields.function(_get_total_free, method=True, string='Total Free'), } _defaults = { - 'date_from': lambda *a: time.strftime('%Y-%m-01'), - 'date_to': lambda *a: (mx.DateTime.now()+mx.DateTime.RelativeDateTime(months=1, day=1, days=-1)).strftime('%Y-%m-%d'), - 'user_id': lambda self, cr, uid, c: uid, - 'state': lambda *args: 'draft', - 'business_days' : lambda *a: 20, + 'date_from': lambda *a: time.strftime('%Y-%m-01'), + 'date_to': lambda *a: (mx.DateTime.now()+mx.DateTime.RelativeDateTime(months=1, day=1, days=-1)).strftime('%Y-%m-%d'), + 'user_id': lambda self, cr, uid, c: uid, + 'state': lambda *args: 'draft', + 'business_days' : lambda *a: 20, } _order = 'date_from desc' - + _constraints = [ (_check_planning_responsible, 'Invalid planning ! Planning dates can\'t overlap for the same responsible. ', ['user_id']) ] @@ -123,15 +123,15 @@ class report_account_analytic_planning(osv.osv): def action_cancel(self, cr, uid, id, context={}): self.write(cr, uid, id, {'state' : 'cancel'}) return True - + def action_draft(self, cr, uid, id, context={}): self.write(cr, uid, id, {'state' : 'draft'}) return True - + def action_done(self, cr, uid, id, context={}): self.write(cr, uid, id, {'state' : 'done'}) return True - + report_account_analytic_planning() class report_account_analytic_planning_line(osv.osv): @@ -167,17 +167,17 @@ class report_account_analytic_planning_line(osv.osv): return result _columns = { - 'account_id':fields.many2one('account.analytic.account', 'Analytic account', required=True), - 'planning_id': fields.many2one('report_account_analytic.planning', 'Planning', required=True, ondelete='cascade'), - 'user_id': fields.many2one('res.users', 'User'), - 'amount': fields.float('Quantity', required=True), - 'amount_unit': fields.many2one('product.uom', 'Qty UoM', required=True), - 'note': fields.text('Note', size=64), + 'account_id':fields.many2one('account.analytic.account', 'Analytic account', required=True), + 'planning_id': fields.many2one('report_account_analytic.planning', 'Planning', required=True, ondelete='cascade'), + 'user_id': fields.many2one('res.users', 'User'), + 'amount': fields.float('Quantity', required=True), + 'amount_unit': fields.many2one('product.uom', 'Qty UoM', required=True), + 'note': fields.text('Note', size=64), 'amount_in_base_uom': fields.function(_amount_base_uom, method=True, string='Quantity in base uom', store=True), - 'task_ids': fields.one2many('project.task', 'planning_line_id', 'Planning Tasks'), + 'task_ids': fields.one2many('project.task', 'planning_line_id', 'Planning Tasks'), } _order = 'user_id,account_id' - + report_account_analytic_planning_line() class account_analytic_account(osv.osv): @@ -187,26 +187,26 @@ class account_analytic_account(osv.osv): _columns = { 'planning_ids': fields.one2many('report_account_analytic.planning.line', 'account_id', 'Plannings'), } - + account_analytic_account() - + class project_task(osv.osv): _name = "project.task" _inherit = "project.task" _columns = { - 'planning_line_id': fields.many2one('report_account_analytic.planning.line', 'Planning', ondelete='cascade'), + 'planning_line_id': fields.many2one('report_account_analytic.planning.line', 'Planning', ondelete='cascade'), } - + def search(self, cr, user, args, offset=0, limit=None, order=None, context=None, count=False): if not context.get('planning'): return super(project_task,self).search(cr, user, args, offset, limit, order, context) cr.execute(" SELECT t.id, t.name \ from project_task t \ join report_account_analytic_planning_line l on (l.id = t.planning_line_id )\ - where l.planning_id=%s" % context.get('planning')) + where l.planning_id=%s",(context.get('planning'),)) ids = map(lambda x: x[0], cr.fetchall()) return ids - + project_task() @@ -215,8 +215,8 @@ class report_account_analytic_planning_user(osv.osv): _description = "Planning by User" _rec_name = 'user_id' _auto = False - - + + def _get_tasks(self, cr, uid, ids, name, args, context): result = {} tm = self.pool.get('res.users').browse(cr, uid, uid, context).company_id.project_time_mode_id @@ -234,7 +234,7 @@ class report_account_analytic_planning_user(osv.osv): cr.execute("""select COALESCE(sum(tasks.remaining_hours),0) from project_task tasks \ where tasks.planning_line_id in (select id from report_account_analytic_planning_line\ where planning_id = %s and user_id=%s)""", (line.planning_id.id, line.user_id.id,)) - + result[line.id] = cr.fetchall()[0][0] / div * div2 else: result[line.id] = 0 @@ -244,11 +244,11 @@ class report_account_analytic_planning_user(osv.osv): result = {} for line in self.browse(cr, uid, ids, context): if line.user_id: - result[line.id] = line.planning_id.business_days - line.plan_tasks - line.plan_open - line.holiday + result[line.id] = line.planning_id.business_days - line.plan_tasks - line.plan_open - line.holiday else: result[line.id] = 0.0 return result - + def _get_timesheets(self, cr, uid, ids, name, args, context): result = {} tm2 = self.pool.get('res.users').browse(cr, uid, uid, context).company_id.planning_time_mode_id @@ -259,7 +259,7 @@ class report_account_analytic_planning_user(osv.osv): for line in self.browse(cr, uid, ids, context): if line.user_id: cr.execute(""" - SELECT sum(unit_amount/uom.factor) FROM account_analytic_line acc + SELECT sum(unit_amount/uom.factor) FROM account_analytic_line acc LEFT JOIN product_uom uom ON (uom.id = acc.product_uom_id) WHERE acc.date>=%s and acc.date<=%s and acc.user_id=%s""", (line.planning_id.date_from, line.planning_id.date_to, line.user_id.id )) res = cr.fetchall() @@ -269,54 +269,54 @@ class report_account_analytic_planning_user(osv.osv): return result _columns = { - 'planning_id': fields.many2one('report_account_analytic.planning', 'Planning'), - 'user_id': fields.many2one('res.users', 'User', readonly=True), - 'tasks' : fields.function(_get_tasks, method=True, string='Remaining Tasks', help='This value is given by the sum of work remaining to do on the task for this planning, expressed in days.'), - 'plan_tasks': fields.float('Time Planned on Tasks', readonly=True, help='This value is given by the sum of time allocation with task(s) linked, expressed in days.'), + 'planning_id': fields.many2one('report_account_analytic.planning', 'Planning'), + 'user_id': fields.many2one('res.users', 'User', readonly=True), + 'tasks' : fields.function(_get_tasks, method=True, string='Remaining Tasks', help='This value is given by the sum of work remaining to do on the task for this planning, expressed in days.'), + 'plan_tasks': fields.float('Time Planned on Tasks', readonly=True, help='This value is given by the sum of time allocation with task(s) linked, expressed in days.'), 'free' : fields.function(_get_free, method=True, string='Unallocated Time', readonly=True,help='Computed as \ -Business Days - (Time Allocation of Tasks + Time Allocation without Tasks + Holiday Leaves)'), - 'plan_open': fields.float('Time Allocation without Tasks', readonly=True,help='This value is given by the sum of time allocation without task(s) linked, expressed in days.'), - 'holiday': fields.float('Leaves',help='This value is given by the total of validated leaves into the \'Date From\' and \'Date To\' of the planning.'), - 'timesheet': fields.function(_get_timesheets, method=True, string='Timesheet', help='This value is given by the sum of all work encoded in the timesheet(s) between the \'Date From\' and \'Date To\' of the planning.'), +Business Days - (Time Allocation of Tasks + Time Allocation without Tasks + Holiday Leaves)'), + 'plan_open': fields.float('Time Allocation without Tasks', readonly=True,help='This value is given by the sum of time allocation without task(s) linked, expressed in days.'), + 'holiday': fields.float('Leaves',help='This value is given by the total of validated leaves into the \'Date From\' and \'Date To\' of the planning.'), + 'timesheet': fields.function(_get_timesheets, method=True, string='Timesheet', help='This value is given by the sum of all work encoded in the timesheet(s) between the \'Date From\' and \'Date To\' of the planning.'), } - + def init(self, cr): cr.execute(""" CREATE OR REPLACE VIEW report_account_analytic_planning_user AS ( - SELECT + SELECT planning.id AS planning_id, planning.id::varchar(32) || '-' || COALESCE(users.id,0)::varchar(32) AS id, planning.business_days, users.id AS user_id, - (SELECT sum(line1.amount_in_base_uom) + (SELECT sum(line1.amount_in_base_uom) FROM report_account_analytic_planning_line line1 WHERE ( - SELECT COUNT(1) - FROM project_task task + SELECT COUNT(1) + FROM project_task task WHERE task.planning_line_id = line1.id - ) > 0 - AND line1.user_id = users.id + ) > 0 + AND line1.user_id = users.id AND line1.planning_id = planning.id )AS plan_tasks, - (SELECT SUM(line1.amount_in_base_uom) + (SELECT SUM(line1.amount_in_base_uom) FROM report_account_analytic_planning_line line1 WHERE ( - SELECT COUNT(1) - FROM project_task task + SELECT COUNT(1) + FROM project_task task WHERE task.planning_line_id = line1.id - ) = 0 - AND line1.user_id = users.id + ) = 0 + AND line1.user_id = users.id AND line1.planning_id = planning.id ) AS plan_open, (SELECT -(SUM(holidays.number_of_days)) - FROM hr_holidays holidays - WHERE holidays.employee_id IN + FROM hr_holidays holidays + WHERE holidays.employee_id IN ( - SELECT emp.id - FROM hr_employee emp WHERE emp.user_id = users.id + SELECT emp.id + FROM hr_employee emp WHERE emp.user_id = users.id ) AND holidays.state IN ('validate') - AND holidays.type = 'remove' - AND holidays.date_from >= planning.date_from + AND holidays.type = 'remove' + AND holidays.date_from >= planning.date_from AND holidays.date_to <= planning.date_to ) AS holiday @@ -331,32 +331,32 @@ Business Days - (Time Allocation of Tasks + Time Allocation without Tasks + Holi planning.id::varchar(32) || '-' || '0' AS id, planning.business_days, line.user_id, - (SELECT SUM(line1.amount_in_base_uom) + (SELECT SUM(line1.amount_in_base_uom) FROM report_account_analytic_planning_line line1 - WHERE (SELECT COUNT(1) FROM project_task task WHERE task.planning_line_id = line1.id) > 0 + WHERE (SELECT COUNT(1) FROM project_task task WHERE task.planning_line_id = line1.id) > 0 AND line1.user_id IS NULL ) AS plan_tasks, - (SELECT SUM(line1.amount_in_base_uom) + (SELECT SUM(line1.amount_in_base_uom) FROM report_account_analytic_planning_line line1 - WHERE (SELECT COUNT(1) FROM project_task task WHERE task.planning_line_id = line1.id) = 0 + WHERE (SELECT COUNT(1) FROM project_task task WHERE task.planning_line_id = line1.id) = 0 AND line1.user_id IS NULL ) AS plan_open, '0' AS holiday - FROM report_account_analytic_planning planning - INNER JOIN report_account_analytic_planning_line line ON line.planning_id = planning.id + FROM report_account_analytic_planning planning + INNER JOIN report_account_analytic_planning_line line ON line.planning_id = planning.id AND line.user_id IS NULL GROUP BY planning.id, planning.business_days, line.user_id, planning.date_from, planning.date_to ) """) report_account_analytic_planning_user() - + class report_account_analytic_planning_account(osv.osv): _name = "report_account_analytic.planning.account" _description = "Planning by Account" _rec_name = 'account_id' _auto = False - + def _get_tasks(self, cr, uid, ids, name, args, context): result = {} tm = self.pool.get('res.users').browse(cr, uid, uid, context).company_id.project_time_mode_id @@ -371,16 +371,16 @@ class report_account_analytic_planning_account(osv.osv): div2 = 1.0 for line in self.browse(cr, uid, ids, context): cr.execute(""" - SELECT COALESCE(sum(tasks.remaining_hours),0) - FROM project_task tasks + SELECT COALESCE(sum(tasks.remaining_hours),0) + FROM project_task tasks WHERE tasks.planning_line_id IN ( - SELECT id + SELECT id FROM report_account_analytic_planning_line WHERE planning_id = %s AND account_id=%s )""", (line.planning_id.id,line.account_id.id )) result[line.id] = cr.fetchall()[0][0] / div *div2 return result - + def _get_timesheets(self, cr, uid, ids, name, args, context): result = {} tm2 = self.pool.get('res.users').browse(cr, uid, uid, context).company_id.planning_time_mode_id @@ -390,7 +390,7 @@ class report_account_analytic_planning_account(osv.osv): div2 = 1.0 for line in self.browse(cr, uid, ids, context): cr.execute(""" - SELECT SUM(unit_amount/uom.factor) FROM account_analytic_line acc + SELECT SUM(unit_amount/uom.factor) FROM account_analytic_line acc LEFT JOIN product_uom uom ON (uom.id = acc.product_uom_id) WHERE acc.date>=%s and acc.date<=%s and acc.account_id=%s""", (line.planning_id.date_from, line.planning_id.date_to, line.account_id.id, )) res = cr.fetchall()[0][0] @@ -401,38 +401,38 @@ class report_account_analytic_planning_account(osv.osv): return result _columns = { - 'planning_id': fields.many2one('report_account_analytic.planning', 'Planning'), - 'account_id': fields.many2one('account.analytic.account', 'Analytic account', readonly=True), - 'tasks' : fields.function(_get_tasks, method=True, string='Remaining Tasks', help='This value is given by the sum of work remaining to do on the task for this planning, expressed in days.'), - 'plan_tasks': fields.float('Time Allocation of Tasks', readonly=True,help='This value is given by the sum of time allocation with the checkbox \'Assigned in Taks\' set to TRUE expressed in days.'), - 'plan_open': fields.float('Time Allocation without Tasks', readonly=True,help='This value is given by the sum of time allocation with the checkbox \'Assigned in Taks\' set to FALSE, expressed in days.'), - 'timesheet': fields.function(_get_timesheets, method=True, string='Timesheet',help='This value is given by the sum of all work encoded in the timesheet(s) between the \'Date From\' and \'Date To\' of the planning.'), + 'planning_id': fields.many2one('report_account_analytic.planning', 'Planning'), + 'account_id': fields.many2one('account.analytic.account', 'Analytic account', readonly=True), + 'tasks' : fields.function(_get_tasks, method=True, string='Remaining Tasks', help='This value is given by the sum of work remaining to do on the task for this planning, expressed in days.'), + 'plan_tasks': fields.float('Time Allocation of Tasks', readonly=True,help='This value is given by the sum of time allocation with the checkbox \'Assigned in Taks\' set to TRUE expressed in days.'), + 'plan_open': fields.float('Time Allocation without Tasks', readonly=True,help='This value is given by the sum of time allocation with the checkbox \'Assigned in Taks\' set to FALSE, expressed in days.'), + 'timesheet': fields.function(_get_timesheets, method=True, string='Timesheet',help='This value is given by the sum of all work encoded in the timesheet(s) between the \'Date From\' and \'Date To\' of the planning.'), } - + def init(self, cr): cr.execute(""" CREATE OR REPLACE VIEW report_account_analytic_planning_account AS ( - SELECT + SELECT MIN(l.id) AS id, l.account_id AS account_id, SUM(l.amount) AS quantity, l.planning_id AS planning_id, - ( SELECT SUM(line1.amount_in_base_uom) + ( SELECT SUM(line1.amount_in_base_uom) FROM report_account_analytic_planning_line line1 - WHERE - ( SELECT COUNT(1) - FROM project_task task + WHERE + ( SELECT COUNT(1) + FROM project_task task WHERE task.planning_line_id = line1.id - ) > 0 + ) > 0 AND l.account_id = line1.account_id AND l.planning_id = line1.planning_id ) AS plan_tasks, - ( SELECT SUM(line1.amount_in_base_uom) + ( SELECT SUM(line1.amount_in_base_uom) FROM report_account_analytic_planning_line line1 - WHERE - ( SELECT COUNT(1) - FROM project_task task + WHERE + ( SELECT COUNT(1) + FROM project_task task WHERE task.planning_line_id = line1.id - ) = 0 + ) = 0 AND l.account_id = line1.account_id AND planning.id = line1.planning_id ) AS plan_open @@ -441,8 +441,8 @@ class report_account_analytic_planning_account(osv.osv): GROUP BY l.account_id, l.planning_id, planning.date_from, planning.date_to, planning.id ) """) - - + + report_account_analytic_planning_account() class report_account_analytic_planning_stat(osv.osv): @@ -452,7 +452,7 @@ class report_account_analytic_planning_stat(osv.osv): _auto = False _log_access = False _order = 'planning_id,user_id' - + def _sum_amount_real(self, cr, uid, ids, name, args, context): result = {} tm2 = self.pool.get('res.users').browse(cr, uid, uid, context).company_id.planning_time_mode_id @@ -469,7 +469,7 @@ where user_id=%s and account_id=%s and date>=%s and date<=%s''', (line.user_id.i cr.execute('select sum(unit_amount) from account_analytic_line where account_id=%s and date>=%s and date<=%s', (line.account_id.id, line.planning_id.date_from, line.planning_id.date_to)) result[line.id] = cr.fetchone()[0] * div2 return result - + def _sum_amount_tasks(self, cr, uid, ids, name, args, context): result = {} tm = self.pool.get('res.users').browse(cr, uid, uid, context).company_id.project_time_mode_id @@ -495,23 +495,23 @@ where user_id=%s and account_id=%s and date>=%s and date<=%s''', (line.user_id.i project_id in (select id from project_project where category_id=%s) and date_close>=%s and date_close<=%s''', ( - line.account_id.id, - line.planning_id.date_from, + line.account_id.id, + line.planning_id.date_from, line.planning_id.date_to) ) result[line.id] = cr.fetchone()[0] /div * div2 return result - + _columns = { - 'planning_id': fields.many2one('report_account_analytic.planning', 'Planning'), - 'user_id': fields.many2one('res.users', 'User'), - 'manager_id': fields.many2one('res.users', 'Manager'), - 'account_id': fields.many2one('account.analytic.account', 'Account', required=True), - 'sum_amount': fields.float('Planned Days', required=True), - 'sum_amount_real': fields.function(_sum_amount_real, method=True, string='Timesheet'), - 'sum_amount_tasks': fields.function(_sum_amount_tasks, method=True, string='Tasks'), + 'planning_id': fields.many2one('report_account_analytic.planning', 'Planning'), + 'user_id': fields.many2one('res.users', 'User'), + 'manager_id': fields.many2one('res.users', 'Manager'), + 'account_id': fields.many2one('account.analytic.account', 'Account', required=True), + 'sum_amount': fields.float('Planned Days', required=True), + 'sum_amount_real': fields.function(_sum_amount_real, method=True, string='Timesheet'), + 'sum_amount_tasks': fields.function(_sum_amount_tasks, method=True, string='Tasks'), } - + def init(self, cr): cr.execute(""" create or replace view report_account_analytic_planning_stat as ( @@ -539,7 +539,7 @@ class res_company(osv.osv): _columns = { 'planning_time_mode_id': fields.many2one('product.uom', 'Planning Time Unit', help='This will set the unit of measure used in plannings.', - + ), } res_company() From e5f2d0041d605afa2ec916b20663edb7043ba25c Mon Sep 17 00:00:00 2001 From: "nch@tinyerp.com" <> Date: Tue, 24 Nov 2009 15:50:21 +0530 Subject: [PATCH 12/53] [IMP]:report_crm module sql queries to parameterized query bzr revid: nch@tinyerp.com-20091124102021-oppe84lus8s0fxuz --- addons/report_crm/report_crm.py | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/addons/report_crm/report_crm.py b/addons/report_crm/report_crm.py index df133b53b4f..92a80e4d0fc 100644 --- a/addons/report_crm/report_crm.py +++ b/addons/report_crm/report_crm.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 . # ############################################################################## @@ -110,29 +110,28 @@ class report_crm_case_section(osv.osv): _name = "report.crm.case.section" _description = "Cases by Section" _auto = False - + def _get_data(self, cr, uid, ids, field_name, arg, context={}): res = {} state_perc = 0.0 avg_ans = 0.0 - + for case in self.browse(cr, uid, ids, context): if field_name != 'avg_answers': state = field_name[5:] - cr.execute("select count(*) from crm_case where section_id =%s and state='%s'"%(case.section_id.id,state)) + cr.execute("select count(*) from crm_case where section_id =%s and state=%s",(case.section_id.id,state,)) state_cases = cr.fetchone()[0] perc_state = (state_cases / float(case.nbr_cases) ) * 100 - res[case.id] = perc_state else: - cr.execute('select count(*) from crm_case_log l where l.section_id=%s'%(case.section_id.id)) + cr.execute('select count(*) from crm_case_log l where l.section_id=%s',(case.section_id.id,)) logs = cr.fetchone()[0] - + avg_ans = logs / case.nbr_cases - res[case.id] = avg_ans - + res[case.id] = avg_ans + return res - + _columns = { 'name': fields.date('Month', readonly=True), # 'user_id':fields.many2one('res.users', 'User', readonly=True), @@ -180,7 +179,7 @@ class report_crm_case_service_dashboard(osv.osv): 'create_date' : fields.datetime('Create Date', readonly=True) } _order = 'date_closed, create_date' - + def init(self, cr): cr.execute("""create or replace view report_crm_case_service_dashboard as ( select @@ -194,12 +193,12 @@ class report_crm_case_service_dashboard(osv.osv): where ((to_date(to_char(cse.date_closed, 'YYYY-MM-dd'),'YYYY-MM-dd') <= CURRENT_DATE) AND - (to_date(to_char(cse.date_closed, 'YYYY-MM-dd'),'YYYY-MM-dd') > (CURRENT_DATE-15)) + (to_date(to_char(cse.date_closed, 'YYYY-MM-dd'),'YYYY-MM-dd') > (CURRENT_DATE-15)) AND cse.state='done') - + OR - + ((to_date(to_char(cse.create_date, 'YYYY-MM-dd'),'YYYY-MM-dd') <= CURRENT_DATE) AND (to_date(to_char(cse.create_date, 'YYYY-MM-dd'),'YYYY-MM-dd') > (CURRENT_DATE-15)) From 6d4e5f230d6b084efa507b292fc95fe44554c9eb Mon Sep 17 00:00:00 2001 From: "nch@tinyerp.com" <> Date: Tue, 24 Nov 2009 16:26:28 +0530 Subject: [PATCH 13/53] [IMP]:project module sql queries to parameterized query bzr revid: nch@tinyerp.com-20091124105628-tbgbq38isa6jswtz --- addons/project/project.py | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/addons/project/project.py b/addons/project/project.py index 96e86b4153c..3e10595c2ce 100644 --- a/addons/project/project.py +++ b/addons/project/project.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 . # ############################################################################## @@ -61,12 +61,12 @@ class project(osv.osv): cr.execute('''SELECT project_id, sum(planned_hours), sum(total_hours), sum(effective_hours) FROM - project_task + project_task WHERE - project_id in ('''+','.join(map(str,ids2))+''') AND + project_id =ANY(%s) AND state<>'cancelled' GROUP BY - project_id''') + project_id''',(ids2,)) progress = dict(map(lambda x: (x[0], (x[1],x[2],x[3])), cr.fetchall())) for project in self.browse(cr, uid, ids, context=context): s = [0.0,0.0,0.0] @@ -133,7 +133,7 @@ class project(osv.osv): # toggle activity of projects, their sub projects and their tasks def set_template(self, cr, uid, ids, context={}): - res = self.setActive(cr, uid, ids, value=False, context=context) + res = self.setActive(cr, uid, ids, value=False, context=context) return res def set_done(self, cr, uid, ids, context={}): @@ -165,7 +165,7 @@ class project(osv.osv): default['name'] = proj.name+_(' (copy)') res = super(project, self).copy(cr, uid, id, default, context) ids = self.search(cr, uid, [('parent_id','child_of', [res])]) - cr.execute('update project_task set active=True where project_id in ('+','.join(map(str, ids))+')') + cr.execute('update project_task set active=True where project_id =ANY(%s)',(ids,)) return res def duplicate_template(self, cr, uid, ids,context={}): @@ -188,17 +188,17 @@ class project(osv.osv): raise osv.except_osv(_('Operation Done'), _('A new project has been created !\nWe suggest you to close this one and work on this new project.')) # set active value for a project, its sub projects and its tasks - def setActive(self, cr, uid, ids, value=True, context={}): - for proj in self.browse(cr, uid, ids, context): + def setActive(self, cr, uid, ids, value=True, context={}): + for proj in self.browse(cr, uid, ids, context): self.write(cr, uid, [proj.id], {'state': value and 'open' or 'template'}, context) cr.execute('select id from project_task where project_id=%s', (proj.id,)) tasks_id = [x[0] for x in cr.fetchall()] if tasks_id: self.pool.get('project.task').write(cr, uid, tasks_id, {'active': value}, context) - cr.execute('select id from project_project where parent_id=%s', (proj.id,)) - project_ids = [x[0] for x in cr.fetchall()] + cr.execute('select id from project_project where parent_id=%s', (proj.id,)) + project_ids = [x[0] for x in cr.fetchall()] for child in project_ids: - self.setActive(cr, uid, [child], value, context) + self.setActive(cr, uid, [child], value, context) return True project() @@ -239,8 +239,7 @@ class task(osv.osv): # Compute: effective_hours, total_hours, progress def _hours_get(self, cr, uid, ids, field_names, args, context): - task_set = ','.join(map(str, ids)) - cr.execute(("SELECT task_id, COALESCE(SUM(hours),0) FROM project_task_work WHERE task_id in (%s) GROUP BY task_id") % (task_set,)) + cr.execute("SELECT task_id, COALESCE(SUM(hours),0) FROM project_task_work WHERE task_id =ANY(%s) GROUP BY task_id",(ids,)) hours = dict(cr.fetchall()) res = {} for task in self.browse(cr, uid, ids, context=context): @@ -265,7 +264,7 @@ class task(osv.osv): #_sql_constraints = [ # ('remaining_hours', 'CHECK (remaining_hours>=0)', 'Please increase and review remaining hours ! It can not be smaller than 0.'), #] - + def copy_data(self, cr, uid, id, default={},context={}): default = default or {} default['work_ids'] = [] @@ -323,7 +322,7 @@ class task(osv.osv): if not tm: return res tm = tm.name - f = self.pool.get('res.company').fields_get(cr, uid, ['project_time_mode_id'], context) + f = self.pool.get('res.company').fields_get(cr, uid, ['project_time_mode_id'], context) eview = etree.fromstring(res['arch']) def _check_rec(eview, tm): if eview.attrib.get('widget',False) == 'float_time': @@ -469,7 +468,7 @@ class config_compute_remaining(osv.osv_memory): _defaults = { 'remaining_hours': _get_remaining } - + def compute_hours(self, cr, uid, ids, context=None): if 'active_id' in context: remaining_hrs=self.browse(cr,uid,ids)[0].remaining_hours From 5c6eab5491af482fb47d0ca27090790450622899 Mon Sep 17 00:00:00 2001 From: "nch@tinyerp.com" <> Date: Tue, 24 Nov 2009 16:45:43 +0530 Subject: [PATCH 14/53] [IMP]:product_margin module sql queries to parameterized query bzr revid: nch@tinyerp.com-20091124111543-onlx8d0jiyzfdmx1 --- addons/product_margin/product_margin.py | 54 ++++++++++++------------- 1 file changed, 25 insertions(+), 29 deletions(-) diff --git a/addons/product_margin/product_margin.py b/addons/product_margin/product_margin.py index 226fee378fb..9d948fc09d0 100644 --- a/addons/product_margin/product_margin.py +++ b/addons/product_margin/product_margin.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 . # ############################################################################## @@ -25,24 +25,22 @@ from tools import config import time class product_product(osv.osv): - _inherit = "product.product" - - + _inherit = "product.product" + + def _product_margin(self, cr, uid, ids, field_names, arg, context): - res = {} + res = {} for val in self.browse(cr, uid, ids,context=context): res[val.id] = {} - date_from=context.get('date_from', time.strftime('%Y-01-01')) - date_to=context.get('date_to', time.strftime('%Y-12-31')) - invoice_state=context.get('invoice_state', 'open_paid') + date_from=context.get('date_from', time.strftime('%Y-01-01')) + date_to=context.get('date_to', time.strftime('%Y-12-31')) + invoice_state=context.get('invoice_state', 'open_paid') if 'date_from' in field_names: res[val.id]['date_from']=date_from if 'date_to' in field_names: res[val.id]['date_to']=date_to if 'invoice_state' in field_names: res[val.id]['invoice_state']=invoice_state - - invoice_types=[] states=[] if invoice_state=='paid': @@ -51,26 +49,24 @@ class product_product(osv.osv): states=['open','paid'] elif invoice_state=='draft_open_paid': states=['draft','open','paid'] - + if 'sale_avg_price' in field_names or 'sale_num_invoiced' in field_names or 'turnover' in field_names or 'sale_expected' in field_names: invoice_types=['out_invoice','in_refund'] if 'purchase_avg_price' in field_names or 'purchase_num_invoiced' in field_names or 'total_cost' in field_names or 'normal_cost' in field_names: invoice_types=['in_invoice','out_refund'] if len(invoice_types): - sql=""" - select - avg(l.price_unit) as avg_unit_price, - sum(l.quantity) as num_qty, - sum(l.quantity * l.price_unit) as total, - sum(l.quantity * product.list_price) as sale_expected, - sum(l.quantity * product.standard_price) as normal_cost + cr.execute("""select + avg(l.price_unit) as avg_unit_price, + sum(l.quantity) as num_qty, + sum(l.quantity * l.price_unit) as total, + sum(l.quantity * product.list_price) as sale_expected, + sum(l.quantity * product.standard_price) as normal_cost from account_invoice_line l left join account_invoice i on (l.invoice_id = i.id) - left join product_template product on (product.id=l.product_id) - where l.product_id = %s and i.state in ('%s') and i.type in ('%s') and i.date_invoice>='%s' and i.date_invoice<='%s' - """%(val.id,"','".join(states),"','".join(invoice_types),date_from,date_to) - cr.execute(sql) - result=cr.fetchall()[0] + left join product_template product on (product.id=l.product_id) + where l.product_id = %s and i.state =ANY(%s) and i.type =ANY(%s) and i.date_invoice>=%s and i.date_invoice<=%s + """,(val.id,states,invoice_types,date_from,date_to)) + result=cr.fetchall()[0] if 'sale_avg_price' in field_names or 'sale_num_invoiced' in field_names or 'turnover' in field_names or 'sale_expected' in field_names: res[val.id]['sale_avg_price']=result[0] and result[0] or 0.0 res[val.id]['sale_num_invoiced']=result[1] and result[1] or 0.0 @@ -82,8 +78,8 @@ class product_product(osv.osv): res[val.id]['purchase_num_invoiced']=result[1] and result[1] or 0.0 res[val.id]['total_cost']=result[2] and result[2] or 0.0 res[val.id]['normal_cost']=result[4] and result[4] or 0.0 - res[val.id]['purchase_gap']=res[val.id]['normal_cost']-res[val.id]['total_cost'] - + res[val.id]['purchase_gap']=res[val.id]['normal_cost']-res[val.id]['total_cost'] + if 'total_margin' in field_names: res[val.id]['total_margin']=val.turnover-val.total_cost if 'expected_margin' in field_names: @@ -91,15 +87,15 @@ class product_product(osv.osv): if 'total_margin_rate' in field_names: res[val.id]['total_margin_rate']=val.turnover and val.total_margin * 100 / val.turnover or 0.0 if 'expected_margin_rate' in field_names: - res[val.id]['expected_margin_rate']=val.sale_expected and val.expected_margin * 100 / val.sale_expected or 0.0 + res[val.id]['expected_margin_rate']=val.sale_expected and val.expected_margin * 100 / val.sale_expected or 0.0 return res - + _columns = { 'date_from': fields.function(_product_margin, method=True, type='date', string='From Date', multi=True), 'date_to': fields.function(_product_margin, method=True, type='date', string='To Date', multi=True), 'invoice_state': fields.function(_product_margin, method=True, type='selection', selection=[ ('paid','Paid'),('open_paid','Open and Paid'),('draft_open_paid','Draft, Open and Paid') - ], string='Invoice State',multi=True, readonly=True), + ], string='Invoice State',multi=True, readonly=True), 'sale_avg_price' : fields.function(_product_margin, method=True, type='float', string='Avg. Unit Price', multi='sale',help="Avg. Price in Customer Invoices)"), 'purchase_avg_price' : fields.function(_product_margin, method=True, type='float', string='Avg. Unit Price', multi='purchase',help="Avg. Price in Supplier Invoices "), 'sale_num_invoiced' : fields.function(_product_margin, method=True, type='float', string='# Invoiced', multi='sale',help="Sum of Quantity in Customer Invoices"), From a7be6bfaf681bcab9ed528f5d18014471a410489 Mon Sep 17 00:00:00 2001 From: "nch@tinyerp.com" <> Date: Tue, 24 Nov 2009 17:39:06 +0530 Subject: [PATCH 15/53] [IMP]:product module sql queries to parameterized query bzr revid: nch@tinyerp.com-20091124120906-ssum4kpo1g1klw3f --- addons/product/pricelist.py | 37 ++++++++++++++++++------------------- addons/product/product.py | 18 +++++++++--------- 2 files changed, 27 insertions(+), 28 deletions(-) diff --git a/addons/product/pricelist.py b/addons/product/pricelist.py index e44e90633fc..0660884848f 100644 --- a/addons/product/pricelist.py +++ b/addons/product/pricelist.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 . # ############################################################################## @@ -83,12 +83,12 @@ class product_pricelist(osv.osv): pricelist_type_obj = self.pool.get('product.pricelist.type') pricelist_type_ids = pricelist_type_obj.search(cr, uid, [], order='name') pricelist_types = pricelist_type_obj.read(cr, uid, pricelist_type_ids, ['key','name'], context=context) - + res = [] - + for type in pricelist_types: res.append((type['key'],type['name'])) - + return res # cr.execute('select key,name from product_pricelist_type order by name') # return cr.fetchall() @@ -101,7 +101,7 @@ class product_pricelist(osv.osv): 'version_id': fields.one2many('product.pricelist.version', 'pricelist_id', 'Pricelist Versions'), 'currency_id': fields.many2one('res.currency', 'Currency', required=True), } - + def name_get(self, cr, uid, ids, context={}): result= [] if not all(ids): @@ -110,7 +110,7 @@ class product_pricelist(osv.osv): name = pl.name + ' ('+ pl.currency_id.name + ')' result.append((pl.id,name)) return result - + def _get_currency(self, cr, uid, ctx): comp = self.pool.get('res.users').browse(cr, uid, uid).company_id @@ -210,17 +210,16 @@ class product_pricelist(osv.osv): elif res['base'] == -2: where = [] if partner: - where = [('name', '=', partner) ] + where = [('name', '=', partner) ] sinfo = supplierinfo_obj.search(cr, uid, [('product_id', '=', tmpl_id)] + where) price = 0.0 if sinfo: cr.execute('SELECT * ' \ 'FROM pricelist_partnerinfo ' \ - 'WHERE suppinfo_id IN (' + \ - ','.join(map(str, sinfo)) + ') ' \ - 'AND min_quantity <= %s ' \ - 'ORDER BY min_quantity DESC LIMIT 1', (qty,)) + 'WHERE suppinfo_id = ANY(%s)' + 'AND min_quantity <= %s ' \ + 'ORDER BY min_quantity DESC LIMIT 1', (sinfo,qty,)) res2 = cr.dictfetchone() if res2: price = res2['price'] @@ -244,12 +243,12 @@ class product_pricelist(osv.osv): # False means no valid line found ! But we may not raise an # exception here because it breaks the search price = False - result[id] = price + result[id] = price if context and ('uom' in context): product = product_obj.browse(cr, uid, prod_id) uom = product.uos_id or product.uom_id result[id] = self.pool.get('product.uom')._compute_price(cr, - uid, uom.id, result[id], context['uom']) + uid, uom.id, result[id], context['uom']) return result product_pricelist() @@ -331,16 +330,16 @@ class product_pricelist_item(osv.osv): 'sequence': lambda *a: 5, 'price_discount': lambda *a: 0, } - + def _check_recursion(self, cr, uid, ids): for obj_list in self.browse(cr, uid, ids): if obj_list.base == -1: main_pricelist = obj_list.price_version_id.pricelist_id.id other_pricelist = obj_list.base_pricelist_id.id if main_pricelist == other_pricelist: - return False + return False return True - + _columns = { 'name': fields.char('Rule Name', size=64, help="Explicit rule name for this pricelist line."), 'price_version_id': fields.many2one('product.pricelist.version', 'Price List Version', required=True, select=True), @@ -367,11 +366,11 @@ class product_pricelist_item(osv.osv): 'price_max_margin': fields.float('Max. Price Margin', digits=(16, int(config['price_accuracy']))), } - + _constraints = [ (_check_recursion, _('Error ! You cannot assign the Main Pricelist as Other Pricelist in PriceList Item!'), ['base_pricelist_id']) ] - + def product_id_change(self, cr, uid, ids, product_id, context={}): if not product_id: return {} diff --git a/addons/product/product.py b/addons/product/product.py index 509bd61c373..5026c9945f6 100644 --- a/addons/product/product.py +++ b/addons/product/product.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 . # ############################################################################## @@ -208,7 +208,7 @@ class product_category(osv.osv): def _check_recursion(self, cr, uid, ids): level = 100 while len(ids): - cr.execute('select distinct parent_id from product_category where id in ('+','.join(map(str, ids))+')') + cr.execute('select distinct parent_id from product_category where id =ANY(%s)',(ids,)) ids = filter(None, map(lambda x:x[0], cr.fetchall())) if not level: return False @@ -394,8 +394,8 @@ class product_product(osv.osv): product = self.browse(cr, uid, [product_id], context)[0] for supinfo in product.seller_ids: if supinfo.name.id == partner_id: - return {'code': supinfo.product_code, 'name': supinfo.product_name, 'variants': ''} - return {'code' : product.default_code, 'name' : product.name, 'variants': product.variants} + return {'code': supinfo.product_code, 'name': supinfo.product_name, 'variants': ''} + return {'code' : product.default_code, 'name' : product.name, 'variants': product.variants} def _product_code(self, cr, uid, ids, name, arg, context={}): res = {} @@ -408,7 +408,7 @@ class product_product(osv.osv): for p in self.browse(cr, uid, ids, context): data = self._get_partner_code_name(cr, uid, [], p.id, context.get('partner_id', None), context) if not data['variants']: - data['variants'] = p.variants + data['variants'] = p.variants if not data['code']: data['code'] = p.code if not data['name']: @@ -444,7 +444,7 @@ class product_product(osv.osv): 'packaging' : fields.one2many('product.packaging', 'product_id', 'Logistical Units', help="Gives the different ways to package the same product. This has no impact on the packing order and is mainly used if you use the EDI module."), 'price_extra': fields.float('Variant Price Extra', digits=(16, int(config['price_accuracy']))), 'price_margin': fields.float('Variant Price Margin', digits=(16, int(config['price_accuracy']))), - 'pricelist_id': fields.dummy(string='Pricelist',relation='product.pricelist', type='many2one'), + 'pricelist_id': fields.dummy(string='Pricelist',relation='product.pricelist', type='many2one'), } def onchange_uom(self, cursor, user, ids, uom_id,uom_po_id): @@ -542,7 +542,7 @@ class product_product(osv.osv): default = {} default = default.copy() default['name'] = product['name'] + _(' (copy)') - + if context.get('variant',False): fields = ['product_tmpl_id', 'active', 'variants', 'default_code', 'price_margin', 'price_extra'] @@ -587,7 +587,7 @@ class product_packaging(osv.osv): } _order = 'sequence' - + def name_get(self, cr, uid, ids, context={}): if not len(ids): return [] From c214c029d4858083ac425ea660557f6046b9ab83 Mon Sep 17 00:00:00 2001 From: "nch@tinyerp.com" <> Date: Tue, 24 Nov 2009 18:01:07 +0530 Subject: [PATCH 16/53] [IMP]:POS module sql queries to parameterized query bzr revid: nch@tinyerp.com-20091124123107-t32wdpt4powu4ldq --- addons/point_of_sale/pos.py | 15 ++++++--------- addons/point_of_sale/report/pos_lines.py | 6 +++--- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/addons/point_of_sale/pos.py b/addons/point_of_sale/pos.py index 4cf8ef4ec56..ef054ba5088 100644 --- a/addons/point_of_sale/pos.py +++ b/addons/point_of_sale/pos.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 . # ############################################################################## @@ -59,7 +59,6 @@ class pos_order(osv.osv): return {'value': {'pricelist_id': pricelist}} def _amount_total(self, cr, uid, ids, field_name, arg, context): - id_set = ",".join(map(str, ids)) cr.execute(""" SELECT p.id, @@ -68,9 +67,8 @@ class pos_order(osv.osv): ) AS amount FROM pos_order p LEFT OUTER JOIN pos_order_line l ON (p.id=l.order_id) - WHERE p.id IN (""" + id_set +""") GROUP BY p.id """) + WHERE p.id =ANY(%s) GROUP BY p.id """,(ids,)) res = dict(cr.fetchall()) - for rec in self.browse(cr, uid, ids, context): if rec.partner_id \ and rec.partner_id.property_account_position \ @@ -112,8 +110,7 @@ class pos_order(osv.osv): return res def payment_get(self, cr, uid, ids, context=None): - cr.execute("select id from pos_payment where order_id in (%s)" % \ - ','.join([str(i) for i in ids])) + cr.execute("select id from pos_payment where order_id =ANY(%s)",(ids,)) return [i[0] for i in cr.fetchall()] def _sale_journal_get(self, cr, uid, context): @@ -891,14 +888,14 @@ class pos_order_line(osv.osv): price_line = float(qty)*float(price) return {'name': product_name, 'product_id': product_id[0], 'price': price, 'price_line': price_line ,'qty': qty } - + def unlink(self, cr, uid, ids, context={}): """Allows to delete pos order lines in draft,cancel state""" for rec in self.browse(cr, uid, ids, context=context): if rec.order_id.state not in ['draft','cancel']: raise osv.except_osv(_('Invalid action !'), _('Cannot delete an order line which is %s !')%(rec.order_id.state,)) return super(pos_order_line, self).unlink(cr, uid, ids, context=context) - + pos_order_line() diff --git a/addons/point_of_sale/report/pos_lines.py b/addons/point_of_sale/report/pos_lines.py index ff766ce3d68..f7dc508c8d7 100644 --- a/addons/point_of_sale/report/pos_lines.py +++ b/addons/point_of_sale/report/pos_lines.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 . # ############################################################################## @@ -47,7 +47,7 @@ class pos_lines(report_sxw.rml_parse): " LEFT JOIN pos_order_line as pol ON po.id = pol.order_id " \ " LEFT JOIN product_taxes_rel as ptr ON pol.product_id = ptr.prod_id " \ " LEFT JOIN account_tax as acct ON acct.id = ptr.tax_id " \ - " WHERE pol.id = %d" %(obj.id)) + " WHERE pol.id = %s" ,(obj.id,)) res=self.cr.fetchone()[0] return res From c13ca999d842fb87eff3fc3c080ac2f82f3ef833 Mon Sep 17 00:00:00 2001 From: "nch@tinyerp.com" <> Date: Tue, 24 Nov 2009 18:40:45 +0530 Subject: [PATCH 17/53] [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), From 19faaa8222cb8fb18370ff355a940b989833fe7c Mon Sep 17 00:00:00 2001 From: "nch@tinyerp.com" <> Date: Tue, 24 Nov 2009 19:04:45 +0530 Subject: [PATCH 18/53] [IMP]:Membership module sql queries to parameterized query bzr revid: nch@tinyerp.com-20091124133445-f7odi503ktfbofsq --- addons/membership/membership.py | 10 ++++------ addons/membership/wizard/invoice_membership.py | 8 +++----- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/addons/membership/membership.py b/addons/membership/membership.py index bb0afe71845..c21385fdccd 100644 --- a/addons/membership/membership.py +++ b/addons/membership/membership.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 . # ############################################################################## @@ -147,9 +147,7 @@ class membership_line(osv.osv): ) JOIN account_invoice ai ON ( ai.id = ail.invoice_id) - WHERE ml.id in (%s) - ''' % ','.join([str(id) for id in ids])) - + WHERE ml.id =ANY(%s)''',(ids,)) res = cr.fetchall() for r in res: if r[0] and r[0] < 0: @@ -401,7 +399,7 @@ class Partner(osv.osv): def _check_recursion(self, cr, uid, ids): level = 100 while len(ids): - cr.execute('select distinct associate_member from res_partner where id in ('+','.join(map(str, ids))+')') + cr.execute('select distinct associate_member from res_partner where id =ANY(%s)',(ids,)) ids = filter(None, map(lambda x:x[0], cr.fetchall())) if not level: return False diff --git a/addons/membership/wizard/invoice_membership.py b/addons/membership/wizard/invoice_membership.py index e1f8c80426f..3881c94ed22 100644 --- a/addons/membership/wizard/invoice_membership.py +++ b/addons/membership/wizard/invoice_membership.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 . # ############################################################################## @@ -32,9 +32,7 @@ def _invoice_membership(self, cr, uid, data, context): cr.execute(''' SELECT partner_id, id, type FROM res_partner_address - WHERE partner_id IN (%s) - ''' % ','.join([str(id) for id in partner_ids]) - ) + WHERE partner_id =ANY(%s)''',(partner_ids,)) fetchal = cr.fetchall() if not fetchal: raise wizard.except_wizard(_('Error !'), _('No Address defined for this partner')) From 8354496c6dfd84bc1cff77260f24079760170ac5 Mon Sep 17 00:00:00 2001 From: "nch@tinyerp.com" <> Date: Wed, 25 Nov 2009 16:04:50 +0530 Subject: [PATCH 19/53] [FIX]:fix string problem bzr revid: nch@tinyerp.com-20091125103450-gla544qdr273udgy --- addons/product_margin/product_margin.py | 16 ++++++++-------- addons/stock/product.py | 4 ++-- addons/stock/report/product_stock.py | 8 ++++---- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/addons/product_margin/product_margin.py b/addons/product_margin/product_margin.py index 9d948fc09d0..51933fd6cdd 100644 --- a/addons/product_margin/product_margin.py +++ b/addons/product_margin/product_margin.py @@ -41,19 +41,19 @@ class product_product(osv.osv): res[val.id]['date_to']=date_to if 'invoice_state' in field_names: res[val.id]['invoice_state']=invoice_state - invoice_types=[] - states=[] + invoice_types=() + states=() if invoice_state=='paid': - states=['paid'] + states=('paid') elif invoice_state=='open_paid': - states=['open','paid'] + states=('open','paid') elif invoice_state=='draft_open_paid': - states=['draft','open','paid'] + states=('draft','open','paid') if 'sale_avg_price' in field_names or 'sale_num_invoiced' in field_names or 'turnover' in field_names or 'sale_expected' in field_names: - invoice_types=['out_invoice','in_refund'] + invoice_types=('out_invoice','in_refund') if 'purchase_avg_price' in field_names or 'purchase_num_invoiced' in field_names or 'total_cost' in field_names or 'normal_cost' in field_names: - invoice_types=['in_invoice','out_refund'] + invoice_types=('in_invoice','out_refund') if len(invoice_types): cr.execute("""select avg(l.price_unit) as avg_unit_price, @@ -64,7 +64,7 @@ class product_product(osv.osv): from account_invoice_line l left join account_invoice i on (l.invoice_id = i.id) left join product_template product on (product.id=l.product_id) - where l.product_id = %s and i.state =ANY(%s) and i.type =ANY(%s) and i.date_invoice>=%s and i.date_invoice<=%s + where l.product_id = %s and i.state in %s and i.type in %s and i.date_invoice>=%s and i.date_invoice<=%s """,(val.id,states,invoice_types,date_from,date_to)) result=cr.fetchall()[0] if 'sale_avg_price' in field_names or 'sale_num_invoiced' in field_names or 'turnover' in field_names or 'sale_expected' in field_names: diff --git a/addons/stock/product.py b/addons/stock/product.py index def19749503..1724b8bc86e 100644 --- a/addons/stock/product.py +++ b/addons/stock/product.py @@ -101,7 +101,7 @@ class product_product(osv.osv): '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,) + 'group by product_id,product_uom',(location_ids,location_ids,ids,tuple(states),) ) results = cr.fetchall() if 'out' in what: @@ -113,7 +113,7 @@ class product_product(osv.osv): '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,) + 'group by product_id,product_uom',(location_ids,location_ids,ids,tuple(states),) ) results2 = cr.fetchall() uom_obj = self.pool.get('product.uom') diff --git a/addons/stock/report/product_stock.py b/addons/stock/report/product_stock.py index 19742c86786..615b65e5e35 100644 --- a/addons/stock/report/product_stock.py +++ b/addons/stock/report/product_stock.py @@ -68,10 +68,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 =ANY(%s)" + "where state in %s" "and location_id=ANY(%s)" "and product_id=ANY(%s)" - "group by date_planned,product_id",(['confirmed','assigned','waiting'],loc_ids ,product_ids,)) + "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') @@ -82,10 +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=ANY(%s)" + "where state in %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,)) + "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: From c80cbcd371389973d6b2589cb5a26105923cb2ac Mon Sep 17 00:00:00 2001 From: "nch@tinyerp.com" <> Date: Wed, 25 Nov 2009 17:02:07 +0530 Subject: [PATCH 20/53] [IMP]:l10n_fr sql queries to parameterized query bzr revid: nch@tinyerp.com-20091125113207-1557k1ysnvp5z52n --- addons/l10n_fr/report/base_report.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/addons/l10n_fr/report/base_report.py b/addons/l10n_fr/report/base_report.py index d12a76298cc..1de66123f2c 100644 --- a/addons/l10n_fr/report/base_report.py +++ b/addons/l10n_fr/report/base_report.py @@ -43,19 +43,16 @@ class base_report(report_sxw.rml_parse): def _load(self,name,form): fiscalyear=self.pool.get('account.fiscalyear').browse(self.cr, self.uid, form['fiscalyear']) - periods=self.pool.get('account.period').search(self.cr, self.uid,[('fiscalyear_id','=',form['fiscalyear'])]) - period_query_cond=str(tuple(periods)) + period_query_cond=self.pool.get('account.period').search(self.cr, self.uid,[('fiscalyear_id','=',form['fiscalyear'])]) - query = "SELECT MIN(date_start) AS date_start, MAX(date_stop) AS date_stop FROM account_period WHERE id IN "+str(period_query_cond) - self.cr.execute(query) + self.cr.execute("SELECT MIN(date_start) AS date_start, MAX(date_stop) AS date_stop FROM account_period WHERE id =ANY(%s)",(period_query_cond,)) dates =self.cr.dictfetchall() self._set_variable('date_start', dates[0]['date_start']) self._set_variable('date_stop', dates[0]['date_stop']) - query = "SELECT l10n_fr_line.code,definition FROM l10n_fr_line LEFT JOIN l10n_fr_report ON l10n_fr_report.id=report_id WHERE l10n_fr_report.code='"+name+"'" - self.cr.execute(query) + self.cr.execute("SELECT l10n_fr_line.code,definition FROM l10n_fr_line LEFT JOIN l10n_fr_report ON l10n_fr_report.id=report_id WHERE l10n_fr_report.code=%s",(name,)) datas =self.cr.dictfetchall() - for line in datas: + for line in datas: self._load_accounts(form,line['code'],eval(line['definition']),fiscalyear,period_query_cond) def _set_variable(self,variable,valeur): @@ -86,9 +83,9 @@ class base_report(report_sxw.rml_parse): closed_cond="" if fiscalyear.state=='done': - closed_cond=" AND (aml.move_id NOT IN (SELECT account_move.id as move_id FROM account_move WHERE period_id IN "+str(period_query_cond)+" AND journal_id=(SELECT res_id FROM ir_model_data WHERE name='closing_journal' AND module='l10n_fr')) OR (aa.type != 'income' AND aa.type !='expense'))" + closed_cond=" AND (aml.move_id NOT IN (SELECT account_move.id as move_id FROM account_move WHERE period_id IN "+str(tuple(period_query_cond))+" AND journal_id=(SELECT res_id FROM ir_model_data WHERE name='closing_journal' AND module='l10n_fr')) OR (aa.type != 'income' AND aa.type !='expense'))" - query = "SELECT aa.code AS code, SUM(debit) as debit, SUM(credit) as credit FROM account_move_line aml LEFT JOIN account_account aa ON aa.id=aml.account_id WHERE "+query_cond+closed_cond+" AND aml.state='valid' AND aml.period_id IN "+str(period_query_cond)+" GROUP BY code" + query = "SELECT aa.code AS code, SUM(debit) as debit, SUM(credit) as credit FROM account_move_line aml LEFT JOIN account_account aa ON aa.id=aml.account_id WHERE "+query_cond+closed_cond+" AND aml.state='valid' AND aml.period_id IN "+str(tuple(period_query_cond))+" GROUP BY code" self.cr.execute(query) lines =self.cr.dictfetchall() @@ -102,7 +99,7 @@ class base_report(report_sxw.rml_parse): value=line["debit"]-line["credit"] elif(type=="D"): value=line["debit"]-line["credit"] - if(value<0.001): value=0.0 + if(value<0.001): value=0.0 elif(type=="C"): value=line["credit"]-line["debit"] if(value<0.001): value=0.0 From db6d336b781f0c87c5677373b543ce692de908cc Mon Sep 17 00:00:00 2001 From: "nch@tinyerp.com" <> Date: Wed, 25 Nov 2009 17:34:43 +0530 Subject: [PATCH 21/53] [IMP]:l10n_ch sql queries to parameterized query bzr revid: nch@tinyerp.com-20091125120443-9kzhbwxbeyhd2uh1 --- addons/l10n_ch/wizard/bvr_import.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/addons/l10n_ch/wizard/bvr_import.py b/addons/l10n_ch/wizard/bvr_import.py index 659c0b557bb..55caf5c4162 100755 --- a/addons/l10n_ch/wizard/bvr_import.py +++ b/addons/l10n_ch/wizard/bvr_import.py @@ -57,12 +57,11 @@ def _reconstruct_invoice_ref(cursor, user, reference, context): # we now searhc for company user_obj=pooler.get_pool(cursor.dbname).get('res.users') user_current=user_obj.browse(cursor, user, user) - + ## - - cursor.execute("SELECT inv.id,inv.number from account_invoice AS inv where inv.company_id = " + str(user_current.company_id.id)) + cursor.execute("SELECT inv.id,inv.number from account_invoice AS inv where inv.company_id = %s" ,(user_current.company_id.id,)) result_invoice = cursor.fetchall() - + for inv_id,inv_name in result_invoice: inv_name = re.sub('[^0-9]', '0', str(inv_name)) if inv_name == reference: @@ -72,7 +71,7 @@ def _reconstruct_invoice_ref(cursor, user, reference, context): cursor.execute('SELECT l.id ' \ 'FROM account_move_line l, account_invoice i ' \ 'WHERE l.move_id = i.move_id AND l.reconcile_id is NULL ' \ - 'AND i.id in (' + ','.join([str(x) for x in [id_invoice]]) + ')') + 'AND i.id =ANY(%s)',([id_invoice],)) inv_line = [] for id_line in cursor.fetchall(): inv_line.append(id_line[0]) @@ -181,7 +180,7 @@ def _import(obj, cursor, user, data, context): ], order='date desc', context=context) if not line_ids: line_ids = _reconstruct_invoice_ref(cursor,user,reference,None) - + line2reconcile = False partner_id = False account_id = False From f9cfe287f8fc821fc5d596a261e42fba3c745a0f Mon Sep 17 00:00:00 2001 From: "nch@tinyerp.com" <> Date: Thu, 26 Nov 2009 10:53:37 +0530 Subject: [PATCH 22/53] [IMP]:l10n_be sql queries to parameterized query bzr revid: nch@tinyerp.com-20091126052337-bks1pvwy16pb9awx --- addons/l10n_be/wizard/partner_vat_listing.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/addons/l10n_be/wizard/partner_vat_listing.py b/addons/l10n_be/wizard/partner_vat_listing.py index 4e9fed80300..fb720429600 100644 --- a/addons/l10n_be/wizard/partner_vat_listing.py +++ b/addons/l10n_be/wizard/partner_vat_listing.py @@ -92,9 +92,7 @@ class wizard_vat(wizard.interface): def _get_partner(self, cr, uid, data, context): pool = pooler.get_pool(cr.dbname) - period_ids = pool.get('account.period').search(cr, uid, [('fiscalyear_id', '=', data['form']['fyear'])]) - period = "("+','.join(map(lambda x: str(x), period_ids)) +")" - + period = pool.get('account.period').search(cr, uid, [('fiscalyear_id', '=', data['form']['fyear'])]) p_id_list = pool.get('res.partner').search(cr,uid,[('vat_subjected','!=',False)]) if not p_id_list: raise wizard.except_wizard(_('Data Insufficient!'),_('No partner has a VAT Number asociated with him.')) @@ -113,8 +111,7 @@ class wizard_vat(wizard.interface): break if not go_ahead: continue - query = 'select b.code,sum(credit)-sum(debit) from account_move_line l left join account_account a on (l.account_id=a.id) left join account_account_type b on (a.user_type=b.id) where b.code in ('"'produit'"','"'tax'"') and l.partner_id='+str(obj_partner.id)+' and l.period_id in '+period+' group by b.code' - cr.execute(query) + cr.execute('select b.code,sum(credit)-sum(debit) from account_move_line l left join account_account a on (l.account_id=a.id) left join account_account_type b on (a.user_type=b.id) where b.code in %s and l.partner_id=%s and l.period_id=ANY(%s) group by b.code',(('produit','tax'),obj_partner.id,period,)) line_info = cr.fetchall() if not line_info: continue From 4925d80f2c6b0ebc91038d7bdbca5a5ebac950b8 Mon Sep 17 00:00:00 2001 From: "nch@tinyerp.com" <> Date: Thu, 26 Nov 2009 11:13:26 +0530 Subject: [PATCH 23/53] [IMP]:Idea sql queries to parameterized query bzr revid: nch@tinyerp.com-20091126054326-evu8fblc8bmwk3ky --- addons/idea/idea.py | 33 ++++++++++----------------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/addons/idea/idea.py b/addons/idea/idea.py index ad5b29e42e1..dff0aa5d041 100644 --- a/addons/idea/idea.py +++ b/addons/idea/idea.py @@ -46,41 +46,28 @@ class idea_idea(osv.osv): def _vote_avg_compute(self, cr, uid, ids, name, arg, context = None): if not len(ids): return {} - - sql = """select i.id, avg(v.score::integer) - from idea_idea i left outer join idea_vote v on i.id = v.idea_id - where i.id in (%s) - group by i.id - """ % ','.join(['%s']*len(ids)) - - cr.execute(sql, ids) + cr.execute(""" select i.id, avg(v.score::integer) + from idea_idea i left outer join idea_vote v on i.id = v.idea_id + where i.id =ANY(%s) + group by i.id """,(ids,)) return dict(cr.fetchall()) def _vote_count(self,cr,uid,ids,name,arg,context=None): if not len(ids): return {} - - sql = """select i.id, count(1) + cr.execute("""select i.id, count(1) from idea_idea i left outer join idea_vote v on i.id = v.idea_id - where i.id in (%s) - group by i.id - """ % ','.join(['%s']*len(ids)) - - cr.execute(sql, ids) + where i.id =ANY(%s) + group by i.id""",(ids,)) return dict(cr.fetchall()) def _comment_count(self,cr,uid,ids,name,arg,context=None): if not len(ids): return {} - - sql = """select i.id, count(1) + cr.execute("""select i.id, count(1) from idea_idea i left outer join idea_comment c on i.id = c.idea_id - where i.id in (%s) - group by i.id - """ % ','.join(['%s']*len(ids)) - - - cr.execute(sql,ids) + where i.id =ANY(%s) + group by i.id""",(ids,)) return dict(cr.fetchall()) def _vote_read(self, cr, uid, ids, name, arg, context = None): From 719291b5c004ffea9edde01fedc204053175c6fd Mon Sep 17 00:00:00 2001 From: "nch@tinyerp.com" <> Date: Thu, 26 Nov 2009 11:49:00 +0530 Subject: [PATCH 24/53] [IMP]:hr_timesheet_sheet sql queries to parameterized query bzr revid: nch@tinyerp.com-20091126061900-zmfo84ck4yngci9p --- addons/hr_timesheet_sheet/hr_timesheet_sheet.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/addons/hr_timesheet_sheet/hr_timesheet_sheet.py b/addons/hr_timesheet_sheet/hr_timesheet_sheet.py index 51ac91ddbf6..f915bf9ea2e 100644 --- a/addons/hr_timesheet_sheet/hr_timesheet_sheet.py +++ b/addons/hr_timesheet_sheet/hr_timesheet_sheet.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 . # ############################################################################## @@ -103,7 +103,7 @@ class hr_timesheet_sheet(osv.osv): LEFT JOIN hr_timesheet_sheet_sheet_day AS day \ ON (sheet.id = day.sheet_id \ AND day.name = sheet.date_current) \ - WHERE sheet.id in (' + ','.join([str(x) for x in ids]) + ')') + WHERE sheet.id =ANY(%s)',(ids,)) for record in cr.fetchall(): res[record[0]] = {} res[record[0]]['total_attendance_day'] = record[1] @@ -117,8 +117,7 @@ class hr_timesheet_sheet(osv.osv): FROM hr_timesheet_sheet_sheet s \ LEFT JOIN hr_timesheet_sheet_sheet_day d \ ON (s.id = d.sheet_id) \ - WHERE s.id in ('+ ','.join(map(str, ids)) + ') \ - GROUP BY s.id') + WHERE s.id =ANY(%s) GROUP BY s.id',(ids,)) for record in cr.fetchall(): res[record[0]] = {} res[record[0]]['total_attendance'] = record[1] @@ -215,7 +214,7 @@ class hr_timesheet_sheet(osv.osv): return True _columns = { - 'name': fields.char('Description', size=64, select=1, + 'name': fields.char('Description', size=64, select=1, states={'confirm':[('readonly', True)], 'done':[('readonly', True)]}), 'user_id': fields.many2one('res.users', 'User', required=True, select=1, states={'confirm':[('readonly', True)], 'done':[('readonly', True)]}), @@ -337,8 +336,7 @@ class hr_timesheet_line(osv.osv): ON (s.date_to >= al.date \ AND s.date_from <= al.date \ AND s.user_id = al.user_id) \ - WHERE l.id in (' + ','.join([str(x) for x in ids]) + ') \ - GROUP BY l.id') + WHERE l.id =ANY(%s) GROUP BY l.id',(ids,)) res = dict(cursor.fetchall()) sheet_names = {} for sheet_id, name in sheet_obj.name_get(cursor, user, res.values(), @@ -455,8 +453,7 @@ class hr_attendance(osv.osv): ON (s.date_to >= to_date(to_char(a.name, 'YYYY-MM-dd'),'YYYY-MM-dd') \ AND s.date_from <= to_date(to_char(a.name, 'YYYY-MM-dd'),'YYYY-MM-dd') \ AND s.user_id = e.user_id) \ - WHERE a.id in (" + ",".join([str(x) for x in ids]) + ") \ - GROUP BY a.id") + WHERE a.id =ANY(%s) GROUP BY a.id",(ids,)) res = dict(cursor.fetchall()) sheet_names = {} for sheet_id, name in sheet_obj.name_get(cursor, user, res.values(), From 486352c771f3bd87900a5171bcf3f5dc581d7a97 Mon Sep 17 00:00:00 2001 From: "nch@tinyerp.com" <> Date: Thu, 26 Nov 2009 12:37:14 +0530 Subject: [PATCH 25/53] [IMP]:hr_timesheet_invoice sql queries to parameterized query bzr revid: nch@tinyerp.com-20091126070714-rn464yyoz7rr72gz --- .../report/cost_ledger.py | 12 +++--- .../wizard/hr_timesheet_invoice_create.py | 42 +++++++++---------- 2 files changed, 25 insertions(+), 29 deletions(-) diff --git a/addons/hr_timesheet_invoice/report/cost_ledger.py b/addons/hr_timesheet_invoice/report/cost_ledger.py index 6541ac494af..374731a67da 100644 --- a/addons/hr_timesheet_invoice/report/cost_ledger.py +++ b/addons/hr_timesheet_invoice/report/cost_ledger.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 . # ############################################################################## @@ -112,7 +112,7 @@ class account_analytic_cost_ledger(report_sxw.rml_parse): return self.cr.fetchone()[0] or 0.0 def _account_sum_balance(self, account_id, date1, date2): - debit = self._account_sum_debit(account_id, date1, date2) + debit = self._account_sum_debit(account_id, date1, date2) credit = self._account_sum_credit(account_id, date1, date2) return (debit-credit) @@ -130,7 +130,7 @@ class account_analytic_cost_ledger(report_sxw.rml_parse): ids = map(lambda x: x.id, accounts) if not len(ids): return 0.0 - self.cr.execute("SELECT sum(amount) FROM account_analytic_line WHERE account_id IN ("+','.join(map(str, ids))+") AND date>=%s AND date<=%s AND amount>0", (date1, date2)) + self.cr.execute("SELECT sum(amount) FROM account_analytic_line WHERE account_id =ANY(%s) AND date>=%s AND date<=%s AND amount>0", (ids,date1, date2)) return self.cr.fetchone()[0] or 0.0 def _sum_credit(self, accounts, date1, date2): @@ -138,7 +138,7 @@ class account_analytic_cost_ledger(report_sxw.rml_parse): if not len(ids): return 0.0 ids = map(lambda x: x.id, accounts) - self.cr.execute("SELECT -sum(amount) FROM account_analytic_line WHERE account_id IN ("+','.join(map(str, ids))+") AND date>=%s AND date<=%s AND amount<0", (date1, date2)) + self.cr.execute("SELECT -sum(amount) FROM account_analytic_line WHERE account_id =ANY(%s) AND date>=%s AND date<=%s AND amount<0", (ids, date1, date2)) return self.cr.fetchone()[0] or 0.0 def _sum_balance(self, accounts, date1, date2): @@ -151,7 +151,7 @@ class account_analytic_cost_ledger(report_sxw.rml_parse): if not len(ids): return 0.0 ids = map(lambda x: x.id, accounts) - self.cr.execute("SELECT sum(unit_amount) FROM account_analytic_line WHERE account_id IN ("+','.join(map(str, ids))+") AND date>=%s AND date<=%s", (date1, date2)) + self.cr.execute("SELECT sum(unit_amount) FROM account_analytic_line WHERE account_id =ANY(%s) AND date>=%s AND date<=%s", (ids,date1, date2)) return self.cr.fetchone()[0] or 0.0 def _sum_revenue(self, accounts): diff --git a/addons/hr_timesheet_invoice/wizard/hr_timesheet_invoice_create.py b/addons/hr_timesheet_invoice/wizard/hr_timesheet_invoice_create.py index 61f629af120..d714d15a294 100644 --- a/addons/hr_timesheet_invoice/wizard/hr_timesheet_invoice_create.py +++ b/addons/hr_timesheet_invoice/wizard/hr_timesheet_invoice_create.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 . # ############################################################################## @@ -35,15 +35,15 @@ class invoice_create(wizard.interface): def _get_accounts(self, cr, uid, data, context): if not len(data['ids']): return {} - cr.execute("SELECT distinct(account_id) from account_analytic_line where id IN (%s)"% (','.join(map(str,data['ids'])),)) + cr.execute("SELECT distinct(account_id) from account_analytic_line where id =ANY(%s)",(data['ids'],)) account_ids = cr.fetchall() return {'accounts': [x[0] for x in account_ids]} def _do_create(self, cr, uid, data, context): pool = pooler.get_pool(cr.dbname) - mod_obj = pool.get('ir.model.data') + mod_obj = pool.get('ir.model.data') result = mod_obj._get_id(cr, uid, 'account', 'view_account_invoice_filter') - res = mod_obj.read(cr, uid, result, ['res_id']) + res = mod_obj.read(cr, uid, result, ['res_id']) analytic_account_obj = pool.get('account.analytic.account') res_partner_obj = pool.get('res.partner') account_payment_term_obj = pool.get('account.payment.term') @@ -91,9 +91,8 @@ class invoice_create(wizard.interface): cr.execute("SELECT product_id, to_invoice, sum(unit_amount) " \ "FROM account_analytic_line as line " \ "WHERE account_id = %s " \ - "AND id IN (" + ','.join([str(x) for x in data['ids']]) + ") " \ - "AND to_invoice IS NOT NULL " \ - "GROUP BY product_id,to_invoice", (account.id,)) + "AND id =ANY(%s) AND to_invoice IS NOT NULL " \ + "GROUP BY product_id,to_invoice", (account.id,data['ids'],)) for product_id,factor_id,qty in cr.fetchall(): product = pool.get('product.product').browse(cr, uid, product_id, context2) @@ -101,7 +100,7 @@ class invoice_create(wizard.interface): raise wizard.except_wizard(_('Error'), _('At least one line has no product !')) factor_name = '' factor = pool.get('hr_timesheet_invoice.factor').browse(cr, uid, factor_id, context2) - + if not data['form']['product']: if factor.customer_name: factor_name = product.name+' - '+factor.customer_name @@ -109,7 +108,7 @@ class invoice_create(wizard.interface): factor_name = product.name else: factor_name = pool.get('product.product').name_get(cr, uid, [data['form']['product']], context=context)[0][1] - + if account.pricelist_id: pl = account.pricelist_id.id price = pool.get('product.pricelist').price_get(cr,uid,[pl], data['form']['product'] or product_id, qty or 1.0, account.partner_id.id)[pl] @@ -119,7 +118,6 @@ class invoice_create(wizard.interface): taxes = product.taxes_id tax = pool.get('account.fiscal.position').map_tax(cr, uid, account.partner_id.property_account_position, taxes) account_id = product.product_tmpl_id.property_account_income.id or product.categ_id.property_account_income_categ.id - curr_line = { 'price_unit': price, 'quantity': qty, @@ -133,17 +131,16 @@ class invoice_create(wizard.interface): 'account_id': account_id, 'account_analytic_id': account.id, } - + # # Compute for lines # cr.execute("SELECT * " # TODO optimize this " FROM account_analytic_line" - " WHERE account_id=%%s" - " AND id IN (%s)" - " AND product_id=%%s" - " AND to_invoice=%%s" % ','.join(['%s']*len(data['ids'])), - tuple([account.id]+ data['ids']+[ product_id, factor_id])) + " WHERE account_id =%s" + " AND id =ANY(%s)" + " AND product_id=%s" + " AND to_invoice=%s",(account.id,data['ids'],product_id, factor_id)) line_ids = cr.dictfetchall() note = [] for line in line_ids: @@ -164,13 +161,12 @@ class invoice_create(wizard.interface): curr_line['note'] = "\n".join(map(lambda x: x or '',note)) pool.get('account.invoice.line').create(cr, uid, curr_line) - strids = ','.join(map(str, data['ids'])) - cr.execute("update account_analytic_line set invoice_id=%%s WHERE account_id = %%s and id IN (%s)" % strids, (last_invoice,account.id,)) - + cr.execute("update account_analytic_line set invoice_id=%s WHERE account_id = %s and id =ANY(%s)" ,(last_invoice,account.id,data['ids'])) + pool.get('account.invoice').button_reset_taxes(cr, uid, [last_invoice], context) - + mod_obj = pooler.get_pool(cr.dbname).get('ir.model.data') - act_obj = pooler.get_pool(cr.dbname).get('ir.actions.act_window') + act_obj = pooler.get_pool(cr.dbname).get('ir.actions.act_window') mod_id = mod_obj.search(cr, uid, [('name', '=', 'action_invoice_tree1')])[0] res_id = mod_obj.read(cr, uid, mod_id, ['res_id'])['res_id'] @@ -178,7 +174,7 @@ class invoice_create(wizard.interface): act_win['domain'] = [('id','in',invoices),('type','=','out_invoice')] act_win['name'] = _('Invoices') return act_win - + # return { # 'domain': "[('id','in', ["+','.join(map(str,invoices))+"])]", # 'name': _('Invoices'), From 4ab78ca82f96ac6268220162421720ad48282400 Mon Sep 17 00:00:00 2001 From: "nch@tinyerp.com" <> Date: Thu, 26 Nov 2009 16:47:31 +0530 Subject: [PATCH 26/53] [IMP]:hr_expense sql queries to parameterized query bzr revid: nch@tinyerp.com-20091126111731-4zuvqe5j26ncwds8 --- addons/hr_expense/hr_expense.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/addons/hr_expense/hr_expense.py b/addons/hr_expense/hr_expense.py index dd9c4e44aba..044272b4a08 100644 --- a/addons/hr_expense/hr_expense.py +++ b/addons/hr_expense/hr_expense.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 . # ############################################################################## @@ -38,8 +38,7 @@ class hr_expense_expense(osv.osv): return super(hr_expense_expense, self).copy(cr, uid, id, default, context) def _amount(self, cr, uid, ids, field_name, arg, context): - id_set = ",".join(map(str, ids)) - cr.execute("SELECT s.id,COALESCE(SUM(l.unit_amount*l.unit_quantity),0) AS amount FROM hr_expense_expense s LEFT OUTER JOIN hr_expense_line l ON (s.id=l.expense_id) WHERE s.id IN ("+id_set+") GROUP BY s.id ") + cr.execute("SELECT s.id,COALESCE(SUM(l.unit_amount*l.unit_quantity),0) AS amount FROM hr_expense_expense s LEFT OUTER JOIN hr_expense_line l ON (s.id=l.expense_id) WHERE s.id =ANY(%s) GROUP BY s.id ",(ids,)) res = dict(cr.fetchall()) return res @@ -126,7 +125,7 @@ class hr_expense_expense(osv.osv): acc = self.pool.get('ir.property').get(cr, uid, 'property_account_expense_categ', 'product.category') if not acc: raise osv.except_osv(_('Error !'), _('Please configure Default Expanse account for Product purchase, `property_account_expense_categ`')) - + lines.append((0, False, { 'name': l.name, 'account_id': acc, @@ -173,11 +172,11 @@ hr_expense_expense() class product_product(osv.osv): _inherit = "product.product" - + _columns = { 'hr_expense_ok': fields.boolean('Can be Expensed', help="Determine if the product can be visible in the list of product within a selection from an HR expense sheet line."), } - + product_product() @@ -187,8 +186,7 @@ class hr_expense_line(osv.osv): def _amount(self, cr, uid, ids, field_name, arg, context): if not len(ids): return {} - id_set = ",".join(map(str, ids)) - cr.execute("SELECT l.id,COALESCE(SUM(l.unit_amount*l.unit_quantity),0) AS amount FROM hr_expense_line l WHERE id IN ("+id_set+") GROUP BY l.id ") + cr.execute("SELECT l.id,COALESCE(SUM(l.unit_amount*l.unit_quantity),0) AS amount FROM hr_expense_line l WHERE id =ANY(%s) GROUP BY l.id ",(ids,)) res = dict(cr.fetchall()) return res From c7264edfb03ad0a507622573cd44f2d6ea9947d2 Mon Sep 17 00:00:00 2001 From: "nch@tinyerp.com" <> Date: Thu, 26 Nov 2009 17:29:07 +0530 Subject: [PATCH 27/53] [IMP]:hr_attendance sql queries to parameterized query bzr revid: nch@tinyerp.com-20091126115907-0xsfarebg1cqw8d3 --- addons/hr_attendance/hr_attendance.py | 29 +++++++++---------- .../wizard/print_attendance_error.py | 16 +++++----- 2 files changed, 21 insertions(+), 24 deletions(-) diff --git a/addons/hr_attendance/hr_attendance.py b/addons/hr_attendance/hr_attendance.py index 07223487dc5..f8603a09590 100644 --- a/addons/hr_attendance/hr_attendance.py +++ b/addons/hr_attendance/hr_attendance.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 . # ############################################################################## @@ -56,7 +56,7 @@ class hr_attendance(osv.osv): 'name' : lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'), 'employee_id' : _employee_get, } - + def _altern_si_so(self, cr, uid, ids): for id in ids: sql = ''' @@ -66,14 +66,14 @@ class hr_attendance(osv.osv): and action in ('sign_in','sign_out') and name <= (select name from hr_attendance where id=%s) order by name desc - limit 2 - ''' % (id, id) - cr.execute(sql) + limit 2 ''' + + cr.execute(sql,(id,id)) atts = cr.fetchall() if not ((len(atts)==1 and atts[0][0] == 'sign_in') or (atts[0][0] != atts[1][0] and atts[0][1] != atts[1][1])): return False return True - + _constraints = [(_altern_si_so, 'Error: Sign in (resp. Sign out) must follow Sign out (resp. Sign in)', ['action'])] _order = 'name desc' hr_attendance() @@ -81,7 +81,7 @@ hr_attendance() class hr_employee(osv.osv): _inherit = "hr.employee" _description = "Employee" - + def _state(self, cr, uid, ids, name, args, context={}): result = {} for id in ids: @@ -96,16 +96,15 @@ class hr_employee(osv.osv): LEFT JOIN hr_attendance \ ON (hr_attendance.employee_id = foo.employee_id \ AND hr_attendance.name = foo.name) \ - WHERE hr_attendance.employee_id \ - in (' + ','.join([str(x) for x in ids]) + ')') + WHERE hr_attendance.employee_id =ANY(%s)',(ids,)) for res in cr.fetchall(): result[res[1]] = res[0] == 'sign_in' and 'present' or 'absent' return result - + _columns = { 'state': fields.function(_state, method=True, type='selection', selection=[('absent', 'Absent'), ('present', 'Present')], string='Attendance'), } - + def sign_change(self, cr, uid, ids, context={}, dt=False): for emp in self.browse(cr, uid, ids): if not self._action_check(cr, uid, emp.id, dt, context): @@ -143,7 +142,7 @@ class hr_employee(osv.osv): res['name'] = dt id = self.pool.get('hr.attendance').create(cr, uid, res, context=context) return id - + hr_employee() - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/hr_attendance/wizard/print_attendance_error.py b/addons/hr_attendance/wizard/print_attendance_error.py index 79c103c79cf..3c461b54f9c 100644 --- a/addons/hr_attendance/wizard/print_attendance_error.py +++ b/addons/hr_attendance/wizard/print_attendance_error.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 . # ############################################################################## @@ -41,21 +41,19 @@ _date_fields = { def _check_data(self, cr, uid, data, *args): date_from = data['form']['init_date'] date_to = data['form']['end_date'] - emp_ids = (','.join([str(x) for x in data['ids']])) - - cr.execute("select id from hr_attendance where employee_id in (%s) and to_char(name,'YYYY-mm-dd')<='%s' and to_char(name,'YYYY-mm-dd')>='%s' and action in ('%s','%s') order by name" %(emp_ids, date_to, date_from, 'sign_in', 'sign_out')) + cr.execute("select id from hr_attendance where employee_id =ANY(%s) and to_char(name,'YYYY-mm-dd')<=%s and to_char(name,'YYYY-mm-dd')>=%s and action =ANY(%s) order by name" ,(data['ids'], date_to, date_from, ['sign_in','sign_out'])) attendance_ids = [x[0] for x in cr.fetchall()] if not attendance_ids: - raise wizard.except_wizard(_('No Data Available'), _('No records found for your selection!')) - + raise wizard.except_wizard(_('No Data Available'), _('No records found for your selection!')) + attendance_records = pooler.get_pool(cr.dbname).get('hr.attendance').browse(cr,uid,attendance_ids) emp_ids = [] for rec in attendance_records: if rec.employee_id.id not in emp_ids: emp_ids.append(rec.employee_id.id) - + data['form']['emp_ids'] = emp_ids - + return data['form'] From 3ab138981416f76a5631a2e42fc73ebed593ff26 Mon Sep 17 00:00:00 2001 From: "nch@tinyerp.com" <> Date: Thu, 26 Nov 2009 17:40:51 +0530 Subject: [PATCH 28/53] [IMP]:hr sql queries to parameterized query bzr revid: nch@tinyerp.com-20091126121051-tm9jjybir4ei2hht --- addons/hr/hr.py | 22 +++++++++++----------- addons/hr/hr_department.py | 12 ++++++------ 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/addons/hr/hr.py b/addons/hr/hr.py index 896a2047eda..e73914c5aa3 100644 --- a/addons/hr/hr.py +++ b/addons/hr/hr.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 . # ############################################################################## @@ -91,27 +91,27 @@ hr_timesheet_group() class hr_employee_category(osv.osv): _name = "hr.employee.category" _description = "Employee Category" - + _columns = { 'name' : fields.char("Category", size=64, required=True), 'parent_id': fields.many2one('hr.employee.category', 'Parent Category', select=True), 'child_ids': fields.one2many('hr.employee.category', 'parent_id', 'Child Categories') } - + def _check_recursion(self, cr, uid, ids): level = 100 while len(ids): - cr.execute('select distinct parent_id from hr_employee_category where id in ('+','.join(map(str, ids))+')') + cr.execute('select distinct parent_id from hr_employee_category where id=ANY(%s)',(ids,)) ids = filter(None, map(lambda x:x[0], cr.fetchall())) if not level: return False level -= 1 return True - + _constraints = [ (_check_recursion, 'Error ! You cannot create recursive Categories.', ['parent_id']) ] - + hr_employee_category() class hr_employee(osv.osv): @@ -146,21 +146,21 @@ class hr_employee(osv.osv): _defaults = { 'active' : lambda *a: True, } - + def _check_recursion(self, cr, uid, ids): level = 100 while len(ids): - cr.execute('select distinct parent_id from hr_employee where id in ('+','.join(map(str, ids))+')') + cr.execute('select distinct parent_id from hr_employee where id =ANY(%s)',(ids,)) ids = filter(None, map(lambda x:x[0], cr.fetchall())) if not level: return False level -= 1 return True - + _constraints = [ (_check_recursion, 'Error ! You cannot create recursive Hierarchy of Employees.', ['parent_id']) ] - + hr_employee() class hr_timesheet(osv.osv): diff --git a/addons/hr/hr_department.py b/addons/hr/hr_department.py index 8c424fab8a6..e329f7b5991 100644 --- a/addons/hr/hr_department.py +++ b/addons/hr/hr_department.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 . # ############################################################################## @@ -43,7 +43,7 @@ class hr_department(osv.osv): def _check_recursion(self, cr, uid, ids): level = 100 while len(ids): - cr.execute('select distinct parent_id from hr_department where id in ('+','.join(map(str, ids))+')') + cr.execute('select distinct parent_id from hr_department where id =ANY(%s)',(ids,)) ids = filter(None, map(lambda x:x[0], cr.fetchall())) if not level: return False @@ -117,12 +117,12 @@ class res_users(osv.osv): ids_dept = obj_dept.search(cr, uid, [('id', 'child_of', mgnt_dept_ids)]) if ids_dept: data_dept = obj_dept.read(cr, uid, ids_dept, ['member_ids']) - childs = map(lambda x: x['member_ids'], data_dept) + childs = map(lambda x: x['member_ids'], data_dept) childs = tools.flatten(childs) - childs = obj_user.search(cr, uid, [('id','in',childs),('active','=',True)]) + childs = obj_user.search(cr, uid, [('id','in',childs),('active','=',True)]) if manager_id in childs: childs.remove(manager_id) - + child_ids.extend(tools.flatten(childs)) set = {} map(set.__setitem__, child_ids, []) From ad4f44dfb7c98df1d92b545f3945e165d53296ca Mon Sep 17 00:00:00 2001 From: "nch@tinyerp.com" <> Date: Thu, 26 Nov 2009 17:50:57 +0530 Subject: [PATCH 29/53] [IMP]:event_project sql queries to parameterized query bzr revid: nch@tinyerp.com-20091126122057-7rbcaa5nz7a3t9ty --- addons/event_project/event.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/addons/event_project/event.py b/addons/event_project/event.py index 055253ef3ec..98f5e2420eb 100644 --- a/addons/event_project/event.py +++ b/addons/event_project/event.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 . # ############################################################################## @@ -36,8 +36,8 @@ class one2many_mod_task(fields.one2many): for id in ids: res[id] = [] for id in ids: - query = "select project_id from event_event where id = %i" %id - cr.execute(query) + query = "select project_id from event_event where id = %s" + cr.execute(query,(id,)) project_ids = [ x[0] for x in cr.fetchall()] ids2 = obj.pool.get(self._obj).search(cr, user, [(self._fields_id,'in',project_ids),('state','<>','done')], limit=self._limit) for r in obj.pool.get(self._obj)._read_flat(cr, user, ids2, [self._fields_id], context=context, load='_classic_write'): From 49903fbd8ed881f50544e46585b52c61b358b6f7 Mon Sep 17 00:00:00 2001 From: "nch@tinyerp.com" <> Date: Thu, 26 Nov 2009 18:00:42 +0530 Subject: [PATCH 30/53] [IMP]:event sql queries to parameterized query bzr revid: nch@tinyerp.com-20091126123042-n2pz0u0vv4sjirxr --- addons/event/event.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/addons/event/event.py b/addons/event/event.py index e3595987c7d..47016273783 100644 --- a/addons/event/event.py +++ b/addons/event/event.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 . # ############################################################################## @@ -76,8 +76,8 @@ class event(osv.osv): def _get_register(self, cr, uid, ids, name, args, context=None): res={} for event in self.browse(cr, uid, ids, context): - query = """select sum(nb_register) from crm_case c left join crm_case_section s on (c.section_id=s.id) right join event_event e on (e.section_id=s.id) right join event_registration r on (r.case_id=c.id) where e.section_id = %s and c.state in ('open','done')""" % event.section_id.id - cr.execute(query) + query = """select sum(nb_register) from crm_case c left join crm_case_section s on (c.section_id=s.id) right join event_event e on (e.section_id=s.id) right join event_registration r on (r.case_id=c.id) where e.section_id = %s and c.state in ('open','done')""" + cr.execute(query,(event.section_id.id,)) res2 = cr.fetchone() if res2 and res2[0]: res[event.id] = res2[0] @@ -88,8 +88,8 @@ class event(osv.osv): def _get_prospect(self, cr, uid, ids, name, args, context=None): res={} for event in self.browse(cr, uid, ids, context): - query = """select sum(nb_register) from crm_case c left join crm_case_section s on (c.section_id=s.id) right join event_event e on (e.section_id=s.id) right join event_registration r on (r.case_id=c.id) where e.section_id = %s and c.state = 'draft'""" % event.section_id.id - cr.execute(query) + query = """select sum(nb_register) from crm_case c left join crm_case_section s on (c.section_id=s.id) right join event_event e on (e.section_id=s.id) right join event_registration r on (r.case_id=c.id) where e.section_id = %s and c.state = 'draft'""" + cr.execute(query,(event.section_id.id,)) res2 = cr.fetchone() if res2 and res2[0]: res[event.id] = res2[0] From 5d8cedeb35e92650904693d30094c606c2b9719b Mon Sep 17 00:00:00 2001 From: "nch@tinyerp.com" <> Date: Thu, 26 Nov 2009 18:09:16 +0530 Subject: [PATCH 31/53] [IMP]:document sql queries to parameterized query bzr revid: nch@tinyerp.com-20091126123916-0xu24h028ctr9vqz --- addons/document/document.py | 54 +++++++++---------- addons/document/ftpserver/abstracted_fs.py | 60 +++++++++++----------- 2 files changed, 57 insertions(+), 57 deletions(-) diff --git a/addons/document/document.py b/addons/document/document.py index 3ce6a9d700f..81352c280a2 100644 --- a/addons/document/document.py +++ b/addons/document/document.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 . # ############################################################################## @@ -99,7 +99,7 @@ class node_class(object): if content.include_name: content_name = self.object2.name obj = pool.get(self.object.ressource_type_id.model) - name_for = obj._name.split('.')[-1] + name_for = obj._name.split('.')[-1] if content_name and content_name.find(name_for) == 0 : content_name = content_name.replace(name_for,'') test_nodename = content_name + (content.suffix or '') + (content.extension or '') @@ -121,17 +121,17 @@ class node_class(object): ids += fobj.search(self.cr, self.uid, where+[ ('parent_id','=',False) ]) res = fobj.browse(self.cr, self.uid, ids, context=self.context) return map(lambda x: node_class(self.cr, self.uid, self.path+'/'+eval('x.'+fobj._rec_name), x, False, context=self.context, type='file', root=False), res) + res2 - + def get_translation(self,value,lang): result = value - #TODO : to get translation term - return result - + #TODO : to get translation term + return result + def directory_list_for_child(self,nodename,parent=False): pool = pooler.get_pool(self.cr.dbname) where = [] - if nodename: - nodename = self.get_translation(nodename, self.context['lang']) + if nodename: + nodename = self.get_translation(nodename, self.context['lang']) where.append(('name','=',nodename)) if (self.object and self.object.type=='directory') or not self.object2: where.append(('parent_id','=',self.object and self.object.id or False)) @@ -144,11 +144,11 @@ class node_class(object): ids = pool.get('document.directory').search(self.cr, self.uid, where+[('ressource_id','=',0)]) if self.object2: - ids += pool.get('document.directory').search(self.cr, self.uid, where+[('ressource_id','=',self.object2.id)]) + ids += pool.get('document.directory').search(self.cr, self.uid, where+[('ressource_id','=',self.object2.id)]) res = pool.get('document.directory').browse(self.cr, self.uid, ids, self.context) return res - def _child_get(self, nodename=False): + def _child_get(self, nodename=False): if self.type not in ('collection','database'): return [] res = self.directory_list_for_child(nodename) @@ -165,13 +165,13 @@ class node_class(object): result +=map(lambda x: node_class(self.cr, self.uid, self.path+'/'+eval('x.'+fobj._rec_name), x, False, context=self.context, type='file', root=self.root), res) if self.type=='collection' and self.object.type=="ressource": where = self.object.domain and eval(self.object.domain, {'active_id':self.root, 'uid':self.uid}) or [] - pool = pooler.get_pool(self.cr.dbname) + pool = pooler.get_pool(self.cr.dbname) obj = pool.get(self.object.ressource_type_id.model) _dirname_field = obj._rec_name if len(obj.fields_get(self.cr, self.uid, ['dirname'])): - _dirname_field = 'dirname' + _dirname_field = 'dirname' - name_for = obj._name.split('.')[-1] + name_for = obj._name.split('.')[-1] if nodename and nodename.find(name_for) == 0 : id = int(nodename.replace(name_for,'')) where.append(('id','=',id)) @@ -185,7 +185,7 @@ class node_class(object): where.append((_dirname_field,'=',nodename)) if self.object.ressource_tree: - if obj._parent_name in obj.fields_get(self.cr,self.uid): + if obj._parent_name in obj.fields_get(self.cr,self.uid): where.append((obj._parent_name,'=',self.object2 and self.object2.id or False)) ids = obj.search(self.cr, self.uid, where) res = obj.browse(self.cr, self.uid, ids,self.context) @@ -198,25 +198,25 @@ class node_class(object): if self.object2: return result - + ids = obj.search(self.cr, self.uid, where) res = obj.browse(self.cr, self.uid, ids,self.context) - for r in res: + for r in res: if len(obj.fields_get(self.cr, self.uid, [_dirname_field])): r.name = eval('r.'+_dirname_field) else: r.name = False if not r.name: - r.name = name_for + '%d'%r.id + r.name = name_for + '%d'%r.id for invalid in INVALID_CHARS: if r.name.find(invalid) : - r.name = r.name.replace(invalid,INVALID_CHARS[invalid]) + r.name = r.name.replace(invalid,INVALID_CHARS[invalid]) result2 = map(lambda x: node_class(self.cr, self.uid, self.path+'/'+x.name.replace('/','__'), self.object, x, context=self.context, root=x.id), res) if result2: if self.object.ressource_tree: result += result2 else: - result = result2 + result = result2 return result def children(self): @@ -301,7 +301,7 @@ class document_directory(osv.osv): def _check_recursion(self, cr, uid, ids): level = 100 while len(ids): - cr.execute('select distinct parent_id from document_directory where id in ('+','.join(map(str, ids))+')') + cr.execute('select distinct parent_id from document_directory where id =ANY(%s)',(ids,)) ids = filter(None, map(lambda x:x[0], cr.fetchall())) if not level: return False @@ -336,9 +336,9 @@ class document_directory(osv.osv): object: the object.directory or object.directory.content object2: the other object linked (if object.directory.content) """ - def get_object(self, cr, uid, uri, context={}): - #TODO : set user's context_lang in context - context.update({'lang':False}) + def get_object(self, cr, uid, uri, context={}): + #TODO : set user's context_lang in context + context.update({'lang':False}) if not uri: return node_class(cr, uid, '', False, context=context, type='database') turi = tuple(uri) @@ -523,7 +523,7 @@ class document_file(osv.osv): def _data_get(self, cr, uid, ids, name, arg, context): result = {} - cr.execute('select id,store_fname,link from ir_attachment where id in ('+','.join(map(str, ids))+')') + cr.execute('select id,store_fname,link from ir_attachment where id =ANY(%s)',(ids,)) for id,r,l in cr.fetchall(): try: value = file(os.path.join(self._get_filestore(cr), r), 'rb').read() @@ -544,7 +544,7 @@ class document_file(osv.osv): os.unlink(os.path.join(self._get_filestore(cr), filename)) except: pass - cr.execute('update ir_attachment set store_fname=NULL WHERE id=%s', (id,) ) + cr.execute('update ir_attachment set store_fname=NULL WHERE id=%s',(id,)) return True #if (not context) or context.get('store_method','fs')=='fs': try: @@ -687,7 +687,7 @@ class document_file(osv.osv): datas=base64.encodestring(urllib.urlopen(vals['link']).read()) else: datas = vals.get('datas',False) - + vals['file_size']= datas and len(datas) or 0 if not self._check_duplication(cr,uid,vals): raise except_orm(_('ValidateError'), _('File name must be unique!')) diff --git a/addons/document/ftpserver/abstracted_fs.py b/addons/document/ftpserver/abstracted_fs.py index 21b38d7dc4f..7779e208739 100644 --- a/addons/document/ftpserver/abstracted_fs.py +++ b/addons/document/ftpserver/abstracted_fs.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 . # ############################################################################## @@ -77,9 +77,9 @@ def _to_decode(s): try: return s.decode('ascii') except UnicodeError: - return s - - + return s + + class file_wrapper(StringIO.StringIO): def __init__(self, sstr='', ressource_id=False, dbname=None, uid=1, name=''): StringIO.StringIO.__init__(self, sstr) @@ -153,7 +153,7 @@ class abstracted_fs: cr.execute("SELECT 1 FROM pg_class WHERE relkind = 'r' AND relname = 'ir_module_module'") if not cr.fetchone(): continue - + cr.execute("select id from ir_module_module where name like 'document%' and state='installed' ") res = cr.fetchone() if res and len(res): @@ -165,7 +165,7 @@ class abstracted_fs: if cr is not None: cr.close() #if db is not None: - # pooler.close_db(db_name) + # pooler.close_db(db_name) return self.db_name_list # Ok @@ -210,10 +210,10 @@ class abstracted_fs: def ftp2fs(self, path_orig, data): path = self.ftpnorm(path_orig) if not data or (path and path=='/'): - return None + return None path2 = filter(None,path.split('/'))[1:] (cr, uid, pool) = data - if len(path2): + if len(path2): path2[-1]=_to_unicode(path2[-1]) res = pool.get('document.directory').get_object(cr, uid, path2[:]) if not res: @@ -221,15 +221,15 @@ class abstracted_fs: return res # Ok - def fs2ftp(self, node): + def fs2ftp(self, node): res='/' if node: res=os.path.normpath(node.path) - res = res.replace("\\", "/") + res = res.replace("\\", "/") while res[:2] == '//': res = res[1:] - res='/' + node.cr.dbname + '/' + _to_decode(res) - + res='/' + node.cr.dbname + '/' + _to_decode(res) + #res = node and ('/' + node.cr.dbname + '/' + _to_decode(self.ftpnorm(node.path))) or '/' return res @@ -309,7 +309,7 @@ class abstracted_fs: s = file_wrapper('', cid, cr.dbname, uid, ) return s - except Exception,e: + except Exception,e: log(e) raise OSError(1, 'Operation not permited.') @@ -372,7 +372,7 @@ class abstracted_fs: # Ok - def chdir(self, path): + def chdir(self, path): if not path: self.cwd='/' return None @@ -400,7 +400,7 @@ class abstracted_fs: 'ressource_parent_type_id': object and object.ressource_type_id.id or False, 'ressource_id': object2 and object2.id or False } - if (object and (object.type in ('directory'))) or not object2: + if (object and (object.type in ('directory'))) or not object2: val['parent_id'] = object and object.id or False # Check if it alreayd exists ! pool.get('document.directory').create(cr, uid, val) @@ -448,8 +448,8 @@ class abstracted_fs: try: uid = security.login(db, self.username, self.password) if uid: - result.append(false_node(db)) - except osv.except_osv: + result.append(false_node(db)) + except osv.except_osv: pass return result return path.children() @@ -535,11 +535,11 @@ class abstracted_fs: ressource_type_id = pool.get('ir.model').search(cr,uid,[('model','=',dst_basedir.object2._name)])[0] ressource_id = dst_basedir.object2.id title = dst_basedir.object2.name - ressource_model = dst_basedir.object2._name + ressource_model = dst_basedir.object2._name if dst_basedir.object2._name=='res.partner': partner_id=dst_basedir.object2.id else: - obj2=pool.get(dst_basedir.object2._name) + obj2=pool.get(dst_basedir.object2._name) partner_id= obj2.fields_get(cr,uid,['partner_id']) and dst_basedir.object2.partner_id.id or False else: ressource_type_id = False @@ -560,7 +560,7 @@ class abstracted_fs: } pool.get('ir.attachment').write(cr, uid, result['attachment'], val) if (not val['res_id']) and result['attachment']: - dst_basedir.cr.execute('update ir_attachment set res_id=NULL where id in ('+','.join(map(str,result['attachment']))+')') + dst_basedir.cr.execute('update ir_attachment set res_id=NULL where id =ANY(%s)',(result['attachment'],)) cr.commit() elif src.type=='file': @@ -586,7 +586,7 @@ class abstracted_fs: if dst_basedir.object2._name=='res.partner': val['partner_id']=dst_basedir.object2.id else: - obj2=pool.get(dst_basedir.object2._name) + obj2=pool.get(dst_basedir.object2._name) val['partner_id']= obj2.fields_get(src.cr, src.uid,['partner_id']) and dst_basedir.object2.partner_id.id or False elif src.object.res_id: # I had to do that because writing False to an integer writes 0 instead of NULL @@ -700,7 +700,7 @@ class abstracted_fs: def get_list_dir(self, path): """"Return an iterator object that yields a directory listing in a form suitable for LIST command. - """ + """ if self.isdir(path): listing = self.listdir(path) #listing.sort() @@ -735,7 +735,7 @@ class abstracted_fs: listing.sort() return self.format_list(basedir, listing) - # Ok + # Ok def format_list(self, basedir, listing, ignore_err=True): """Return an iterator object that yields the entries of given directory emulating the "/bin/ls -lA" UNIX command output. @@ -774,13 +774,13 @@ class abstracted_fs: # stat.st_mtime could fail (-1) if last mtime is too old # in which case we return the local time as last mtime try: - mname=_get_month_name(time.strftime("%m", time.localtime(st.st_mtime))) + mname=_get_month_name(time.strftime("%m", time.localtime(st.st_mtime))) mtime = mname+' '+time.strftime("%d %H:%M", time.localtime(st.st_mtime)) except ValueError: mname=_get_month_name(time.strftime("%m")) - mtime = mname+' '+time.strftime("%d %H:%M") - # formatting is matched with proftpd ls output - path=_to_decode(file.path) #file.path.encode('ascii','replace').replace('?','_') + mtime = mname+' '+time.strftime("%d %H:%M") + # formatting is matched with proftpd ls output + path=_to_decode(file.path) #file.path.encode('ascii','replace').replace('?','_') yield "%s %3s %-8s %-8s %8s %s %s\r\n" %(perms, nlinks, uname, gname, size, mtime, path.split('/')[-1]) @@ -818,7 +818,7 @@ class abstracted_fs: if 'd' in perms: permdir += 'p' type = size = perm = modify = create = unique = mode = uid = gid = "" - for file in listing: + for file in listing: try: st = self.stat(file) except OSError: @@ -828,7 +828,7 @@ class abstracted_fs: # type + perm if stat.S_ISDIR(st.st_mode): if 'type' in facts: - type = 'type=dir;' + type = 'type=dir;' if 'perm' in facts: perm = 'perm=%s;' %permdir else: From 4f78616ccc05d93985e95189bfa2bae2dbf0128d Mon Sep 17 00:00:00 2001 From: "nch@tinyerp.com" <> Date: Thu, 26 Nov 2009 18:37:24 +0530 Subject: [PATCH 32/53] [IMP]:crm_profiling sql queries to parameterized query bzr revid: nch@tinyerp.com-20091126130724-l1zbrv8m5agursha --- addons/crm_profiling/crm_profiling.py | 28 +++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/addons/crm_profiling/crm_profiling.py b/addons/crm_profiling/crm_profiling.py index ebf9d3ac7c5..1ec2430b840 100644 --- a/addons/crm_profiling/crm_profiling.py +++ b/addons/crm_profiling/crm_profiling.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 . # ############################################################################## @@ -28,17 +28,17 @@ def _get_answers(cr, uid, ids): query = """ select distinct(answer) from profile_question_yes_rel - where profile in (%s)"""% ','.join([str(i) for i in ids ]) + where profile=ANY(%s)""" - cr.execute(query) + cr.execute(query,(ids,)) ans_yes = [x[0] for x in cr.fetchall()] query = """ select distinct(answer) from profile_question_no_rel - where profile in (%s)"""% ','.join([str(i) for i in ids ]) + where profile=ANY(%s)""" - cr.execute(query) + cr.execute(query,(ids,)) ans_no = [x[0] for x in cr.fetchall()] return [ans_yes, ans_no] @@ -50,7 +50,7 @@ def _get_parents(cr, uid, ids): select distinct(parent_id) from crm_segmentation where parent_id is not null - and id in (%s)""" % ','.join([str(i) for i in ids ])) + and id=ANY(%s)""",(ids,)) parent_ids = [x[0] for x in cr.fetchall()] @@ -88,17 +88,17 @@ def test_prof(cr, uid, seg_id, pid, answers_ids = []): def _recompute_categ(self, cr, uid, pid, answers_ids): ok = [] cr.execute(''' - select r.category_id - from res_partner_category_rel r left join crm_segmentation s on (r.category_id = s.categ_id) + select r.category_id + from res_partner_category_rel r left join crm_segmentation s on (r.category_id = s.categ_id) where r.partner_id = %s and (s.exclusif = false or s.exclusif is null) ''', (pid,)) for x in cr.fetchall(): ok.append(x[0]) query = ''' - select id, categ_id - from crm_segmentation - where profiling_active = true''' + select id, categ_id + from crm_segmentation + where profiling_active = true''' if ok != []: query = query +''' and categ_id not in(%s)'''% ','.join([str(i) for i in ok ]) query = query + ''' order by id ''' @@ -140,7 +140,7 @@ class questionnaire(osv.osv): for name, oid in result: quest_form = quest_form + '' % (oid,) quest_fields['quest_form%d' % (oid,)] = {'string': name, 'type': 'many2one', 'relation': 'crm_profiling.answer', 'domain': [('question_id','=',oid)] } - quest_form = quest_form + '''''' + quest_form = quest_form + '''''' return quest_form, quest_fields _columns = { @@ -213,7 +213,7 @@ class crm_segmentation(osv.osv): if categ['exclusif']: cr.execute('delete from res_partner_category_rel where category_id=%s', (categ['categ_id'][0],)) - id = categ['id'] + id = categ['id'] cr.execute('select id from res_partner order by id ') partners = [x[0] for x in cr.fetchall()] From 76e3ad82ca7a1df003809b0a2844fb40c1f033ce Mon Sep 17 00:00:00 2001 From: "nch@tinyerp.com" <> Date: Fri, 27 Nov 2009 14:47:12 +0530 Subject: [PATCH 33/53] [IMP]:crm sql queries to parameterized query bzr revid: nch@tinyerp.com-20091127091712-t7hk74vdjkg2n2oi --- addons/crm/crm.py | 172 ++++++++++++------------ addons/crm/report/report_businessopp.py | 7 +- 2 files changed, 89 insertions(+), 90 deletions(-) diff --git a/addons/crm/crm.py b/addons/crm/crm.py index 4b246a0665b..8a620d9a9d5 100755 --- a/addons/crm/crm.py +++ b/addons/crm/crm.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 . # ############################################################################## @@ -75,8 +75,8 @@ class crm_case_section(osv.osv): 'parent_id': fields.many2one('crm.case.section', 'Parent Section'), 'child_ids': fields.one2many('crm.case.section', 'parent_id', 'Child Sections'), "gateway_ids" : fields.one2many("crm.email.gateway",'section_id',"Email Gateway"), - 'calendar' : fields.boolean('Calendar', help='Allow to show calendar'), - + 'calendar' : fields.boolean('Calendar', help='Allow to show calendar'), + } _defaults = { 'active': lambda *a: 1, @@ -88,7 +88,7 @@ class crm_case_section(osv.osv): def _check_recursion(self, cr, uid, ids): level = 100 while len(ids): - cr.execute('select distinct parent_id from crm_case_section where id in ('+','.join(map(str, ids))+')') + cr.execute('select distinct parent_id from crm_case_section where id =ANY(%s)',(ids,)) ids = filter(None, map(lambda x:x[0], cr.fetchall())) if not level: return False @@ -212,37 +212,37 @@ crm_case_section() class crm_email_gateway_server(osv.osv): _name = "crm.email.gateway.server" - _description = "Email Gateway Server" + _description = "Email Gateway Server" _columns = { 'name': fields.char('Server Address',size=64,required=True ,help="IMAP/POP Address Of Email gateway Server"), 'login': fields.char('User',size=64,required=True,help="User Login Id of Email gateway"), - 'password': fields.char('Password',size=64,required=True,help="User Password Of Email gateway"), - 'server_type': fields.selection([("pop","POP"),("imap","Imap")],"Type of Server", required=True, help="Type of Email gateway Server"), + 'password': fields.char('Password',size=64,required=True,help="User Password Of Email gateway"), + 'server_type': fields.selection([("pop","POP"),("imap","Imap")],"Type of Server", required=True, help="Type of Email gateway Server"), 'port': fields.integer("Port" , help="Port Of Email gateway Server. If port is omitted, the standard POP3 port (110) is used for POP EMail Server and the standard IMAP4 port (143) is used for IMAP Sever."), 'ssl': fields.boolean('SSL',help ="Use Secure Authentication"), - 'active': fields.boolean('Active'), + 'active': fields.boolean('Active'), + } + _defaults = { + 'server_type':lambda * a:'pop', + 'active':lambda * a:True, } - _defaults = { - 'server_type':lambda * a:'pop', - 'active':lambda * a:True, - } crm_email_gateway_server() - + class crm_email_gateway(osv.osv): _name = "crm.email.gateway" _description = "Email Gateway" - + _columns = { 'name': fields.char('Name',size=64,help="Name of Mail Gateway."), 'server_id': fields.many2one('crm.email.gateway.server',"Gateway Server", required=True), 'to_email_id': fields.char('TO', size=64, help="Email address used in the From field of outgoing messages"), - 'cc_email_id': fields.char('CC',size=64,help="Default eMail in case of any trouble."), - 'section_id': fields.many2one('crm.case.section',"Section",required=True), + 'cc_email_id': fields.char('CC',size=64,help="Default eMail in case of any trouble."), + 'section_id': fields.many2one('crm.case.section',"Section",required=True), 'mail_history': fields.one2many("crm.email.history","gateway_id","History", readonly=True) - } - + } + def _fetch_mails(self, cr, uid, ids=False, context={}): ''' Function called by the scheduler to fetch mails @@ -250,36 +250,36 @@ class crm_email_gateway(osv.osv): cr.execute('select * from crm_email_gateway gateway \ inner join crm_email_gateway_server server \ on server.id = gateway.server_id where server.active = True') - ids2 = map(lambda x: x[0], cr.fetchall() or []) + ids2 = map(lambda x: x[0], cr.fetchall() or []) return self.fetch_mails(cr, uid, ids=ids2, context=context) - - def parse_mail(self, cr, uid, gateway_id, email_message, email_parser=None, context={}): - msg_id = case_id = note = False - user_obj = self.pool.get('res.users') - mail_history_obj = self.pool.get('crm.email.history') + + def parse_mail(self, cr, uid, gateway_id, email_message, email_parser=None, context={}): + msg_id = case_id = note = False + user_obj = self.pool.get('res.users') + mail_history_obj = self.pool.get('crm.email.history') users = user_obj.read(cr, uid, uid, ['password']) mailgateway = self.browse(cr, uid, gateway_id, context=context) try : if not email_parser: - email_parser = openerp_mailgate.email_parser(uid, users['password'], mailgateway.section_id.id, - mailgateway.to_email_id or '', mailgateway.cc_email_id or '', dbname=cr.dbname, - host=tools.config['interface'] or 'localhost', port=tools.config['port'] or '8069') - - msg_txt = email.message_from_string(email_message) - msg_id = msg_txt['Message-ID'] - case_id = email_parser.parse(msg_txt)[0] + email_parser = openerp_mailgate.email_parser(uid, users['password'], mailgateway.section_id.id, + mailgateway.to_email_id or '', mailgateway.cc_email_id or '', dbname=cr.dbname, + host=tools.config['interface'] or 'localhost', port=tools.config['port'] or '8069') + + msg_txt = email.message_from_string(email_message) + msg_id = msg_txt['Message-ID'] + case_id = email_parser.parse(msg_txt)[0] except Exception, e: - note = "Error in Parsing Mail: %s " %(str(e)) - netsvc.Logger().notifyChannel('Emailgate:Parsing mail:%s' % (mailgateway.name or + note = "Error in Parsing Mail: %s " %(str(e)) + netsvc.Logger().notifyChannel('Emailgate:Parsing mail:%s' % (mailgateway.name or '%s (%s)'%(mailgateway.server_id.login, mailgateway.server_id.name)), netsvc.LOG_ERROR, str(e)) - - mail_history_obj.create(cr, uid, {'name':msg_id, 'case_id': case_id, 'gateway_id':mailgateway.id, 'note':note}) + + mail_history_obj.create(cr, uid, {'name':msg_id, 'case_id': case_id, 'gateway_id':mailgateway.id, 'note':note}) return case_id,note - - def fetch_mails(self, cr, uid, ids=[], section_ids=[], context={}): + + def fetch_mails(self, cr, uid, ids=[], section_ids=[], context={}): if len(section_ids): - casesection_obj = self.pool.get('crm.case.section') - for section in casesection_obj.read(cr, uid, section_ids, ['gateway_ids']): + casesection_obj = self.pool.get('crm.case.section') + for section in casesection_obj.read(cr, uid, section_ids, ['gateway_ids']): ids += section['gateway_ids'] log_messages = [] for mailgateway in self.browse(cr, uid, ids): @@ -287,58 +287,58 @@ class crm_email_gateway(osv.osv): mailgate_server = mailgateway.server_id if not mailgate_server.active: continue - mailgate_name = mailgateway.name or "%s (%s)" % (mailgate_server.login, mailgate_server.name) + mailgate_name = mailgateway.name or "%s (%s)" % (mailgate_server.login, mailgate_server.name) log_messages.append("Mail Server : %s" % mailgate_name) - log_messages.append("="*40) - new_messages = [] + log_messages.append("="*40) + new_messages = [] if mailgate_server.server_type == 'pop': if mailgate_server.ssl: pop_server = POP3_SSL(mailgate_server.name or 'localhost', mailgate_server.port or 110) else: - pop_server = POP3(mailgate_server.name or 'localhost', mailgate_server.port or 110) + pop_server = POP3(mailgate_server.name or 'localhost', mailgate_server.port or 110) pop_server.user(mailgate_server.login) pop_server.pass_(mailgate_server.password) pop_server.list() - (numMsgs, totalSize) = pop_server.stat() - for i in range(1, numMsgs + 1): - (header, msges, octets) = pop_server.retr(i) + (numMsgs, totalSize) = pop_server.stat() + for i in range(1, numMsgs + 1): + (header, msges, octets) = pop_server.retr(i) case_id, note = self.parse_mail(cr, uid, mailgateway.id, '\n'.join(msges)) - log = '' + log = '' if case_id: log = _('Case Successfull Created : %d'% case_id) - if note: - log = note + if note: + log = note log_messages.append(log) new_messages.append(i) - pop_server.quit() - + pop_server.quit() + elif mailgate_server.server_type == 'imap': if mailgate_server.ssl: imap_server = IMAP4_SSL(mailgate_server.name or 'localhost', mailgate_server.port or 143) else: - imap_server = IMAP4(mailgate_server.name or 'localhost', mailgate_server.port or 143) + imap_server = IMAP4(mailgate_server.name or 'localhost', mailgate_server.port or 143) imap_server.login(mailgate_server.login, mailgate_server.password) imap_server.select() typ, data = imap_server.search(None, '(UNSEEN)') - for num in data[0].split(): - typ, data = imap_server.fetch(num, '(RFC822)') + for num in data[0].split(): + typ, data = imap_server.fetch(num, '(RFC822)') case_id, note = self.parse_mail(cr, uid, mailgateway.id, data[0][1]) - log = '' + log = '' if case_id: log = 'Case Successfully Created : %d'% case_id - if note: - log = note + if note: + log = note log_messages.append(log) new_messages.append(num) imap_server.close() imap_server.logout() - - except Exception, e: - log_messages.append("Error in Fetching Mail: %s " %(str(e))) + + except Exception, e: + log_messages.append("Error in Fetching Mail: %s " %(str(e))) netsvc.Logger().notifyChannel('Emailgate:Fetching mail:[%d]%s' % (mailgate_server.id, mailgate_server.name), netsvc.LOG_ERROR, str(e)) - - log_messages.append("-"*25) - log_messages.append("Total Read Mail: %d\n\n" %(len(new_messages))) + + log_messages.append("-"*25) + log_messages.append("Total Read Mail: %d\n\n" %(len(new_messages))) return log_messages crm_email_gateway() @@ -507,7 +507,7 @@ class crm_case(osv.osv): 'date_deadline': fields.datetime('Deadline'), 'date_closed': fields.datetime('Closed', readonly=True), 'canal_id': fields.many2one('res.partner.canal', 'Channel',help="The channels represent the different communication modes available with the customer." \ - " With each commercial opportunity, you can indicate the canall which is this opportunity source."), + " With each commercial opportunity, you can indicate the canall which is this opportunity source."), 'user_id': fields.many2one('res.users', 'Responsible'), 'history_line': fields.one2many('crm.case.history', 'case_id', 'Communication', readonly=1), 'log_ids': fields.one2many('crm.case.log', 'case_id', 'Logs History', readonly=1), @@ -599,9 +599,9 @@ class crm_case(osv.osv): _result = ptrn.search(str(case.name)) if not _result: result_name = False - regex_n = not reg_name or result_name + regex_n = not reg_name or result_name ok = ok and regex_n - + reg_history = action.regex_history result_history = True if reg_history: @@ -610,9 +610,9 @@ class crm_case(osv.osv): _result = ptrn.search(str(case.history_line[0].description)) if not _result: result_history = False - regex_h = not reg_history or result_history + regex_h = not reg_history or result_history ok = ok and regex_h - + if not ok: continue @@ -652,7 +652,7 @@ class crm_case(osv.osv): if ok: if action.server_action_id: context.update({'active_id':case.id,'active_ids':[case.id]}) - self.pool.get('ir.actions.server').run(cr, uid, [action.server_action_id.id], context) + self.pool.get('ir.actions.server').run(cr, uid, [action.server_action_id.id], context) write = {} if action.act_state: case.state = action.act_state @@ -694,7 +694,7 @@ class crm_case(osv.osv): emails += (action.act_mail_to_email or '').split(',') emails = filter(None, emails) if len(emails) and action.act_mail_body: - emails = list(set(emails)) + emails = list(set(emails)) self.email_send(cr, uid, case, emails, action.act_mail_body) break action_ids = newactions @@ -800,10 +800,10 @@ class crm_case(osv.osv): if not case.section_id.reply_to: raise osv.except_osv(_('Error!'),("Reply TO is not specified in Section")) if not case.email_from: - raise osv.except_osv(_('Error!'),("Partner Email is not specified in Case")) + raise osv.except_osv(_('Error!'),("Partner Email is not specified in Case")) if case.section_id.reply_to and case.email_from: src = case.email_from - + dest = case.section_id.reply_to body = case.email_last or case.description if not destination: @@ -818,7 +818,7 @@ class crm_case(osv.osv): attach_ids = self.pool.get('ir.attachment').search(cr, uid, [('res_model', '=', 'crm.case'), ('res_id', '=', case.id)]) attach_to_send = self.pool.get('ir.attachment').read(cr, uid, attach_ids, ['datas_fname','datas']) attach_to_send = map(lambda x: (x['datas_fname'], base64.decodestring(x['datas'])), attach_to_send) - + # Send an email flag = tools.email_send( src, @@ -830,8 +830,8 @@ class crm_case(osv.osv): attach=attach_to_send ) if flag: - raise osv.except_osv(_('Email!'),("Email Successfully Sent")) - else: + raise osv.except_osv(_('Email!'),("Email Successfully Sent")) + else: raise osv.except_osv(_('Email Fail!'),("Email is not sent successfully")) return True @@ -874,12 +874,12 @@ class crm_case(osv.osv): body = case.description or '' if case.user_id.signature: body += '\n\n%s' % (case.user_id.signature) - + emailfrom = case.user_id.address_id and case.user_id.address_id.email or False if not emailfrom: raise osv.except_osv(_('Error!'), _("No E-Mail ID Found for your Company address!")) - + tools.email_send( emailfrom, emails, @@ -1055,7 +1055,7 @@ class crm_email_add_cc_wizard(osv.osv_memory): 'email': fields.char('Email', size=32), 'subject': fields.char('Subject', size=32), } - + def change_email(self, cr, uid, ids, user, partner): if (not partner and not user): return {'value':{'email': False}} @@ -1069,8 +1069,8 @@ class crm_email_add_cc_wizard(osv.osv_memory): if addr: email = self.pool.get('res.partner.address').read(cr, uid,addr[0] , ['email'])['email'] return {'value':{'email': email}} - - + + def add_cc(self, cr, uid, ids, context={}): data = self.read(cr, uid, ids[0]) email = data['email'] @@ -1081,7 +1081,7 @@ class crm_email_add_cc_wizard(osv.osv_memory): history_line = self.pool.get('crm.case.history').browse(cr, uid, context['active_id']) crm_case = self.pool.get('crm.case') case = history_line.log_id.case_id - body = history_line.description.replace('\n','\n> ') + body = history_line.description.replace('\n','\n> ') flag = tools.email_send( case.user_id.address_id.email, [case.email_from], @@ -1091,11 +1091,11 @@ class crm_email_add_cc_wizard(osv.osv_memory): tinycrm=str(case.id) ) if flag: - crm_case.write(cr, uid, case.id, {'email_cc' : case.email_cc and case.email_cc +','+ email or email}) - else: - raise osv.except_osv(_('Email Fail!'),("Lastest Email is not sent successfully")) + crm_case.write(cr, uid, case.id, {'email_cc' : case.email_cc and case.email_cc +','+ email or email}) + else: + raise osv.except_osv(_('Email Fail!'),("Lastest Email is not sent successfully")) return {} - + crm_email_add_cc_wizard() # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/crm/report/report_businessopp.py b/addons/crm/report/report_businessopp.py index fb54dc88b18..735d764db70 100644 --- a/addons/crm/report/report_businessopp.py +++ b/addons/crm/report/report_businessopp.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 . # ############################################################################## @@ -55,9 +55,8 @@ class report_custom(report_int): minbenef = 999999999999999999999 maxbenef = 0 - cr.execute('select probability, planned_revenue, planned_cost, user_id, res_users.name as name from crm_case left join res_users on (crm_case.user_id=res_users.id) where crm_case.id in ('+','.join(map(str, ids))+') order by user_id') + cr.execute('select probability, planned_revenue, planned_cost, user_id, res_users.name as name from crm_case left join res_users on (crm_case.user_id=res_users.id) where crm_case.id =ANY(%s) order by user_id',(ids,)) res = cr.dictfetchall() - for row in res: proba = row['probability'] or 0 / 100.0 cost = row['planned_cost'] or 0 From 500eb8a77f9d183c777b77cea8c5bc3274004100 Mon Sep 17 00:00:00 2001 From: "nch@tinyerp.com" <> Date: Fri, 27 Nov 2009 14:55:21 +0530 Subject: [PATCH 34/53] [IMP]:board sql queries to parameterized query bzr revid: nch@tinyerp.com-20091127092521-333d1oe7md5qoh0l --- addons/board/board.py | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/addons/board/board.py b/addons/board/board.py index 6238da69a46..529c3c16763 100644 --- a/addons/board/board.py +++ b/addons/board/board.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 . # ############################################################################## @@ -24,9 +24,9 @@ from osv import fields,osv class board_board(osv.osv): _name = 'board.board' - + def create_view(self, cr, uid, ids, context): - + board = self.pool.get('board.board').browse(cr, uid, ids, context) left = [] right = [] @@ -52,23 +52,22 @@ class board_board(osv.osv): """ % ('\n'.join(left), '\n'.join(right)) - + return arch def write(self, cr, uid, ids, vals, context={}): result = super(board_board, self).write(cr, uid, ids, vals, context) cr.commit() - + board = self.pool.get('board.board').browse(cr, uid, ids[0]) - + view = self.create_view(cr, uid, ids[0], context) id = board.view_id.id - - cr.execute("update ir_ui_view set arch='%s' where id=%s" % (view, id)) + cr.execute("update ir_ui_view set arch=%s where id=%s" , (view, id)) cr.commit() - + return result - + def create(self, cr, user, vals, context=None): if not 'name' in vals: return False @@ -84,31 +83,31 @@ class board_board(osv.osv): super(board_board, self).write(cr, user, [id], {'view_id': view_id}, context) return id - + def fields_view_get(self, cr, user, view_id=None, view_type='form', context=None, toolbar=False, submenu=False): res = {} res = super(board_board, self).fields_view_get(cr, user, view_id, view_type, context, toolbar=toolbar, submenu=submenu) - + vids = self.pool.get('ir.ui.view.custom').search(cr, user, [('user_id','=',user), ('ref_id','=',view_id)]) if vids: view_id = vids[0] arch = self.pool.get('ir.ui.view.custom').browse(cr, user, view_id) res['arch'] = arch.arch - + res['toolbar'] = {'print':[],'action':[],'relate':[]} return res - + _columns = { 'name': fields.char('Dashboard', size=64, required=True), 'view_id': fields.many2one('ir.ui.view', 'Board View'), 'line_ids': fields.one2many('board.board.line', 'board_id', 'Action Views') } - + # the following lines added to let the button on dashboard work. _defaults = { 'name': lambda *args: 'Dashboard' } - + board_board() class board_line(osv.osv): From 832aad3299581b784f12f19190adc325e36c155f Mon Sep 17 00:00:00 2001 From: "nch@tinyerp.com" <> Date: Fri, 27 Nov 2009 15:03:37 +0530 Subject: [PATCH 35/53] [IMP]:base_module_quality sql queries to parameterized query bzr revid: nch@tinyerp.com-20091127093337-qzoienqx9dz3z21y --- addons/base_module_quality/speed_test/speed_test.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/addons/base_module_quality/speed_test/speed_test.py b/addons/base_module_quality/speed_test/speed_test.py index e2a34eaa4dd..1c5b8728d5f 100644 --- a/addons/base_module_quality/speed_test/speed_test.py +++ b/addons/base_module_quality/speed_test/speed_test.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 . # ############################################################################## @@ -45,8 +45,9 @@ This test checks the speed of the module. Note that at least 5 demo data is need # remove osv_memory class becaz it does not have demo data if obj_list: - cr.execute("select w.res_model from ir_actions_todo as t left join ir_act_window as w on t.action_id=w.id where w.res_model in ('%s')"% ("','".join(obj_list))) + cr.execute("select w.res_model from ir_actions_todo as t left join ir_act_window as w on t.action_id=w.id where w.res_model =ANY(%s)",(obj_list,)) res = cr.fetchall() + print res for remove_obj in res: if remove_obj and (remove_obj[0] in obj_list): obj_list.remove(remove_obj[0]) From 13ae64b05eee86d051b0be4fbac238e8c79fd0db Mon Sep 17 00:00:00 2001 From: "nch@tinyerp.com" <> Date: Fri, 27 Nov 2009 16:09:43 +0530 Subject: [PATCH 36/53] [IMP]:Auction sql queries to parameterized query bzr revid: nch@tinyerp.com-20091127103943-z5x1rujyu5wxfvkq --- addons/auction/auction.py | 14 ++++----- addons/auction/report/auction_total_rml.py | 36 +++++++++++----------- addons/auction/report/buyer_list.py | 8 ++--- addons/auction/report/catalog2.py | 8 ++--- 4 files changed, 33 insertions(+), 33 deletions(-) diff --git a/addons/auction/auction.py b/addons/auction/auction.py index 29ce8b30421..2e944207517 100644 --- a/addons/auction/auction.py +++ b/addons/auction/auction.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 . # ############################################################################## @@ -95,12 +95,12 @@ class auction_dates(osv.osv): RETURN: True """ # objects vendus mais non factures - cr.execute('select count(*) as c from auction_lots where auction_id in ('+','.join(map(str, ids))+') and state=%s and obj_price>0', ('draft',)) + cr.execute('select count(*) as c from auction_lots where auction_id =ANY(%s) and state=%s and obj_price>0', (ids,'draft',)) nbr = cr.fetchone()[0] ach_uids = {} - cr.execute('select id from auction_lots where auction_id in ('+','.join(map(str, ids))+') and state=%s and obj_price>0', ('draft',)) + cr.execute('select id from auction_lots where auction_id =ANY(%s) and state=%s and obj_price>0', (ids,'draft',)) r=self.pool.get('auction.lots').lots_invoice(cr, uid, [x[0] for x in cr.fetchall()],{},None) - cr.execute('select id from auction_lots where auction_id in ('+','.join(map(str, ids))+') and obj_price>0') + cr.execute('select id from auction_lots where auction_id =ANY(%s) and obj_price>0',(ids,)) ids2 = [x[0] for x in cr.fetchall()] # for auction in auction_ids: c=self.pool.get('auction.lots').seller_trans_create(cr, uid, ids2,{}) @@ -113,7 +113,7 @@ auction_dates() # Deposits #---------------------------------------------------------- def _inv_uniq(cr, ids): - cr.execute('select name from auction_deposit where id in ('+','.join(map(lambda x: str(x), ids))+')') + cr.execute('select name from auction_deposit where id =ANY(%s)',(ids,)) for datas in cr.fetchall(): cr.execute('select count(*) from auction_deposit where name=%s', (datas[0],)) if cr.fetchone()[0]>1: @@ -229,7 +229,7 @@ def _type_get(self, cr, uid,ids): # Lots #---------------------------------------------------------- def _inv_constraint(cr, ids): - cr.execute('select id, bord_vnd_id, lot_num from auction_lots where id in ('+','.join(map(lambda x: str(x), ids))+')') + cr.execute('select id, bord_vnd_id, lot_num from auction_lots where id =ANY(%s)', (ids,)) for datas in cr.fetchall(): cr.execute('select count(*) from auction_lots where bord_vnd_id=%s and lot_num=%s', (datas[1],datas[2])) if cr.fetchone()[0]>1: diff --git a/addons/auction/report/auction_total_rml.py b/addons/auction/report/auction_total_rml.py index 15f61bc103b..646aa489ebe 100644 --- a/addons/auction/report/auction_total_rml.py +++ b/addons/auction/report/auction_total_rml.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 . # ############################################################################## @@ -54,7 +54,7 @@ class auction_total_rml(report_sxw.rml_parse): for lot_id in objects: auc_lot_ids.append(lot_id.id) self.total_obj=auc_lot_ids - self.cr.execute('select auction_id from auction_lots where id in ('+','.join(map(str,auc_lot_ids))+') group by auction_id') + self.cr.execute('select auction_id from auction_lots where id =ANY(%s) group by auction_id',(auc_lot_ids,)) auc_date_ids = self.cr.fetchall() auct_dat=[] for ad_id in auc_date_ids: @@ -64,52 +64,52 @@ class auction_total_rml(report_sxw.rml_parse): def sum_taxes(self,auction_id): - self.cr.execute("select count(1) from auction_lots where id in ("+",".join(map(str,self.total_obj))+") and auction_id=%s group by auction_id ", (auction_id,)) + self.cr.execute("select count(1) from auction_lots where id =ANY(%s) and auction_id=%s group by auction_id ", (self.total_obj,auction_id,)) res = self.cr.fetchone() return res[0] def sold_item(self, object_id): - self.cr.execute("select count(1) from auction_lots where id in ("+",".join(map(str,self.total_obj))+") and auction_id=%s and state in ('unsold') ", (object_id,)) + self.cr.execute("select count(1) from auction_lots where id =ANY(%s) and auction_id=%s and state in ('unsold') ", (self.total_obj,object_id,)) res = self.cr.fetchone() return str(res[0]) def sum_buyer(self, auction_id): - self.cr.execute("select count(*) from auction_lots where id in ("+",".join(map(str,self.total_obj))+") and auction_id=%s and (ach_uid is not null or ach_login is not null) ", (auction_id,)) + self.cr.execute("select count(*) from auction_lots where id =ANY(%s) and auction_id=%s and (ach_uid is not null or ach_login is not null) ", (self.total_obj,auction_id,)) res = self.cr.fetchone() return str(res[0]) def sum_seller(self, auction_id): - self.cr.execute("select count(distinct bord_vnd_id) from auction_lots where id in ("+",".join(map(str,self.total_obj))+") and auction_id=%s AND bord_vnd_id is not null ", (auction_id,)) + self.cr.execute("select count(distinct bord_vnd_id) from auction_lots where id =ANY(%s) and auction_id=%s AND bord_vnd_id is not null ", (self.total_obj,auction_id,)) res = self.cr.fetchone() return res[0] def sum_adj(self, auction_id): - self.cr.execute("select sum(obj_price) from auction_lots where id in ("+",".join(map(str,self.total_obj))+") and auction_id=%s ", (auction_id,)) + self.cr.execute("select sum(obj_price) from auction_lots where id =ANY(%s) and auction_id=%s ", (self.total_obj,auction_id,)) res = self.cr.fetchone() return str(res[0]) def count_take(self, auction_id): - self.cr.execute("select count(*) from auction_lots where id in ("+",".join(map(str,self.total_obj))+") and auction_id=%s and ach_emp='True' ", (auction_id,)) + self.cr.execute("select count(*) from auction_lots where id =ANY(%s) and auction_id=%s and ach_emp='True' ", (self.total_obj,auction_id,)) res = self.cr.fetchone() return str(res[0]) def chek_paid(self, auction_id): - self.cr.execute("select count(1) from auction_lots where id in ("+",".join(map(str,self.total_obj))+") and auction_id=%s and ((paid_ach='T') or (is_ok='T')) ", (auction_id,)) + self.cr.execute("select count(1) from auction_lots where id =ANY(%s) and auction_id=%s and ((paid_ach='T') or (is_ok='T')) ", (self.total_obj,auction_id,)) res = self.cr.fetchone() return str(res[0]) def check_paid_seller(self,auction_id): - self.cr.execute("select sum(seller_price) from auction_lots where id in ("+",".join(map(str,self.total_obj))+") and auction_id=%s and paid_vnd != 'T' ", (auction_id,)) + self.cr.execute("select sum(seller_price) from auction_lots where id =ANY(%s) and auction_id=%s and paid_vnd != 'T' ", (self.total_obj,auction_id,)) res = self.cr.fetchone() return str(res[0]) or 0.0 def sum_credit(self,auction_id): - self.cr.execute("select sum(buyer_price) from auction_lots where id in ("+",".join(map(str,self.total_obj))+") and auction_id=%s", (auction_id,)) + self.cr.execute("select sum(buyer_price) from auction_lots where id =ANY(%s) and auction_id=%s", (self.total_obj,auction_id,)) res = self.cr.fetchone() return str(res[0]) def sum_debit_buyer(self,auction_id): - self.cr.execute("select sum(buyer_price) from auction_lots where id in ("+",".join(map(str,self.total_obj))+") and auction_id=%s", (auction_id,)) + self.cr.execute("select sum(buyer_price) from auction_lots where id =ANY(%s) and auction_id=%s", (self.total_obj,auction_id,)) res = self.cr.fetchone() return str(res[0] or 0) @@ -121,27 +121,27 @@ class auction_total_rml(report_sxw.rml_parse): def sum_credit_seller(self, object_id): - self.cr.execute("select sum(seller_price) from auction_lots where id in ("+",".join(map(str,self.total_obj))+") and auction_id=%s", (object_id,)) + self.cr.execute("select sum(seller_price) from auction_lots where id =ANY(%s) and auction_id=%s", (self.total_obj,object_id,)) res = self.cr.fetchone() return str(res[0] or 0) def sum_minadj(self, auction_id): - self.cr.execute('select sum(lot_est1) from auction_lots where id in ('+','.join(map(str,self.total_obj))+') and auction_id=%s', (auction_id,)) + self.cr.execute('select sum(lot_est1) from auction_lots where id =ANY(%s) and auction_id=%s', (self.total_obj,auction_id,)) res = self.cr.fetchone() return str(res[0]) or 0 def sum_maxadj(self, auction_id): - self.cr.execute('select sum(lot_est2) from auction_lots where id in ('+','.join(map(str,self.total_obj))+') and auction_id=%s', (auction_id,)) + self.cr.execute('select sum(lot_est2) from auction_lots where id =ANY(%s) and auction_id=%s', (self.total_obj,auction_id,)) res = self.cr.fetchone() return str(res[0]) or 0 def sum_buyer_paid(self, auction_id): - self.cr.execute("select count(*) from auction_lots where id in ("+",".join(map(str,self.total_obj))+") and auction_id=%s and state = 'paid' ", (auction_id,)) + self.cr.execute("select count(*) from auction_lots where id =ANY(%s) and auction_id=%s and state = 'paid' ", (self.total_obj,auction_id,)) res = self.cr.fetchone() return str(res[0]) def count_comm(self, auction_id): - self.cr.execute("select count(*) from auction_lots where id in ("+",".join(map(str,self.total_obj))+") and auction_id=%s and obj_comm is not null ", (auction_id,)) + self.cr.execute("select count(*) from auction_lots where id =ANY(%s) and auction_id=%s and obj_comm is not null ", (self.total_obj,auction_id,)) res = self.cr.fetchone() return str(res[0]) diff --git a/addons/auction/report/buyer_list.py b/addons/auction/report/buyer_list.py index 171c81a09f9..8726ec147a8 100644 --- a/addons/auction/report/buyer_list.py +++ b/addons/auction/report/buyer_list.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 . # ############################################################################## @@ -49,7 +49,7 @@ class buyer_list(report_sxw.rml_parse): for lot_id in objects: auc_lot_ids.append(lot_id.id) self.auc_lot_ids=auc_lot_ids - self.cr.execute('select auction_id from auction_lots where id in ('+','.join(map(str,auc_lot_ids))+') group by auction_id') + self.cr.execute('select auction_id from auction_lots where id =ANY(%s) group by auction_id',(auc_lot_ids,)) auc_date_ids = self.cr.fetchall() auct_dat=[] for ad_id in auc_date_ids: @@ -70,7 +70,7 @@ class buyer_list(report_sxw.rml_parse): auc_date_ids = self.pool.get('auction.dates').search(self.cr,self.uid,([('name','like',obj['name'])])) # self.cr.execute('select ach_uid,count(1) as no_lot, sum(obj_price) as adj_price, sum(buyer_price)-sum(obj_price) as buyer_cost ,sum(buyer_price) as to_pay from auction_lots where id in ('+','.join(map(str,self.auc_lot_ids))+') and auction_id=%s and ach_uid is not null group by ach_uid ', (auc_date_ids[0],)) - self.cr.execute('select ach_login as ach_uid,count(1) as no_lot, sum(obj_price) as adj_price, sum(buyer_price)-sum(obj_price) as buyer_cost ,sum(buyer_price) as to_pay from auction_lots where id in ('+','.join(map(str,self.auc_lot_ids))+') and auction_id=%s and ach_login is not null group by ach_login order by ach_login', (auc_date_ids[0],)) + self.cr.execute('select ach_login as ach_uid,count(1) as no_lot, sum(obj_price) as adj_price, sum(buyer_price)-sum(obj_price) as buyer_cost ,sum(buyer_price) as to_pay from auction_lots where id =ANY(%s) and auction_id=%s and ach_login is not null group by ach_login order by ach_login', (self.auc_lot_ids,auc_date_ids[0],)) res = self.cr.dictfetchall() for r in res: # if r['ach_uid']: diff --git a/addons/auction/report/catalog2.py b/addons/auction/report/catalog2.py index 38493d6f6bd..d43cd0ca72e 100644 --- a/addons/auction/report/catalog2.py +++ b/addons/auction/report/catalog2.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 . # ############################################################################## @@ -125,8 +125,8 @@ class auction_catalog(report_rml): auction_ids = [] for test in ab: if test.has_key('auction_id'): - auction_ids.append(str(test['auction_id'][0])) - cr.execute('select * from auction_lots where auction_id in ('+ ','.join(auction_ids)+')') + auction_ids.append(test['auction_id'][0]) + cr.execute('select * from auction_lots where auction_id =ANY(%s)',(auction_ids,)) res = cr.dictfetchall() for cat in res: product =doc.createElement('product') From b7f02461046773d78aeebe9dfdbc0d64fff786a7 Mon Sep 17 00:00:00 2001 From: "nch@tinyerp.com" <> Date: Fri, 27 Nov 2009 16:21:31 +0530 Subject: [PATCH 37/53] [IMP]:account_voucher sql queries to parameterized query bzr revid: nch@tinyerp.com-20091127105131-anms4a2s78yirywj --- addons/account_voucher/voucher.py | 232 +++++++++++++++--------------- 1 file changed, 116 insertions(+), 116 deletions(-) diff --git a/addons/account_voucher/voucher.py b/addons/account_voucher/voucher.py index 7493f24c18a..d4f39a806a4 100755 --- a/addons/account_voucher/voucher.py +++ b/addons/account_voucher/voucher.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 . # ############################################################################## @@ -43,49 +43,49 @@ class account_voucher(osv.osv): return periods[0] else: return False - + def _get_type(self, cr, uid, context={}): type = context.get('type', 'rec_voucher') return type - + def _get_reference_type(self, cursor, user, context=None): return [('none', 'Free Reference')] - + def _get_journal(self, cr, uid, context): type_inv = 'rec_voucher' - + if type(context) == type(''): type_inv = context elif type(context) == type({}): type_inv = context.get('type', 'rec_voucher') type2journal = { - 'rec_voucher': 'cash', + 'rec_voucher': 'cash', 'bank_rec_voucher': 'cash', 'pay_voucher': 'cash', - 'bank_pay_voucher': 'cash', + 'bank_pay_voucher': 'cash', 'cont_voucher': 'cash', 'journal_sale_vou': 'sale', 'journal_pur_voucher': 'purchase', 'journal_voucher':'expanse' } - + journal_obj = self.pool.get('account.journal') ttype = type2journal.get(type_inv, 'cash') res = journal_obj.search(cr, uid, [('type', '=', ttype)], limit=1) - + if res: return res[0] else: return False - + def _get_currency(self, cr, uid, context): user = pooler.get_pool(cr.dbname).get('res.users').browse(cr, uid, [uid])[0] if user.company_id: return user.company_id.currency_id.id else: return pooler.get_pool(cr.dbname).get('res.currency').search(cr, uid, [('rate','=',1.0)])[0] - + _name = 'account.voucher' _description = 'Accounting Voucher' _order = "number" @@ -114,7 +114,7 @@ class account_voucher(osv.osv): ('proforma','Pro-forma'), ('posted','Posted'), ('cancel','Cancel') - ], 'State', + ], 'State', readonly=True), 'amount':fields.float('Amount', readonly=True), 'number':fields.char('Number', size=32, readonly=True), @@ -125,7 +125,7 @@ class account_voucher(osv.osv): 'move_ids':fields.many2many('account.move.line', 'voucher_id', 'account_id', 'rel_account_move', 'Real Entry'), 'partner_id':fields.many2one('res.partner', 'Partner', readonly=True, states={'draft':[('readonly',False)]}) } - + _defaults = { 'state': lambda *a: 'draft', 'date' : lambda *a: time.strftime('%Y-%m-%d'), @@ -138,11 +138,11 @@ class account_voucher(osv.osv): context=context).company_id.id, 'currency_id': _get_currency, } - + def _get_analityc_lines(self, cr, uid, id): inv = self.browse(cr, uid, [id])[0] cur_obj = self.pool.get('res.currency') - + def onchange_account(self, cr, uid, ids, account_id): if not account_id: return {'value':{'amount':False}} @@ -163,7 +163,7 @@ class account_voucher(osv.osv): else: account_id = journal.browse(cr, uid, journal_id).default_credit_account_id return {'value':{'account_id':account_id.id}} - + def open_voucher(self, cr, uid, ids, context={}): obj=self.pool.get('account.voucher').browse(cr,uid,ids) total=0 @@ -172,18 +172,18 @@ class account_voucher(osv.osv): self.write(cr,uid,ids,{'amount':total}) self.write(cr, uid, ids, {'state':'proforma'}) return True - + def proforma_voucher(self, cr, uid, ids, context={}): self.action_number(cr, uid, ids) self.action_move_line_create(cr, uid, ids) self.write(cr, uid, ids, {'state':'posted'}) return True - + def cancel_voucher(self,cr,uid,ids,context={}): self.action_cancel(cr, uid, ids) self.write(cr, uid, ids, {'state':'cancel'}) return True - + def action_cancel_draft(self, cr, uid, ids, *args): self.write(cr, uid, ids, {'state':'draft'}) return True @@ -198,7 +198,7 @@ class account_voucher(osv.osv): raise osv.except_osv('Invalid action !', 'Cannot delete invoice(s) which are already opened or paid !') osv.osv.unlink(self, cr, uid, unlink_ids) return True - + def _get_analytic_lines(self, cr, uid, id): inv = self.browse(cr, uid, [id])[0] cur_obj = self.pool.get('res.currency') @@ -210,14 +210,14 @@ class account_voucher(osv.osv): sign = -1 iml = self.pool.get('account.voucher.line').move_line_get(cr, uid, inv.id) - + for il in iml: if il['account_analytic_id']: if inv.type in ('pay_voucher', 'rec_voucher','cont_voucher','bank_pay_voucher','bank_rec_voucher','journal_sale_vou','journal_pur_voucher'): ref = inv.reference else: ref = self._convert_ref(cr, uid, inv.number) - + il['analytic_lines'] = [(0, 0, { 'name': il['name'], 'date': inv['date'], @@ -228,7 +228,7 @@ class account_voucher(osv.osv): 'ref': ref, })] return iml - + def action_move_line_create(self, cr, uid, ids, *args): for inv in self.browse(cr, uid, ids): if inv.move_id: @@ -248,13 +248,13 @@ class account_voucher(osv.osv): else: ref = self._convert_ref(cr, uid, inv.number) - acc_id = None + acc_id = None date = inv.date total_currency = 0 acc_id = None for i in iml: partner_id=i['partner_id'] - acc_id = i['account_id'] + acc_id = i['account_id'] if inv.currency_id.id != company_currency: i['currency_id'] = inv.currency_id.id i['amount_currency'] = i['amount'] @@ -291,14 +291,14 @@ class account_voucher(osv.osv): line = map(lambda x:(0,0,self.line_get_convert(cr, uid, x,date, context={})) ,iml) an_journal_id=inv.journal_id.analytic_journal_id.id journal_id = inv.journal_id.id - + journal = self.pool.get('account.journal').browse(cr, uid, journal_id) if journal.sequence_id: name = self.pool.get('ir.sequence').get_id(cr, uid, journal.sequence_id.id) move = { - 'name': name, - 'journal_id': journal_id, + 'name': name, + 'journal_id': journal_id, 'voucher_type':inv.type, 'narration' : inv.narration } @@ -309,7 +309,7 @@ class account_voucher(osv.osv): move_id = self.pool.get('account.move').create(cr, uid, move) ref = move['name'] amount=0.0 - + #create the first line our self move_line = { 'name': inv.name, @@ -320,7 +320,7 @@ class account_voucher(osv.osv): 'journal_id':journal_id , 'period_id':inv.period_id.id, 'partner_id': False, - 'ref': ref, + 'ref': ref, 'date': inv.date } if inv.type in ('rec_voucher', 'bank_rec_voucher', 'journal_pur_voucher', 'journal_voucher'): @@ -328,9 +328,9 @@ class account_voucher(osv.osv): else: move_line['credit'] = inv.amount * (-1) self.pool.get('account.move.line').create(cr, uid, move_line) - + for line in inv.payment_ids: - + move_line = { 'name':line.name, 'debit':False, @@ -340,24 +340,24 @@ class account_voucher(osv.osv): 'journal_id':journal_id , 'period_id':inv.period_id.id, 'partner_id':line.partner_id.id or False, - 'ref':ref, + 'ref':ref, 'date':inv.date } - + if line.type == 'dr': move_line['debit'] = line.amount or False amount=line.amount elif line.type == 'cr': move_line['credit'] = line.amount or False amount=line.amount * (-1) - + ml_id=self.pool.get('account.move.line').create(cr, uid, move_line) - + if inv.narration: line.name=inv.narration else: line.name=line.name - + if line.account_analytic_id: an_line = { 'name':line.name, @@ -370,18 +370,18 @@ class account_voucher(osv.osv): 'ref':ref } self.pool.get('account.analytic.line').create(cr,uid,an_line) - + self.write(cr, uid, [inv.id], {'move_id': move_id}) obj=self.pool.get('account.move').browse(cr, uid, move_id) - + for line in obj.line_id : cr.execute('insert into voucher_id (account_id,rel_account_move) values (%d, %d)',(int(ids[0]),int(line.id))) - + return True - + def line_get_convert(self, cr, uid, x, date, context={}): - + return { 'date':date, 'date_maturity': x.get('date_maturity', False), @@ -399,12 +399,12 @@ class account_voucher(osv.osv): } def _convert_ref(self, cr, uid, ref): return (ref or '').replace('/','') - - + + def action_number(self, cr, uid, ids, *args): cr.execute('SELECT id, type, number, move_id, reference ' \ 'FROM account_voucher ' \ - 'WHERE id IN ('+','.join(map(str, ids))+')') + 'WHERE id =ANY(%s)',(ids,)) for (id, invtype, number, move_id, reference) in cr.fetchall(): if not number: number = self.pool.get('ir.sequence').get(cr, uid, invtype) @@ -413,21 +413,21 @@ class account_voucher(osv.osv): ref = reference else: ref = self._convert_ref(cr, uid, number) - + cr.execute('UPDATE account_voucher SET number=%s ' \ - 'WHERE id=%d', (number, id)) + 'WHERE id=%s', (number, id)) cr.execute('UPDATE account_move_line SET ref=%s ' \ - 'WHERE move_id=%d AND (ref is null OR ref = \'\')', + 'WHERE move_id=%s AND (ref is null OR ref = \'\')', (ref, move_id)) cr.execute('UPDATE account_analytic_line SET ref=%s ' \ 'FROM account_move_line ' \ - 'WHERE account_move_line.move_id = %d ' \ + 'WHERE account_move_line.move_id = %s ' \ 'AND account_analytic_line.move_id = account_move_line.id', (ref, move_id)) return True - + def name_get(self, cr, uid, ids, context={}): if not len(ids): return [] @@ -454,7 +454,7 @@ class account_voucher(osv.osv): if not ids: ids = self.search(cr, user, [('name',operator,name)]+ args, limit=limit, context=context) return self.name_get(cr, user, ids, context) - + def copy(self, cr, uid, id, default=None, context=None): if default is None: default = {} @@ -463,7 +463,7 @@ class account_voucher(osv.osv): if 'date' not in default: default['date'] = time.strftime('%Y-%m-%d') return super(account_voucher, self).copy(cr, uid, id, default, context) - + def action_cancel(self, cr, uid, ids, *args): account_move_obj = self.pool.get('account.move') voucher = self.read(cr, uid, ids, ['move_id']) @@ -476,7 +476,7 @@ class account_voucher(osv.osv): account_move_obj.unlink(cr, uid, [i['move_id'][0]]) self.write(cr, uid, ids, {'state':'cancel', 'move_id':False}) return True - + account_voucher() class VoucherLine(osv.osv): @@ -495,7 +495,7 @@ class VoucherLine(osv.osv): _defaults = { 'type': lambda *a: 'cr' } - + def move_line_get(self, cr, uid, voucher_id, context={}): res = [] @@ -507,7 +507,7 @@ class VoucherLine(osv.osv): for line in inv.payment_ids: res.append(self.move_line_get_item(cr, uid, line, context)) return res - + def onchange_partner(self, cr, uid, ids, partner_id, ttype ,type1): if not partner_id: return {'value' : {'account_id' : False, 'type' : False ,'amount':False}} @@ -517,54 +517,54 @@ class VoucherLine(osv.osv): account_id = obj.browse(cr, uid, partner_id).property_account_receivable balance = obj.browse(cr,uid,partner_id).credit ttype = 'cr' - elif type1 in ('pay_voucher','bank_pay_voucher','cont_voucher') : + elif type1 in ('pay_voucher','bank_pay_voucher','cont_voucher') : account_id = obj.browse(cr, uid, partner_id).property_account_payable balance = obj.browse(cr,uid,partner_id).debit ttype = 'dr' - elif type1 in ('journal_sale_vou') : + elif type1 in ('journal_sale_vou') : account_id = obj.browse(cr, uid, partner_id).property_account_receivable balance = obj.browse(cr,uid,partner_id).credit ttype = 'dr' - elif type1 in ('journal_pur_voucher') : + elif type1 in ('journal_pur_voucher') : account_id = obj.browse(cr, uid, partner_id).property_account_payable balance = obj.browse(cr,uid,partner_id).debit - ttype = 'cr' - + ttype = 'cr' + return { 'value' : {'account_id' : account_id.id, 'type' : ttype, 'amount':balance} } - + def onchange_amount(self, cr, uid, ids,partner_id,amount, type,type1): if not amount: return {'value' : {}} if partner_id: - + obj = self.pool.get('res.partner') if type1 in ('rec_voucher', 'bank_rec_voucher', 'journal_voucher'): if amount < 0 : - account_id = obj.browse(cr, uid, partner_id).property_account_payable + account_id = obj.browse(cr, uid, partner_id).property_account_payable type = 'dr' else: - account_id = obj.browse(cr, uid, partner_id).property_account_receivable + account_id = obj.browse(cr, uid, partner_id).property_account_receivable type = 'cr' - - elif type1 in ('pay_voucher','bank_pay_voucher','cont_voucher') : + + elif type1 in ('pay_voucher','bank_pay_voucher','cont_voucher') : if amount < 0 : - account_id = obj.browse(cr, uid, partner_id).property_account_receivable + account_id = obj.browse(cr, uid, partner_id).property_account_receivable type = 'cr' else: account_id = obj.browse(cr, uid, partner_id).property_account_payable type = 'dr' - - elif type1 in ('journal_sale_vou') : + + elif type1 in ('journal_sale_vou') : if amount < 0 : account_id = obj.browse(cr, uid, partner_id).property_account_payable type = 'cr' else: account_id = obj.browse(cr, uid, partner_id).property_account_receivable type = 'dr' - - elif type1 in ('journal_pur_voucher') : + + elif type1 in ('journal_pur_voucher') : if amount< 0 : account_id = obj.browse(cr, uid, partner_id).property_account_receivable type = 'dr' @@ -574,70 +574,70 @@ class VoucherLine(osv.osv): else: if type1 in ('rec_voucher', 'bank_rec_voucher', 'journal_voucher'): if amount < 0 : - + type = 'dr' else: - + type = 'cr' - - elif type1 in ('pay_voucher','bank_pay_voucher','cont_voucher') : + + elif type1 in ('pay_voucher','bank_pay_voucher','cont_voucher') : if amount < 0 : - + type = 'cr' else: - + type = 'dr' - - elif type1 in ('journal_sale_vou') : + + elif type1 in ('journal_sale_vou') : if amount < 0 : - + type = 'cr' else: - + type = 'dr' - - elif type1 in ('journal_pur_voucher') : + + elif type1 in ('journal_pur_voucher') : if amount< 0 : - + type = 'dr' else: - + type = 'cr' - + return { 'value' : { 'type' : type , 'amount':amount} } - + def onchange_type(self, cr, uid, ids,partner_id,amount,type,type1): if partner_id: - + obj = self.pool.get('res.partner') - + if type1 in ('rec_voucher','bank_rec_voucher', 'journal_voucher'): if type == 'dr' : - account_id = obj.browse(cr, uid, partner_id).property_account_payable + account_id = obj.browse(cr, uid, partner_id).property_account_payable total=amount*(-1) else: - account_id = obj.browse(cr, uid, partner_id).property_account_receivable + account_id = obj.browse(cr, uid, partner_id).property_account_receivable total=amount*(-1) - - elif type1 in ('pay_voucher','bank_pay_voucher','cont_voucher') : + + elif type1 in ('pay_voucher','bank_pay_voucher','cont_voucher') : if type == 'cr' : - account_id = obj.browse(cr, uid, partner_id).property_account_receivable + account_id = obj.browse(cr, uid, partner_id).property_account_receivable total=amount*(-1) else: account_id = obj.browse(cr, uid, partner_id).property_account_payable total=amount*(-1) - - elif type1 in ('journal_sale_vou') : + + elif type1 in ('journal_sale_vou') : if type == 'cr' : account_id = obj.browse(cr, uid, partner_id).property_account_payable total=amount*(-1) else: account_id = obj.browse(cr, uid, partner_id).property_account_receivable total=amount*(-1) - - elif type1 in ('journal_pur_voucher') : + + elif type1 in ('journal_pur_voucher') : if type == 'dr' : account_id = obj.browse(cr, uid, partner_id).property_account_receivable total=amount*(-1) @@ -647,40 +647,40 @@ class VoucherLine(osv.osv): else: if type1 in ('rec_voucher','bank_rec_voucher', 'journal_voucher'): if type == 'dr' : - + total=amount*(-1) else: - + total=amount*(-1) - - elif type1 in ('pay_voucher','bank_pay_voucher','cont_voucher') : + + elif type1 in ('pay_voucher','bank_pay_voucher','cont_voucher') : if type == 'cr' : - + total=amount*(-1) else: - + total=amount*(-1) - - elif type1 in ('journal_sale_vou') : + + elif type1 in ('journal_sale_vou') : if type == 'cr' : - + total=amount*(-1) else: - + total=amount*(-1) - - elif type1 in ('journal_pur_voucher') : + + elif type1 in ('journal_pur_voucher') : if type == 'dr' : - + total=amount*(-1) else: - + total=amount*(-1) - + return { 'value' : {'type' : type , 'amount':total} } - + def move_line_get_item(self, cr, uid, line, context={}): return { 'type':'src', @@ -691,7 +691,7 @@ class VoucherLine(osv.osv): 'account_analytic_id':line.account_analytic_id.id or False, 'ref' : line.ref } - + VoucherLine() From 27823255c10d8c4eafe7ca2e0791d10ba4310dc3 Mon Sep 17 00:00:00 2001 From: "nch@tinyerp.com" <> Date: Fri, 27 Nov 2009 16:32:43 +0530 Subject: [PATCH 38/53] [IMP]:account_payment sql queries to parameterized query bzr revid: nch@tinyerp.com-20091127110243-181hk1mvg6ea34gu --- addons/account_payment/account_move_line.py | 2 +- addons/account_payment/payment.py | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/addons/account_payment/account_move_line.py b/addons/account_payment/account_move_line.py index eb612148d99..ffb6c452aec 100644 --- a/addons/account_payment/account_move_line.py +++ b/addons/account_payment/account_move_line.py @@ -42,7 +42,7 @@ class account_move_line(osv.osv): WHERE move_line_id = ml.id AND po.state != 'cancel') as amount FROM account_move_line ml - WHERE id in (%s)""" % (",".join(map(str,map(int, ids))))) + WHERE id =ANY(%s)""" ,(ids,)) r=dict(cr.fetchall()) return r diff --git a/addons/account_payment/payment.py b/addons/account_payment/payment.py index 8d46db771f4..22a564d7574 100644 --- a/addons/account_payment/payment.py +++ b/addons/account_payment/payment.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 . # ############################################################################## @@ -100,7 +100,7 @@ class payment_order(osv.osv): ('draft', 'Draft'), ('open','Confirmed'), ('cancel','Cancelled'), - ('done','Done')], 'State', select=True, + ('done','Done')], 'State', select=True, help='When an order is placed the state is \'Draft\'.\n Once the bank is confirmed the state is set to \'Confirmed\'.\n Then the order is paid the state is \'Done\'.'), 'line_ids': fields.one2many('payment.line','order_id','Payment lines',states={'done':[('readonly',True)]}), 'total': fields.function(_total, string="Total", method=True, @@ -225,8 +225,8 @@ class payment_line(osv.osv): from account_move_line ml inner join payment_line pl on (ml.id = pl.move_line_id) - where pl.id in (%s)"""% - (self.translate(name), ','.join(map(str, ids)))) + where pl.id =ANY(%s)""", + (self.translate(name),ids,)) res = dict(cr.fetchall()) if name == 'partner_id': From 23874d7282a6bdc96c62853ddec1a268a4a9f3d3 Mon Sep 17 00:00:00 2001 From: "nch@tinyerp.com" <> Date: Fri, 27 Nov 2009 17:05:13 +0530 Subject: [PATCH 39/53] [IMP]:account_budget sql queries to parameterized query bzr revid: nch@tinyerp.com-20091127113513-5utkqwss17vjh7yy --- addons/account_budget/crossovered_budget.py | 27 ++++++++++--------- .../report/analytic_account_budget_report.py | 8 +++--- .../report/crossovered_budget_report.py | 8 +++--- 3 files changed, 20 insertions(+), 23 deletions(-) diff --git a/addons/account_budget/crossovered_budget.py b/addons/account_budget/crossovered_budget.py index 694ac6c1a8d..22051179ce1 100644 --- a/addons/account_budget/crossovered_budget.py +++ b/addons/account_budget/crossovered_budget.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 . # ############################################################################## @@ -45,13 +45,13 @@ class account_budget_post(osv.osv): 'account_ids': fields.many2many('account.account', 'account_budget_rel', 'budget_id', 'account_id', 'Accounts'), 'crossovered_budget_line': fields.one2many('crossovered.budget.lines', 'general_budget_id', 'Budget Lines'), 'company_id': fields.many2one('res.company', 'Company', required=True), - 'sequence': fields.integer('Sequence'), + 'sequence': fields.integer('Sequence'), } _defaults = { - 'sequence': lambda *a: 1, - 'company_id': lambda self,cr,uid,c: self.pool.get('res.users').browse(cr, uid, uid, c).company_id.id, + 'sequence': lambda *a: 1, + 'company_id': lambda self,cr,uid,c: self.pool.get('res.users').browse(cr, uid, uid, c).company_id.id, } - _order = "sequence, name" + _order = "sequence, name" def spread(self, cr, uid, ids, fiscalyear_id=False, amount=0.0): dobj = self.pool.get('account.budget.post.dotation') @@ -76,8 +76,10 @@ class account_budget_post_dotation(osv.osv): total_days=strToDate(obj_period.date_stop) - strToDate(obj_period.date_start) budget_id=line.post_id and line.post_id.id or False - query="select id from crossovered_budget_lines where general_budget_id= '"+ str(budget_id) + "' AND (date_from >='" +obj_period.date_start +"' and date_from <= '"+obj_period.date_stop + "') OR (date_to >='" +obj_period.date_start +"' and date_to <= '"+obj_period.date_stop + "') OR (date_from <'" +obj_period.date_start +"' and date_to > '"+obj_period.date_stop + "')" - cr.execute(query) + query="select id from crossovered_budget_lines where \ + general_budget_id= %s AND (date_from >=%s and date_from <= %s ) \ + OR (date_to >=%s and date_to <= %s) OR (date_from < %s and date_to > %s)" + cr.execute(query,(budget_id,obj_period.date_start,obj_period.date_stop,obj_period.date_start,obj_period.date_stop,obj_period.date_start,obj_period.date_stop,)) res1=cr.fetchall() tot_planned=0.00 @@ -175,10 +177,9 @@ class crossovered_budget_lines(osv.osv): date_from = context['wizard_date_from'] if context.has_key('wizard_date_to'): date_to = context['wizard_date_to'] - - cr.execute("select sum(amount) from account_analytic_line where account_id=%%s and (date " - "between to_date(%%s,'yyyy-mm-dd') and to_date(%%s,'yyyy-mm-dd')) and " - "general_account_id in (%s)" % ",".join(map(str,acc_ids)), (line.analytic_account_id.id, date_from, date_to )) + cr.execute("select sum(amount) from account_analytic_line where account_id=%s and (date " + "between to_date(%s,'yyyy-mm-dd') and to_date(%s,'yyyy-mm-dd')) and " + "general_account_id=ANY(%s)", (line.analytic_account_id.id, date_from, date_to,acc_ids,)) result = cr.fetchone()[0] if result is None: result = 0.00 @@ -213,7 +214,7 @@ class crossovered_budget_lines(osv.osv): elapsed = min(strToDate(line.date_to),strToDate(date_to)) - max(strToDate(line.date_from),strToDate(date_from)) if strToDate(date_to) < strToDate(line.date_from): elapsed = strToDate(date_to) - strToDate(date_to) - + if total.days: theo_amt = float(elapsed.days/float(total.days))*line.planned_amount else: diff --git a/addons/account_budget/report/analytic_account_budget_report.py b/addons/account_budget/report/analytic_account_budget_report.py index 30f193d91cd..56885900c1c 100644 --- a/addons/account_budget/report/analytic_account_budget_report.py +++ b/addons/account_budget/report/analytic_account_budget_report.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 . # ############################################################################## @@ -65,13 +65,11 @@ class analytic_account_budget_report(report_sxw.rml_parse): if not b_line_ids: return [] - bd_lines_ids = ','.join([str(x) for x in b_line_ids]) - d_from=form['date_from'] d_to=form['date_to'] # bd_ids = ','.join([str(x) for x in budget_lines]) - self.cr.execute('select distinct(crossovered_budget_id) from crossovered_budget_lines where id in (%s)'%(bd_lines_ids)) + self.cr.execute('select distinct(crossovered_budget_id) from crossovered_budget_lines where id =ANY(%s)',(b_line_ids,)) budget_ids=self.cr.fetchall() context={'wizard_date_from':d_from,'wizard_date_to':d_to} diff --git a/addons/account_budget/report/crossovered_budget_report.py b/addons/account_budget/report/crossovered_budget_report.py index 7e8fbfce115..59d393146e5 100644 --- a/addons/account_budget/report/crossovered_budget_report.py +++ b/addons/account_budget/report/crossovered_budget_report.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 . # ############################################################################## @@ -71,10 +71,8 @@ class budget_report(report_sxw.rml_parse): if not budget_ids: return [] - b_line_ids=','.join([str(x) for x in budget_ids]) - # bd_ids = ','.join([str(x) for x in budget_lines]) - self.cr.execute('select distinct(analytic_account_id) from crossovered_budget_lines where id in (%s)'%(b_line_ids)) + self.cr.execute('select distinct(analytic_account_id) from crossovered_budget_lines where id =ANY(%s)',(budget_ids,)) an_ids=self.cr.fetchall() context={'wizard_date_from':d_from,'wizard_date_to':d_to} From f247d0f7e3dac3cdb4458e070a6cbe33556d1d54 Mon Sep 17 00:00:00 2001 From: "nch@tinyerp.com" <> Date: Fri, 27 Nov 2009 17:31:20 +0530 Subject: [PATCH 40/53] [IMP]:account_analytic_analysis sql queries to parameterized query bzr revid: nch@tinyerp.com-20091127120120-e28m6bdemzsm8asn --- .../account_analytic_analysis.py | 72 ++++++++----------- 1 file changed, 28 insertions(+), 44 deletions(-) diff --git a/addons/account_analytic_analysis/account_analytic_analysis.py b/addons/account_analytic_analysis/account_analytic_analysis.py index bbd976f8c29..2dde526d558 100644 --- a/addons/account_analytic_analysis/account_analytic_analysis.py +++ b/addons/account_analytic_analysis/account_analytic_analysis.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2009 Tiny SPRL (). # @@ -15,14 +15,14 @@ # 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 . # ############################################################################## import operator from osv import osv, fields from osv.orm import intersect -import tools.sql +import tools.sql from tools.translate import _ @@ -34,14 +34,13 @@ class account_analytic_account(osv.osv): res = {} ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)]) if ids2: - acc_set = ",".join(map(str, ids2)) cr.execute("select account_analytic_line.account_id, COALESCE(sum(amount),0.0) \ from account_analytic_line \ join account_analytic_journal \ on account_analytic_line.journal_id = account_analytic_journal.id \ - where account_analytic_line.account_id IN (%s) \ + where account_analytic_line.account_id =ANY(%s) \ and account_analytic_journal.type = 'sale' \ - group by account_analytic_line.account_id" % acc_set) + group by account_analytic_line.account_id" ,(ids2,)) for account_id, sum in cr.fetchall(): res[account_id] = round(sum,2) for obj_id in ids: @@ -60,7 +59,6 @@ class account_analytic_account(osv.osv): ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)]) if ids2: # Amount uninvoiced hours to invoice at sale price - acc_set = ",".join(map(str, ids2)) cr.execute("""SELECT account_analytic_account.id, \ COALESCE(sum (product_template.list_price * \ account_analytic_line.unit_amount * \ @@ -77,11 +75,11 @@ class account_analytic_account(osv.osv): on account_analytic_account.id = account_analytic_line.account_id \ JOIN hr_timesheet_invoice_factor \ on hr_timesheet_invoice_factor.id = account_analytic_account.to_invoice \ - WHERE account_analytic_account.id IN (%s) \ + WHERE account_analytic_account.id =ANY(%s) \ AND account_analytic_line.invoice_id is null \ AND account_analytic_line.to_invoice IS NOT NULL \ and account_analytic_journal.type in ('purchase','general') \ - GROUP BY account_analytic_account.id;"""%acc_set) + GROUP BY account_analytic_account.id;""",(ids2,)) for account_id, sum in cr.fetchall(): res[account_id] = round(sum,2) @@ -113,16 +111,15 @@ class account_analytic_account(osv.osv): res = {} ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)]) if ids2: - acc_set = ",".join(map(str, ids2)) cr.execute("select account_analytic_line.account_id, COALESCE(sum(unit_amount),0.0) \ from account_analytic_line \ join account_analytic_journal \ on account_analytic_line.journal_id = account_analytic_journal.id \ - where account_analytic_line.account_id IN (%s) \ + where account_analytic_line.account_id =ANY(%s) \ and account_analytic_journal.type='general' \ and invoice_id is null \ AND to_invoice IS NOT NULL \ - GROUP BY account_analytic_line.account_id;"%acc_set) + GROUP BY account_analytic_line.account_id;",(ids2,)) for account_id, sum in cr.fetchall(): res[account_id] = round(sum,2) for obj_id in ids: @@ -139,14 +136,13 @@ class account_analytic_account(osv.osv): res = {} ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)]) if ids2: - acc_set = ",".join(map(str, ids2)) cr.execute("select account_analytic_line.account_id,COALESCE(SUM(unit_amount),0.0) \ from account_analytic_line \ join account_analytic_journal \ on account_analytic_line.journal_id = account_analytic_journal.id \ - where account_analytic_line.account_id IN (%s) \ + where account_analytic_line.account_id =ANY(%s) \ and account_analytic_journal.type='general' \ - GROUP BY account_analytic_line.account_id"%acc_set) + GROUP BY account_analytic_line.account_id",(ids2,)) ff = cr.fetchall() for account_id, sum in ff: res[account_id] = round(sum,2) @@ -164,14 +160,13 @@ class account_analytic_account(osv.osv): res = {} ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)]) if ids2: - acc_set = ",".join(map(str, ids2)) cr.execute("""select account_analytic_line.account_id,COALESCE(sum(amount),0.0) \ from account_analytic_line \ join account_analytic_journal \ on account_analytic_line.journal_id = account_analytic_journal.id \ - where account_analytic_line.account_id IN (%s) \ + where account_analytic_line.account_id =ANY(%s) \ and amount<0 \ - GROUP BY account_analytic_line.account_id"""%acc_set) + GROUP BY account_analytic_line.account_id""",(ids2,)) for account_id, sum in cr.fetchall(): res[account_id] = round(sum,2) for obj_id in ids: @@ -189,7 +184,6 @@ class account_analytic_account(osv.osv): res2 = {} ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)]) if ids2: - acc_set = ",".join(map(str, ids2)) cr.execute("""select account_analytic_line.account_id as account_id, \ COALESCE(sum((account_analytic_line.unit_amount * pt.list_price) \ - (account_analytic_line.unit_amount * pt.list_price \ @@ -205,10 +199,10 @@ class account_analytic_account(osv.osv): on (a.id=account_analytic_line.account_id) \ join hr_timesheet_invoice_factor hr \ on (hr.id=a.to_invoice) \ - where account_analytic_line.account_id IN (%s) \ + where account_analytic_line.account_id =ANY(%s) \ and a.to_invoice IS NOT NULL \ and account_analytic_journal.type in ('purchase','general') - GROUP BY account_analytic_line.account_id"""%acc_set) + GROUP BY account_analytic_line.account_id""",(ids2,)) for account_id, sum in cr.fetchall(): res2[account_id] = round(sum,2) @@ -230,12 +224,11 @@ class account_analytic_account(osv.osv): res = {} ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)]) if ids2: - acc_set = ",".join(map(str, ids2)) cr.execute("select account_analytic_line.account_id, max(date) \ from account_analytic_line \ - where account_id IN (%s) \ + where account_id =ANY(%s) \ and invoice_id is null \ - GROUP BY account_analytic_line.account_id" % acc_set) + GROUP BY account_analytic_line.account_id" ,(ids2,)) for account_id, sum in cr.fetchall(): res[account_id] = sum for obj_id in ids: @@ -252,15 +245,14 @@ class account_analytic_account(osv.osv): res = {} ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)]) if ids2: - acc_set = ",".join(map(str, ids2)) cr.execute ("select account_analytic_line.account_id, \ date(max(account_invoice.date_invoice)) \ from account_analytic_line \ join account_invoice \ on account_analytic_line.invoice_id = account_invoice.id \ - where account_analytic_line.account_id IN (%s) \ + where account_analytic_line.account_id =ANY(%s) \ and account_analytic_line.invoice_id is not null \ - GROUP BY account_analytic_line.account_id"%acc_set) + GROUP BY account_analytic_line.account_id",(ids2,)) for account_id, sum in cr.fetchall(): res[account_id] = sum for obj_id in ids: @@ -277,12 +269,11 @@ class account_analytic_account(osv.osv): res = {} ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)]) if ids2: - acc_set = ",".join(map(str, ids2)) cr.execute("select account_analytic_line.account_id, max(date) \ from account_analytic_line \ - where account_id IN (%s) \ + where account_id =ANY(%s) \ and invoice_id is not null \ - GROUP BY account_analytic_line.account_id;"%acc_set) + GROUP BY account_analytic_line.account_id;",(ids2,)) for account_id, sum in cr.fetchall(): res[account_id] = sum for obj_id in ids: @@ -373,8 +364,7 @@ class account_analytic_account(osv.osv): ids2 = self.search(cr, uid, [('parent_id', 'child_of', [id])]) if ids2: cr.execute('SELECT DISTINCT(month_id) FROM account_analytic_analysis_summary_month ' \ - 'WHERE account_id in (' + ','.join([str(x) for x in ids2]) + ') ' \ - 'AND unit_amount <> 0.0') + 'WHERE account_id =ANY(%s) AND unit_amount <> 0.0',(ids2,)) res[id] = [int(id * 1000000 + int(x[0])) for x in cr.fetchall()] else: res[id] = [] @@ -388,11 +378,10 @@ class account_analytic_account(osv.osv): ids2 = self.search(cr, uid, [('parent_id', 'child_of', [id])]) if ids2: cr.execute('SELECT DISTINCT("user") FROM account_analytic_analysis_summary_user ' \ - 'WHERE account_id in (' + ','.join([str(x) for x in ids2]) + ') ' \ - 'AND unit_amount <> 0.0') + 'WHERE account_id =ANY(%s) AND unit_amount <> 0.0',(ids2,)) res[id] = [int((id * max_user) + x[0]) for x in cr.fetchall()] else: - res[id] = [] + res[id] = [] return res _columns ={ @@ -432,13 +421,11 @@ class account_analytic_account_summary_user(osv.osv): account_ids = [int(str(x/max_user - (x%max_user == 0 and 1 or 0))) for x in ids] user_ids = [int(str(x-((x/max_user - (x%max_user == 0 and 1 or 0)) *max_user))) for x in ids] account_ids2 = account_obj.search(cr, uid, [('parent_id', 'child_of', account_ids)]) - user_set = ','.join([str(x) for x in user_ids]) if account_ids2: - acc_set = ','.join([str(x) for x in account_ids2]) cr.execute('SELECT id, unit_amount ' \ 'FROM account_analytic_analysis_summary_user ' \ - 'WHERE account_id in (%s) ' \ - 'AND "user" in (%s) ' % (acc_set, user_set)) + 'WHERE account_id =ANY(%s) ' \ + 'AND "user" =ANY(%s)',(account_ids2, user_ids,)) for sum_id, unit_amount in cr.fetchall(): res[sum_id] = unit_amount for obj_id in ids: @@ -599,14 +586,11 @@ class account_analytic_account_summary_month(osv.osv): account_ids = [int(str(int(x))[:-6]) for x in ids] month_ids = [int(str(int(x))[-6:]) for x in ids] account_ids2 = account_obj.search(cr, uid, [('parent_id', 'child_of', account_ids)]) - month_set = ','.join([str(x) for x in month_ids]) if account_ids2: - acc_set = ','.join([str(x) for x in account_ids2]) cr.execute('SELECT id, unit_amount ' \ 'FROM account_analytic_analysis_summary_month ' \ - 'WHERE account_id in (%s) ' \ - 'AND month_id in (%s) ' % \ - (acc_set, month_set)) + 'WHERE account_id =ANY(%s) ' \ + 'AND month_id =ANY(%s) ',(account_ids2, month_ids,)) for sum_id, unit_amount in cr.fetchall(): res[sum_id] = unit_amount for obj_id in ids: From cf02ffe65f2bcf6c6f592031d1ebad7410dfe487 Mon Sep 17 00:00:00 2001 From: "nch@tinyerp.com" <> Date: Mon, 30 Nov 2009 15:54:22 +0530 Subject: [PATCH 41/53] [IMP]:Account sql queries to parameterized query bzr revid: nch@tinyerp.com-20091130102422-dgvq2kh7y8dm453q --- addons/account/account.py | 30 +++---- addons/account/account_move_line.py | 10 +-- addons/account/partner.py | 14 +-- addons/account/project/project.py | 42 ++++----- .../project/report/analytic_balance.py | 68 +++++++-------- .../account/project/report/analytic_check.py | 5 +- addons/account/project/report/cost_ledger.py | 10 +-- .../report/inverted_analytic_balance.py | 20 ++--- .../project/report/quantity_cost_ledger.py | 33 +++---- addons/account/report/account_balance.py | 18 ++-- addons/account/report/aged_trial_balance.py | 86 +++++++++---------- addons/account/report/general_journal.py | 30 +++---- addons/account/report/general_ledger.py | 46 ++++------ .../report/general_ledger_landscape.py | 58 ++++++------- addons/account/report/partner_balance.py | 51 ++++++----- addons/account/report/tax_report.py | 57 ++++++------ addons/account/report/third_party_ledger.py | 79 +++++++++-------- .../wizard/wizard_account_balance_report.py | 10 +-- .../account/wizard/wizard_fiscalyear_close.py | 21 ++--- .../wizard/wizard_general_ledger_report.py | 26 +++--- .../wizard/wizard_open_closed_fiscalyear.py | 14 +-- .../wizard/wizard_partner_balance_report.py | 23 +++-- addons/account/wizard/wizard_refund.py | 21 ++--- .../wizard/wizard_third_party_ledger.py | 8 +- 24 files changed, 366 insertions(+), 414 deletions(-) diff --git a/addons/account/account.py b/addons/account/account.py index 0229297c2de..38e65bc3ed3 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -201,20 +201,19 @@ class account_account(osv.osv): } #get all the necessary accounts ids2 = self._get_children_and_consol(cr, uid, ids, context) - acc_set = ",".join(map(str, ids2)) #compute for each account the balance/debit/credit from the move lines accounts = {} if ids2: query = self.pool.get('account.move.line')._query_get(cr, uid, context=context) - cr.execute(("SELECT l.account_id as id, " +\ + cr.execute("SELECT l.account_id as id, " +\ ' , '.join(map(lambda x: mapping[x], field_names)) + "FROM " \ "account_move_line l " \ "WHERE " \ - "l.account_id IN (%s) " \ + "l.account_id =ANY(%s) " \ "AND " + query + " " \ - "GROUP BY l.account_id") % (acc_set, )) + "GROUP BY l.account_id",(ids2,)) for res in cr.dictfetchall(): accounts[res['id']] = res @@ -329,7 +328,7 @@ class account_account(osv.osv): if (obj_self in obj_self.child_consol_ids) or (p_id and (p_id is obj_self.id)): return False while(ids): - cr.execute('select distinct child_id from account_account_consol_rel where parent_id in ('+','.join(map(str, ids))+')') + cr.execute('select distinct child_id from account_account_consol_rel where parent_id =ANY(%s)',(ids,)) child_ids = filter(None, map(lambda x: x[0], cr.fetchall())) c_ids = child_ids if (p_id and (p_id in c_ids)) or (obj_self.id in c_ids): @@ -753,7 +752,7 @@ class account_move(osv.osv): def _amount_compute(self, cr, uid, ids, name, args, context, where =''): if not ids: return {} - cr.execute('select move_id,sum(debit) from account_move_line where move_id in ('+','.join(map(str,map(int, ids)))+') group by move_id') + cr.execute('select move_id,sum(debit) from account_move_line where move_id =ANY(%s) group by move_id',(ids,)) result = dict(cr.fetchall()) for id in ids: result.setdefault(id, 0.0) @@ -834,7 +833,7 @@ class account_move(osv.osv): if new_name: self.write(cr, uid, [move.id], {'name':new_name}) - cr.execute('update account_move set state=%s where id in ('+','.join(map(str, ids))+')', ('posted',)) + cr.execute('update account_move set state=%s where id =ANY(%s) ',('posted',ids,)) else: raise osv.except_osv(_('Integrity Error !'), _('You can not validate a non-balanced entry !')) return True @@ -847,7 +846,7 @@ class account_move(osv.osv): if not line.journal_id.update_posted: raise osv.except_osv(_('Error !'), _('You can not modify a posted entry of this journal !\nYou should set the journal to allow cancelling entries if you want to do that.')) if len(ids): - cr.execute('update account_move set state=%s where id in ('+','.join(map(str, ids))+')', ('draft',)) + cr.execute('update account_move set state=%s where id =ANY(%s)',('draft',ids,)) return True def write(self, cr, uid, ids, vals, context={}): @@ -1113,23 +1112,22 @@ class account_tax_code(osv.osv): """ def _sum(self, cr, uid, ids, name, args, context, where =''): ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)]) - acc_set = ",".join(map(str, ids2)) if context.get('based_on', 'invoices') == 'payments': cr.execute('SELECT line.tax_code_id, sum(line.tax_amount) \ FROM account_move_line AS line, \ account_move AS move \ LEFT JOIN account_invoice invoice ON \ (invoice.move_id = move.id) \ - WHERE line.tax_code_id in ('+acc_set+') '+where+' \ + WHERE line.tax_code_id =ANY(%s) '+where+' \ AND move.id = line.move_id \ AND ((invoice.state = \'paid\') \ OR (invoice.id IS NULL)) \ - GROUP BY line.tax_code_id') + GROUP BY line.tax_code_id',(ids2,)) else: cr.execute('SELECT line.tax_code_id, sum(line.tax_amount) \ FROM account_move_line AS line \ - WHERE line.tax_code_id in ('+acc_set+') '+where+' \ - GROUP BY line.tax_code_id') + WHERE line.tax_code_id =ANY(%s) '+where+' \ + GROUP BY line.tax_code_id',(ids2,)) res=dict(cr.fetchall()) for record in self.browse(cr, uid, ids, context): def _rec_get(record): @@ -1204,7 +1202,7 @@ class account_tax_code(osv.osv): def _check_recursion(self, cr, uid, ids): level = 100 while len(ids): - cr.execute('select distinct parent_id from account_tax_code where id in ('+','.join(map(str, ids))+')') + cr.execute('select distinct parent_id from account_tax_code where id =ANY(%s)',(ids,)) ids = filter(None, map(lambda x:x[0], cr.fetchall())) if not level: return False @@ -1824,7 +1822,7 @@ class account_account_template(osv.osv): def _check_recursion(self, cr, uid, ids): level = 100 while len(ids): - cr.execute('select parent_id from account_account_template where id in ('+','.join(map(str, ids))+')') + cr.execute('select parent_id from account_account_template where id =ANY(%s)',(ids,)) ids = filter(None, map(lambda x:x[0], cr.fetchall())) if not level: return False @@ -1883,7 +1881,7 @@ class account_tax_code_template(osv.osv): def _check_recursion(self, cr, uid, ids): level = 100 while len(ids): - cr.execute('select distinct parent_id from account_tax_code_template where id in ('+','.join(map(str, ids))+')') + cr.execute('select distinct parent_id from account_tax_code_template where id =ANY(%s)',(ids,)) ids = filter(None, map(lambda x:x[0], cr.fetchall())) if not level: return False diff --git a/addons/account/account_move_line.py b/addons/account/account_move_line.py index cc1f1fcd3b0..9037c710c0c 100644 --- a/addons/account/account_move_line.py +++ b/addons/account/account_move_line.py @@ -257,7 +257,7 @@ class account_move_line(osv.osv): cursor.execute('SELECT l.id, i.id ' \ 'FROM account_move_line l, account_invoice i ' \ 'WHERE l.move_id = i.move_id ' \ - 'AND l.id in (' + ','.join([str(x) for x in ids]) + ')') + 'AND l.id =ANY(%s)',(ids,)) invoice_ids = [] for line_id, invoice_id in cursor.fetchall(): res[line_id] = invoice_id @@ -552,8 +552,6 @@ class account_move_line(osv.osv): return True def reconcile(self, cr, uid, ids, type='auto', writeoff_acc_id=False, writeoff_period_id=False, writeoff_journal_id=False, context={}): - id_set = ','.join(map(str, ids)) - lines = self.browse(cr, uid, ids, context=context) unrec_lines = filter(lambda x: not x['reconcile_id'], lines) credit = debit = 0.0 @@ -578,10 +576,10 @@ class account_move_line(osv.osv): cr.execute('SELECT account_id, reconcile_id \ FROM account_move_line \ - WHERE id IN ('+id_set+') \ - GROUP BY account_id,reconcile_id') + WHERE id =ANY(%s) \ + GROUP BY account_id,reconcile_id',(ids,)) r = cr.fetchall() -#TODO: move this check to a constraint in the account_move_reconcile object + #TODO: move this check to a constraint in the account_move_reconcile object if (len(r) != 1) and not context.get('fy_closing', False): raise osv.except_osv(_('Error'), _('Entries are not of the same account or already reconciled ! ')) if not unrec_lines: diff --git a/addons/account/partner.py b/addons/account/partner.py index e5b81110c93..7c2b25206c0 100644 --- a/addons/account/partner.py +++ b/addons/account/partner.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 . # ############################################################################## @@ -90,20 +90,20 @@ class res_partner(osv.osv): _description = 'Partner' def _credit_debit_get(self, cr, uid, ids, field_names, arg, context): query = self.pool.get('account.move.line')._query_get(cr, uid, context=context) - cr.execute(("""select + cr.execute("""select l.partner_id, a.type, sum(l.debit-l.credit) from account_move_line l left join account_account a on (l.account_id=a.id) where - a.type in ('receivable','payable') and - l.partner_id in (%s) and + a.type =ANY(%s) and + l.partner_id =ANY(%s) and l.reconcile_id is null and - """ % (','.join(map(str, ids)),))+query+""" + """+query+""" group by l.partner_id, a.type - """) + """,(['receivable','payable'],ids,)) tinvert = { 'credit': 'receivable', 'debit': 'payable' diff --git a/addons/account/project/project.py b/addons/account/project/project.py index f446b6fdf29..c0a3fa5e0bc 100644 --- a/addons/account/project/project.py +++ b/addons/account/project/project.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 . # ############################################################################## @@ -34,15 +34,14 @@ class account_analytic_account(osv.osv): _description = 'Analytic Accounts' def _credit_calc(self, cr, uid, ids, name, arg, context={}): - acc_set = ",".join(map(str, ids)) where_date = '' if context.get('from_date',False): where_date += " AND l.date >= '" + context['from_date'] + "'" if context.get('to_date',False): where_date += " AND l.date <= '" + context['to_date'] + "'" - - cr.execute("SELECT a.id, COALESCE(SUM(l.amount),0) FROM account_analytic_account a LEFT JOIN account_analytic_line l ON (a.id=l.account_id %s) WHERE l.amount<0 and a.id IN (%s) GROUP BY a.id" % (where_date,acc_set)) + + cr.execute("SELECT a.id, COALESCE(SUM(l.amount),0) FROM account_analytic_account a LEFT JOIN account_analytic_line l ON (a.id=l.account_id "+where_date+") WHERE l.amount<0 and a.id =ANY(%s) GROUP BY a.id",(ids,)) r = dict(cr.fetchall()) for i in ids: r.setdefault(i,0.0) @@ -50,15 +49,13 @@ class account_analytic_account(osv.osv): def _debit_calc(self, cr, uid, ids, name, arg, context={}): - acc_set = ",".join(map(str, ids)) - where_date = '' if context.get('from_date',False): where_date += " AND l.date >= '" + context['from_date'] + "'" if context.get('to_date',False): where_date += " AND l.date <= '" + context['to_date'] + "'" - - cr.execute("SELECT a.id, COALESCE(SUM(l.amount),0) FROM account_analytic_account a LEFT JOIN account_analytic_line l ON (a.id=l.account_id %s) WHERE l.amount>0 and a.id IN (%s) GROUP BY a.id" % (where_date,acc_set)) + + cr.execute("SELECT a.id, COALESCE(SUM(l.amount),0) FROM account_analytic_account a LEFT JOIN account_analytic_line l ON (a.id=l.account_id "+where_date+") WHERE l.amount>0 and a.id =ANY(%s) GROUP BY a.id" ,(ids,)) r= dict(cr.fetchall()) for i in ids: r.setdefault(i,0.0) @@ -67,26 +64,25 @@ class account_analytic_account(osv.osv): def _balance_calc(self, cr, uid, ids, name, arg, context={}): res = {} ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)]) - acc_set = ",".join(map(str, ids2)) - + for i in ids: res.setdefault(i,0.0) - - if not acc_set: + + if not ids2: return res - + where_date = '' if context.get('from_date',False): where_date += " AND l.date >= '" + context['from_date'] + "'" if context.get('to_date',False): where_date += " AND l.date <= '" + context['to_date'] + "'" - - cr.execute("SELECT a.id, COALESCE(SUM(l.amount),0) FROM account_analytic_account a LEFT JOIN account_analytic_line l ON (a.id=l.account_id %s) WHERE a.id IN (%s) GROUP BY a.id" % (where_date,acc_set)) - + + cr.execute("SELECT a.id, COALESCE(SUM(l.amount),0) FROM account_analytic_account a LEFT JOIN account_analytic_line l ON (a.id=l.account_id "+where_date+") WHERE a.id =ANY(%s) GROUP BY a.id",(ids2,)) + for account_id, sum in cr.fetchall(): res[account_id] = sum - cr.execute("SELECT a.id, r.currency_id FROM account_analytic_account a INNER JOIN res_company r ON (a.company_id = r.id) where a.id in (%s)" % acc_set) + cr.execute("SELECT a.id, r.currency_id FROM account_analytic_account a INNER JOIN res_company r ON (a.company_id = r.id) where a.id =ANY(%s)",(ids2,)) currency= dict(cr.fetchall()) @@ -115,23 +111,23 @@ class account_analytic_account(osv.osv): res = {} ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)]) acc_set = ",".join(map(str, ids2)) - + for i in ids: res.setdefault(i,0.0) - + if not acc_set: return res - + where_date = '' if context.get('from_date',False): where_date += " AND l.date >= '" + context['from_date'] + "'" if context.get('to_date',False): where_date += " AND l.date <= '" + context['to_date'] + "'" - + cr.execute('SELECT a.id, COALESCE(SUM(l.unit_amount), 0) \ FROM account_analytic_account a \ LEFT JOIN account_analytic_line l ON (a.id = l.account_id ' + where_date + ') \ - WHERE a.id IN ('+acc_set+') GROUP BY a.id') + WHERE a.id =ANY(%s) GROUP BY a.id',(ids2,)) for account_id, sum in cr.fetchall(): res[account_id] = sum diff --git a/addons/account/project/report/analytic_balance.py b/addons/account/project/report/analytic_balance.py index c8204505f84..dc1f1fe4f84 100644 --- a/addons/account/project/report/analytic_balance.py +++ b/addons/account/project/report/analytic_balance.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 . # ############################################################################## @@ -47,7 +47,7 @@ class account_analytic_balance(report_sxw.rml_parse): self.empty_acc = False self.acc_data_dict = {}# maintains a relation with an account with its successors. self.acc_sum_list = []# maintains a list of all ids - + def get_children(self, ids): ids2 = [] read_data = self.pool.get('account.analytic.account').read(self.cr, self.uid, ids,['child_ids','code','complete_name','balance']) @@ -56,23 +56,23 @@ class account_analytic_balance(report_sxw.rml_parse): inculde_empty = True if (not self.empty_acc) and data['balance'] == 0.00: inculde_empty = False - if inculde_empty: + if inculde_empty: self.acc_ids.append(data['id']) self.read_data.append(data) if data['child_ids']: - res = self.get_children(data['child_ids']) - return True - - + res = self.get_children(data['child_ids']) + return True + + def _get_objects(self, empty_acc): if self.read_data: return self.read_data self.empty_acc = empty_acc self.read_data = [] self.get_children(self.ids) - + return self.read_data - + def _lines_g(self, account_id, date1, date2): account_analytic_obj = self.pool.get('account.analytic.account') ids = account_analytic_obj.search(self.cr, self.uid, @@ -86,7 +86,7 @@ class account_analytic_balance(report_sxw.rml_parse): GROUP BY aal.general_account_id, aa.name, aa.code, aal.code \ ORDER BY aal.code", (date1, date2)) res = self.cr.dictfetchall() - + for r in res: if r['balance'] > 0: r['debit'] = r['balance'] @@ -99,7 +99,7 @@ class account_analytic_balance(report_sxw.rml_parse): r['debit'] = 0.0 r['credit'] = 0.0 return res - + def _move_sum(self, account_id, date1, date2, option): if account_id not in self.acc_data_dict: account_analytic_obj = self.pool.get('account.analytic.account') @@ -107,24 +107,23 @@ class account_analytic_balance(report_sxw.rml_parse): self.acc_data_dict[account_id] = ids else: ids = self.acc_data_dict[account_id] - + if option == "credit" : self.cr.execute("SELECT -sum(amount) FROM account_analytic_line \ - WHERE account_id in ("+ ','.join(map(str, ids)) +") \ - AND date>=%s AND date<=%s AND amount<0", - (date1, date2)) + WHERE account_id =ANY(%s) AND date>=%s AND date<=%s AND amount<0", + (ids,date1, date2)) elif option == "debit" : self.cr.execute("SELECT sum(amount) FROM account_analytic_line \ - WHERE account_id in ("+ ','.join(map(str, ids)) +") \ + WHERE account_id =ANY(%s)\ AND date>=%s AND date<=%s AND amount>0", - (date1, date2)) + (ids,date1, date2)) elif option == "quantity" : self.cr.execute("SELECT sum(unit_amount) FROM account_analytic_line \ - WHERE account_id in ("+ ','.join(map(str, ids)) +") \ + WHERE account_id =ANY(%s)\ AND date>=%s AND date<=%s", - (date1, date2)) + (ids,date1, date2)) return self.cr.fetchone()[0] or 0.0 - + # def _move_sum_debit(self, account_id, date1, date2): # account_analytic_obj = self.pool.get('account.analytic.account') @@ -147,12 +146,12 @@ class account_analytic_balance(report_sxw.rml_parse): # AND date>=%s AND date<=%s AND amount<0", # (date1, date2)) # return self.cr.fetchone()[0] or 0.0 -# +# def _move_sum_balance(self, account_id, date1, date2): - debit = self._move_sum(account_id, date1, date2, 'debit') + debit = self._move_sum(account_id, date1, date2, 'debit') credit = self._move_sum(account_id, date1, date2, 'credit') return (debit-credit) - + # def _move_sum_quantity(self, account_id, date1, date2): # account_analytic_obj = self.pool.get('account.analytic.account') # ids = account_analytic_obj.search(self.cr, self.uid, @@ -166,7 +165,6 @@ class account_analytic_balance(report_sxw.rml_parse): def _sum_all(self, accounts, date1, date2, option): ids = map(lambda x: x['id'], accounts) - if not len(ids): return 0.0 @@ -176,25 +174,21 @@ class account_analytic_balance(report_sxw.rml_parse): self.acc_sum_list = ids2 else: ids2 = self.acc_sum_list - if option == "debit" : self.cr.execute("SELECT sum(amount) FROM account_analytic_line \ - WHERE account_id IN ("+','.join(map(str, ids2))+") \ - AND date>=%s AND date<=%s AND amount>0", - (date1, date2)) + WHERE account_id =ANY(%s) AND date>=%s AND date<=%s AND amount>0", + (ids,date1, date2,)) elif option == "credit" : self.cr.execute("SELECT -sum(amount) FROM account_analytic_line \ - WHERE account_id IN ("+','.join(map(str, ids2))+") \ - AND date>=%s AND date<=%s AND amount<0", - (date1, date2)) + WHERE account_id =ANY(%s) AND date>=%s AND date<=%s AND amount<0", + (ids,date1, date2,)) elif option == "quantity" : self.cr.execute("SELECT sum(unit_amount) FROM account_analytic_line \ - WHERE account_id IN ("+','.join(map(str, ids2))+") \ - AND date>=%s AND date<=%s", - (date1, date2)) + WHERE account_id =ANY(%s)AND date>=%s AND date<=%s", + (ids,date1, date2,)) return self.cr.fetchone()[0] or 0.0 - + # def _sum_debit(self, accounts, date1, date2): # ids = map(lambda x: x['id'], accounts) # if not len(ids): @@ -208,7 +202,7 @@ class account_analytic_balance(report_sxw.rml_parse): # AND date>=%s AND date<=%s AND amount>0", # (date1, date2)) # return self.cr.fetchone()[0] or 0.0 -# +# # def _sum_credit(self, accounts, date1, date2): # ids = map(lambda x: x['id'], accounts) # if not len(ids): diff --git a/addons/account/project/report/analytic_check.py b/addons/account/project/report/analytic_check.py index feadef9aa6e..7b588f97691 100644 --- a/addons/account/project/report/analytic_check.py +++ b/addons/account/project/report/analytic_check.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 . # ############################################################################## @@ -43,7 +43,6 @@ class account_analytic_analytic_check(report_sxw.rml_parse): def _lines_p(self, date1, date2): res = [] acc_obj = self.pool.get('account.account') - # print"3333333acc_obj3333333",acc_obj.read(self.cr, self.uid, self.ids, ['name', 'code','user_type']) for a in acc_obj.read(self.cr, self.uid, self.ids, ['name', 'code']): self.cr.execute("SELECT sum(debit), sum(credit) \ diff --git a/addons/account/project/report/cost_ledger.py b/addons/account/project/report/cost_ledger.py index ef0097ab24b..1883eb6d8b5 100644 --- a/addons/account/project/report/cost_ledger.py +++ b/addons/account/project/report/cost_ledger.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 . # ############################################################################## @@ -85,7 +85,7 @@ class account_analytic_cost_ledger(report_sxw.rml_parse): return self.cr.fetchone()[0] or 0.0 def _account_sum_balance(self, account_id, date1, date2): - debit = self._account_sum_debit(account_id, date1, date2) + debit = self._account_sum_debit(account_id, date1, date2) credit = self._account_sum_credit(account_id, date1, date2) return (debit-credit) @@ -93,7 +93,7 @@ class account_analytic_cost_ledger(report_sxw.rml_parse): ids = map(lambda x: x.id, accounts) if not len(ids): return 0.0 - self.cr.execute("SELECT sum(amount) FROM account_analytic_line WHERE account_id IN ("+','.join(map(str, ids))+") AND date>=%s AND date<=%s AND amount>0", (date1, date2)) + self.cr.execute("SELECT sum(amount) FROM account_analytic_line WHERE account_id =ANY(%s) AND date>=%s AND date<=%s AND amount>0", (ids, date1, date2,)) return self.cr.fetchone()[0] or 0.0 def _sum_credit(self, accounts, date1, date2): @@ -101,7 +101,7 @@ class account_analytic_cost_ledger(report_sxw.rml_parse): if not len(ids): return 0.0 ids = map(lambda x: x.id, accounts) - self.cr.execute("SELECT -sum(amount) FROM account_analytic_line WHERE account_id IN ("+','.join(map(str, ids))+") AND date>=%s AND date<=%s AND amount<0", (date1, date2)) + self.cr.execute("SELECT -sum(amount) FROM account_analytic_line WHERE account_id =ANY(%s) AND date>=%s AND date<=%s AND amount<0", (ids,date1, date2,)) return self.cr.fetchone()[0] or 0.0 def _sum_balance(self, accounts, date1, date2): diff --git a/addons/account/project/report/inverted_analytic_balance.py b/addons/account/project/report/inverted_analytic_balance.py index bbc8bfbf003..bc44fc4d1f2 100644 --- a/addons/account/project/report/inverted_analytic_balance.py +++ b/addons/account/project/report/inverted_analytic_balance.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 . # ############################################################################## @@ -40,8 +40,8 @@ class account_inverted_analytic_balance(report_sxw.rml_parse): ids = map(lambda x: x.id, accounts) self.cr.execute("SELECT aa.name AS name, aa.code AS code, sum(aal.amount) AS balance, sum(aal.unit_amount) AS quantity, aa.id AS id \ FROM account_analytic_line AS aal, account_account AS aa \ - WHERE (aal.general_account_id=aa.id) AND (aal.account_id IN ("+','.join(map(str, ids))+")) AND (date>=%s) AND (date<=%s) AND aa.active \ - GROUP BY aal.general_account_id, aa.name, aa.code, aal.code, aa.id ORDER BY aal.code", (date1, date2)) + WHERE (aal.general_account_id=aa.id) AND (aal.account_id =ANY(%s)) AND (date>=%s) AND (date<=%s) AND aa.active \ + GROUP BY aal.general_account_id, aa.name, aa.code, aal.code, aa.id ORDER BY aal.code", (ids,date1,date2,)) res = self.cr.dictfetchall() for r in res: @@ -60,8 +60,8 @@ class account_inverted_analytic_balance(report_sxw.rml_parse): ids = map(lambda x: x.id, accounts) self.cr.execute("SELECT sum(aal.amount) AS balance, sum(aal.unit_amount) AS quantity, aaa.code AS code, aaa.name AS name, account_id \ FROM account_analytic_line AS aal, account_analytic_account AS aaa \ - WHERE aal.account_id=aaa.id AND aal.account_id IN ("+','.join(map(str, ids))+") AND aal.general_account_id=%s AND aal.date>=%s AND aal.date<=%s \ - GROUP BY aal.account_id, general_account_id, aaa.code, aaa.name ORDER BY aal.account_id", (general_account_id, date1, date2)) + WHERE aal.account_id=aaa.id AND aal.account_id =ANY(%s) AND aal.general_account_id=%s AND aal.date>=%s AND aal.date<=%s \ + GROUP BY aal.account_id, general_account_id, aaa.code, aaa.name ORDER BY aal.account_id", (ids,general_account_id, date1, date2,)) res = self.cr.dictfetchall() aaa_obj = self.pool.get('account.analytic.account') @@ -86,14 +86,14 @@ class account_inverted_analytic_balance(report_sxw.rml_parse): ids = map(lambda x: x.id, accounts) self.cr.execute("SELECT sum(amount) \ FROM account_analytic_line \ - WHERE account_id IN ("+','.join(map(str, ids))+") AND date>=%s AND date<=%s AND amount>0", (date1, date2)) + WHERE account_id =ANY(%s) AND date>=%s AND date<=%s AND amount>0", (ids,date1, date2,)) return self.cr.fetchone()[0] or 0.0 - + def _sum_credit(self, accounts, date1, date2): ids = map(lambda x: x.id, accounts) self.cr.execute("SELECT -sum(amount) \ FROM account_analytic_line \ - WHERE account_id IN ("+','.join(map(str, ids))+") AND date>=%s AND date<=%s AND amount<0", (date1, date2)) + WHERE account_id =ANY(%s) AND date>=%s AND date<=%s AND amount<0", (ids,date1, date2,)) return self.cr.fetchone()[0] or 0.0 def _sum_balance(self, accounts, date1, date2): @@ -105,7 +105,7 @@ class account_inverted_analytic_balance(report_sxw.rml_parse): ids = map(lambda x: x.id, accounts) self.cr.execute("SELECT sum(unit_amount) \ FROM account_analytic_line \ - WHERE account_id IN ("+','.join(map(str, ids))+") AND date>=%s AND date<=%s", (date1, date2)) + WHERE account_id =ANY(%s) AND date>=%s AND date<=%s", (ids,date1, date2,)) return self.cr.fetchone()[0] or 0.0 report_sxw.report_sxw('report.account.analytic.account.inverted.balance', 'account.analytic.account', 'addons/account/project/report/inverted_analytic_balance.rml',parser=account_inverted_analytic_balance, header=False) diff --git a/addons/account/project/report/quantity_cost_ledger.py b/addons/account/project/report/quantity_cost_ledger.py index 83c4ff15824..98a1fd974a1 100644 --- a/addons/account/project/report/quantity_cost_ledger.py +++ b/addons/account/project/report/quantity_cost_ledger.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 . # ############################################################################## @@ -52,10 +52,9 @@ class account_analytic_quantity_cost_ledger(report_sxw.rml_parse): WHERE (aal.account_id=%s) AND (aal.date>=%s) \ AND (aal.date<=%s) AND (aal.general_account_id=aa.id) \ AND aa.active \ - AND (aal.journal_id IN (" + - ','.join(map(str, journal_ids)) + ")) \ + AND (aal.journal_id =ANY(%s) ) \ GROUP BY aa.code, aa.name, aa.id ORDER BY aa.code", - (account_id, date1, date2)) + (account_id, date1, date2,journal_ids)) res = self.cr.dictfetchall() return res @@ -80,10 +79,9 @@ class account_analytic_quantity_cost_ledger(report_sxw.rml_parse): account_analytic_journal AS aaj \ WHERE (aal.general_account_id=%s) AND (aal.account_id=%s) \ AND (aal.date>=%s) AND (aal.date<=%s) \ - AND (aal.journal_id=aaj.id) AND (aaj.id IN (" + - ','.join(map(str, journal_ids)) + ")) \ - ORDER BY aal.date, aaj.code, aal.code", - (general_account_id, account_id, date1, date2)) + AND (aal.journal_id=aaj.id) AND (aaj.id =ANY(%s)) \ + ORDER BY aal.date, aaj.code, aal.code", + (general_account_id, account_id, date1, date2,journal_ids,)) res = self.cr.dictfetchall() return res @@ -98,9 +96,8 @@ class account_analytic_quantity_cost_ledger(report_sxw.rml_parse): self.cr.execute("SELECT sum(unit_amount) \ FROM account_analytic_line \ WHERE account_id = %s AND date >= %s AND date <= %s \ - AND journal_id IN (" + - ','.join(map(str, journal_ids)) + ")", - (account_id, date1, date2)) + AND journal_id =ANY(%s)", + (account_id, date1, date2,journal_ids,)) return self.cr.fetchone()[0] or 0.0 def _sum_quantity(self, accounts, date1, date2, journals): @@ -110,18 +107,14 @@ class account_analytic_quantity_cost_ledger(report_sxw.rml_parse): if not journals or not journals[0][2]: self.cr.execute("SELECT sum(unit_amount) \ FROM account_analytic_line \ - WHERE account_id IN (" + - ','.join(map(str, ids)) + ") AND date>=%s AND date<=%s", - (date1, date2)) + WHERE account_id =ANY(%s) AND date>=%s AND date<=%s", + (date1, date2,ids,)) else: journal_ids = journals[0][2] self.cr.execute("SELECT sum(unit_amount) \ FROM account_analytic_line \ - WHERE account_id IN (" + - ','.join(map(str, ids)) + ") AND date >= %s AND date <= %s \ - AND journal_id IN (" + - ','.join(map(str, journal_ids)) + ")", - (date1, date2)) + WHERE account_id =ANY(%s) AND date >= %s AND date <= %s \ + AND journal_id =ANY(%s)",(ids,date1, date2,journal_ids)) return self.cr.fetchone()[0] or 0.0 report_sxw.report_sxw('report.account.analytic.account.quantity_cost_ledger', diff --git a/addons/account/report/account_balance.py b/addons/account/report/account_balance.py index 7402648897e..56686096ac0 100644 --- a/addons/account/report/account_balance.py +++ b/addons/account/report/account_balance.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 . # ############################################################################## @@ -57,10 +57,10 @@ class account_balance(report_sxw.rml_parse): def get_periods(self, form): result='' if form.has_key('periods') and form['periods'][0][2]: - period_ids = ",".join([str(x) for x in form['periods'][0][2] if x]) - self.cr.execute("select name from account_period where id in (%s)" % (period_ids)) + period_ids = form['periods'][0][2] + self.cr.execute("select name from account_period where id =ANY(%s)" ,(period_ids)) res = self.cr.fetchall() - len_res = len(res) + len_res = len(res) for r in res: if (r == res[len_res-1]): result+=r[0]+". " @@ -75,10 +75,10 @@ class account_balance(report_sxw.rml_parse): result+=r.name+". " else: result+=r.name+", " - + return str(result and result[:-1]) or '' - + def lines(self, form, ids={}, done=None, level=1): if not ids: ids = self.ids @@ -98,7 +98,7 @@ class account_balance(report_sxw.rml_parse): ctx['periods'] = form['periods'][0][2] elif form['state']== 'bydate': ctx['date_from'] = form['date_from'] - ctx['date_to'] = form['date_to'] + ctx['date_to'] = form['date_to'] elif form['state'] == 'all' : ctx['periods'] = form['periods'][0][2] ctx['date_from'] = form['date_from'] @@ -165,7 +165,7 @@ class account_balance(report_sxw.rml_parse): # # result_acc += self.lines(form, ids2, done, level+1) return result_acc - + def _sum_credit(self): return self.sum_credit diff --git a/addons/account/report/aged_trial_balance.py b/addons/account/report/aged_trial_balance.py index be53679f70a..a3626640802 100644 --- a/addons/account/report/aged_trial_balance.py +++ b/addons/account/report/aged_trial_balance.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 . # ############################################################################## @@ -47,26 +47,26 @@ class aged_trial_report(rml_parse.rml_parse): def _get_lines(self, form): if (form['result_selection'] == 'customer' ): - self.ACCOUNT_TYPE = "('receivable')" + self.ACCOUNT_TYPE = ['receivable'] elif (form['result_selection'] == 'supplier'): - self.ACCOUNT_TYPE = "('payable')" + self.ACCOUNT_TYPE = ['payable'] else: - self.ACCOUNT_TYPE = "('payable','receivable')" + self.ACCOUNT_TYPE = ['payable','receivable'] res = [] account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line') self.line_query = account_move_line_obj._query_get(self.cr, self.uid, obj='line', context={'fiscalyear': form['fiscalyear']}) - self.cr.execute("""SELECT DISTINCT res_partner.id AS id, - res_partner.name AS name - FROM res_partner,account_move_line AS line, account_account - WHERE (line.account_id=account_account.id) - AND ((reconcile_id IS NULL) - OR (reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > '%s' ))) - AND (line.partner_id=res_partner.id) - AND (account_account.company_id = %s) - ORDER BY res_partner.name""" % (form['date1'],form['company_id'])) + self.cr.execute("""SELECT DISTINCT res_partner.id AS id, + res_partner.name AS name + FROM res_partner,account_move_line AS line, account_account + WHERE (line.account_id=account_account.id) + AND ((reconcile_id IS NULL) + OR (reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > %s ))) + AND (line.partner_id=res_partner.id) + AND (account_account.company_id = %s) + ORDER BY res_partner.name""" , (form['date1'],form['company_id'])) partners = self.cr.dictfetchall() ## mise a 0 du total for i in range(7): @@ -74,20 +74,20 @@ class aged_trial_report(rml_parse.rml_parse): # # Build a string like (1,2,3) for easy use in SQL query - partner_ids = '(' + ','.join( [str(x['id']) for x in partners] ) + ')' + partner_ids = [x['id'] for x in partners] # This dictionary will store the debit-credit for all partners, using partner_id as key. totals = {} - self.cr.execute("""SELECT partner_id, SUM(debit-credit) + self.cr.execute("""SELECT partner_id, SUM(debit-credit) FROM account_move_line AS line, account_account - WHERE (line.account_id = account_account.id) - AND (account_account.type IN %s) - AND (partner_id in %s) + WHERE (line.account_id = account_account.id) + AND (account_account.type =ANY(%s)) + AND (partner_id =ANY (%s)) AND ((reconcile_id IS NULL) - OR (reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > '%s' ))) - AND (account_account.company_id = %s) - AND account_account.active - GROUP BY partner_id""" % (self.ACCOUNT_TYPE, partner_ids,form['date1'],form['company_id'])) + OR (reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > %s ))) + AND (account_account.company_id = %s) + AND account_account.active + GROUP BY partner_id""" , (self.ACCOUNT_TYPE, partner_ids,form['date1'],form['company_id'],)) t = self.cr.fetchall() for i in t: totals[i[0]] = i[1] @@ -95,17 +95,17 @@ class aged_trial_report(rml_parse.rml_parse): # This dictionary will store the future or past of all partners future_past = {} if form['direction_selection'] == 'future': - self.cr.execute("""SELECT partner_id, SUM(debit-credit) - FROM account_move_line AS line, account_account - WHERE (line.account_id=account_account.id) - AND (account_account.type IN %s) - AND (COALESCE(date_maturity,date) < '%s') - AND (partner_id in %s) + self.cr.execute("""SELECT partner_id, SUM(debit-credit) + FROM account_move_line AS line, account_account + WHERE (line.account_id=account_account.id) + AND (account_account.type =ANY (%s)) + AND (COALESCE(date_maturity,date) < %s) + AND (partner_id =ANY (%s)) AND ((reconcile_id IS NULL) - OR (reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > '%s' ))) - AND (account_account.company_id = %s) - AND account_account.active - GROUP BY partner_id"""% (self.ACCOUNT_TYPE, form['date1'], partner_ids,form['date1'], form['company_id'])) + OR (reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > %s ))) + AND (account_account.company_id = %s) + AND account_account.active + GROUP BY partner_id""", (self.ACCOUNT_TYPE, form['date1'], partner_ids,form['date1'], form['company_id'],)) t = self.cr.fetchall() for i in t: future_past[i[0]] = i[1] @@ -113,14 +113,14 @@ class aged_trial_report(rml_parse.rml_parse): self.cr.execute("""SELECT partner_id, SUM(debit-credit) FROM account_move_line AS line, account_account WHERE (line.account_id=account_account.id) - AND (account_account.type IN %s) - AND (COALESCE(date_maturity,date) > '%s') - AND (partner_id in %s) + AND (account_account.type =ANY (%s)) + AND (COALESCE(date_maturity,date) > %s) + AND (partner_id =ANY (%s)) AND ((reconcile_id IS NULL) - OR (reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > '%s' ))) + OR (reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > %s ))) AND (account_account.company_id = %s) AND account_account.active - GROUP BY partner_id""" % (self.ACCOUNT_TYPE, form['date1'], partner_ids, form['date1'], form['company_id'])) + GROUP BY partner_id""" , (self.ACCOUNT_TYPE, form['date1'], partner_ids, form['date1'], form['company_id'],)) t = self.cr.fetchall() for i in t: future_past[i[0]] = i[1] @@ -132,14 +132,14 @@ class aged_trial_report(rml_parse.rml_parse): self.cr.execute("""SELECT partner_id, SUM(debit-credit) FROM account_move_line AS line, account_account WHERE (line.account_id=account_account.id) - AND (account_account.type IN %s) - AND (COALESCE(date_maturity,date) BETWEEN '%s' AND '%s') - AND (partner_id in %s ) + AND (account_account.type =ANY (%s)) + AND (COALESCE(date_maturity,date) BETWEEN %s AND %s) + AND (partner_id =ANY (%s)) AND ((reconcile_id IS NULL) - OR (reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > '%s' ))) + OR (reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > %s ))) AND (account_account.company_id = %s) AND account_account.active - GROUP BY partner_id""" % (self.ACCOUNT_TYPE, form[str(i)]['start'], form[str(i)]['stop'],partner_ids ,form['date1'] ,form['company_id'])) + GROUP BY partner_id""" , (self.ACCOUNT_TYPE, form[str(i)]['start'], form[str(i)]['stop'],partner_ids ,form['date1'] ,form['company_id'],)) t = self.cr.fetchall() d = {} diff --git a/addons/account/report/general_journal.py b/addons/account/report/general_journal.py index bc29eb4966a..fd10c100f8a 100644 --- a/addons/account/report/general_journal.py +++ b/addons/account/report/general_journal.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 . # ############################################################################## @@ -41,10 +41,10 @@ class journal_print(report_sxw.rml_parse): def set_context(self, objects, data, ids, report_type = None): super(journal_print, self).set_context(objects, data, ids, report_type) - self.cr.execute('select period_id, journal_id from account_journal_period where id in (' + ','.join([str(id) for id in ids]) + ')') + self.cr.execute('select period_id, journal_id from account_journal_period where id =ANY(%s)',(ids,)) res = self.cr.fetchall() - self.period_ids = ','.join([str(x[0]) for x in res]) - self.journal_ids = ','.join([str(x[1]) for x in res]) + self.period_ids = map(lambda x:x[0],res) + self.journal_ids = map(lambda x:x[1],res) # returns a list of period objs def periods(self, journal_period_objs): @@ -74,7 +74,7 @@ class journal_print(report_sxw.rml_parse): periods.append(data.period_id.id) for period in periods: period_data = self.pool.get('account.period').browse(self.cr, self.uid, period) - self.cr.execute('select j.code, j.name, sum(l.debit) as debit, sum(l.credit) as credit from account_move_line l left join account_journal j on (l.journal_id=j.id) where period_id=%s and journal_id in (' + ','.join(map(str, journal_id)) + ') and l.state<>\'draft\' group by j.id, j.code, j.name', (period,)) + self.cr.execute('select j.code, j.name, sum(l.debit) as debit, sum(l.credit) as credit from account_move_line l left join account_journal j on (l.journal_id=j.id) where period_id=%s and journal_id =ANY(%s) and l.state<>\'draft\' group by j.id, j.code, j.name', (period,journal_id,)) res = self.cr.dictfetchall() res[0].update({'period_name':period_data.name}) res[0].update({'pid':period}) @@ -82,45 +82,45 @@ class journal_print(report_sxw.rml_parse): return lines_data if not self.journal_ids: return [] - self.cr.execute('select j.code, j.name, sum(l.debit) as debit, sum(l.credit) as credit from account_move_line l left join account_journal j on (l.journal_id=j.id) where period_id=%s and journal_id in (' + self.journal_ids + ') and l.state<>\'draft\' group by j.id, j.code, j.name', (period_id,)) + self.cr.execute('select j.code, j.name, sum(l.debit) as debit, sum(l.credit) as credit from account_move_line l left join account_journal j on (l.journal_id=j.id) where period_id=%s and journal_id =ANY(%s) and l.state<>\'draft\' group by j.id, j.code, j.name', (period_id,self.journal_ids,)) res = self.cr.dictfetchall() return res def _sum_debit_period(self, period_id,journal_id=None): if type(journal_id)==type([]): - self.cr.execute('select sum(debit) from account_move_line where period_id=%s and journal_id in (' + ','.join(map(str, journal_id)) + ') and state<>\'draft\'', (period_id,)) + self.cr.execute('select sum(debit) from account_move_line where period_id=%s and journal_id =ANY(%s) and state<>\'draft\'', (period_id,journal_id,)) return self.cr.fetchone()[0] or 0.0 if not self.journal_ids: return 0.0 - self.cr.execute('select sum(debit) from account_move_line where period_id=%s and journal_id in (' + self.journal_ids + ') and state<>\'draft\'', (period_id,)) + self.cr.execute('select sum(debit) from account_move_line where period_id=%s and journal_id =ANY(%s) and state<>\'draft\'', (period_id,self.journal_ids,)) return self.cr.fetchone()[0] or 0.0 def _sum_credit_period(self, period_id,journal_id=None): if type(journal_id)==type([]): - self.cr.execute('select sum(credit) from account_move_line where period_id=%s and journal_id in (' + ','.join(map(str, journal_id)) + ') and state<>\'draft\'', (period_id,)) + self.cr.execute('select sum(credit) from account_move_line where period_id=%s and journal_id =ANY(%s) and state<>\'draft\'', (period_id,journal_id,)) return self.cr.fetchone()[0] or 0.0 if not self.journal_ids: return 0.0 - self.cr.execute('select sum(credit) from account_move_line where period_id=%s and journal_id in (' + self.journal_ids + ') and state<>\'draft\'', (period_id,)) + self.cr.execute('select sum(credit) from account_move_line where period_id=%s and journal_id =ANY(%s) and state<>\'draft\'', (period_id,self.journal_ids,)) return self.cr.fetchone()[0] or 0.0 def _sum_debit(self,period_id=None,journal_id=None): if type(period_id)==type([]): - self.cr.execute('select sum(debit) from account_move_line where period_id in (' + ','.join(map(str, period_id)) + ') and journal_id in (' + ','.join(map(str, journal_id)) + ') and state<>\'draft\'') + self.cr.execute('select sum(debit) from account_move_line where period_id =ANY(%s) and journal_id =ANY(%s) and state<>\'draft\'',(period_id,journal_id,)) return self.cr.fetchone()[0] or 0.0 if not self.journal_ids or not self.period_ids: return 0.0 - self.cr.execute('select sum(debit) from account_move_line where period_id in (' + self.period_ids + ') and journal_id in (' + self.journal_ids + ') and state<>\'draft\'') + self.cr.execute('select sum(debit) from account_move_line where period_id =ANY(%s) and journal_id =ANY(%s) and state<>\'draft\'',(self.period_ids,self.journal_ids,)) return self.cr.fetchone()[0] or 0.0 def _sum_credit(self,period_id=None,journal_id=None): if type(period_id)==type([]): - self.cr.execute('select sum(credit) from account_move_line where period_id in (' + ','.join(map(str, period_id)) + ') and journal_id in (' + ','.join(map(str, journal_id)) + ') and state<>\'draft\'') + self.cr.execute('select sum(credit) from account_move_line where period_id =ANY(%s) and journal_id =ANY(%s) and state<>\'draft\'',(period_id,journal_id,)) return self.cr.fetchone()[0] or 0.0 if not self.journal_ids or not self.period_ids: return 0.0 - self.cr.execute('select sum(credit) from account_move_line where period_id in (' + self.period_ids + ') and journal_id in (' + self.journal_ids + ') and state<>\'draft\'') + self.cr.execute('select sum(credit) from account_move_line where period_id =ANY(%s) and journal_id =ANY(%s) and state<>\'draft\'',(self.period_ids,self.journal_ids,)) return self.cr.fetchone()[0] or 0.0 report_sxw.report_sxw('report.account.general.journal', 'account.journal.period', 'addons/account/report/general_journal.rml',parser=journal_print) report_sxw.report_sxw('report.account.general.journal.wiz', 'account.journal.period', 'addons/account/report/wizard_general_journal.rml',parser=journal_print, header=False) diff --git a/addons/account/report/general_ledger.py b/addons/account/report/general_ledger.py index beb96f3cf24..5db2545d070 100644 --- a/addons/account/report/general_ledger.py +++ b/addons/account/report/general_ledger.py @@ -89,7 +89,7 @@ class general_ledger(rml_parse.rml_parse): # We have the account ID we will search all account move line from now until this time # We are in the case of we are on the top of the account move Line cr.execute('SELECT distinct(ac.code) as code_rest,ac.name as name_rest from account_account AS ac, account_move_line mv\ - where ac.id = mv.account_id and mv.move_id = ' + num_id_move +' and mv.account_id <> ' + account_id ) + where ac.id = mv.account_id and mv.move_id = %s and mv.account_id <> %s' ,(num_id_move,account_id,)) res_mv = cr.dictfetchall() # we need a result more than 2 line to make the test so we will made the the on 1 because we have exclude the current line if (len(res_mv) >=1): @@ -120,15 +120,11 @@ class general_ledger(rml_parse.rml_parse): ## This function will return the most aged date periods = form['periods'][0][2] if not periods: - sql = """ - Select min(p.date_start) as start_date,max(p.date_stop) as stop_date from account_period as p where p.fiscalyear_id = """ + str(form['fiscalyear']) + """ - """ + self.cr.execute(""" + Select min(p.date_start) as start_date,max(p.date_stop) as stop_date from account_period as p where p.fiscalyear_id = %s""",(form['fiscalyear'],)) else: - periods_id = ','.join(map(str, periods)) - sql = """ - Select min(p.date_start) as start_date,max(p.date_stop) as stop_date from account_period as p where p.id in ( """ + periods_id + """) - """ - self.cr.execute(sql) + self.cr.execute(""" + Select min(p.date_start) as start_date,max(p.date_stop) as stop_date from account_period as p where p.id =ANY(%s)""",(periods,)) res = self.cr.dictfetchall() borne_min = res[0]['start_date'] borne_max = res[0]['stop_date'] @@ -138,15 +134,11 @@ class general_ledger(rml_parse.rml_parse): elif form['state'] == 'all': periods = form['periods'][0][2] if not periods: - sql = """ - Select min(p.date_start) as start_date,max(p.date_stop) as stop_date from account_period as p where p.fiscalyear_id = """ + str(form['fiscalyear']) + """ - """ + self.cr.execute(""" + Select min(p.date_start) as start_date,max(p.date_stop) as stop_date from account_period as p where p.fiscalyear_id = %s""",(form['fiscalyear'],)) else: - periods_id = ','.join(map(str, periods)) - sql = """ - Select min(p.date_start) as start_date,max(p.date_stop) as stop_date from account_period as p where p.id in ( """ + periods_id + """) - """ - self.cr.execute(sql) + self.cr.execute(""" + Select min(p.date_start) as start_date,max(p.date_stop) as stop_date from account_period as p where p.id =ANY(%s)""",(periods,)) res = self.cr.dictfetchall() period_min = res[0]['start_date'] period_max = res[0]['stop_date'] @@ -230,8 +222,8 @@ class general_ledger(rml_parse.rml_parse): else: ## We will now compute solde initiaux for move in res: - SOLDEINIT = "SELECT sum(l.debit) AS sum_debit, sum(l.credit) AS sum_credit FROM account_move_line l WHERE l.account_id = " + str(move.id) + " AND l.date < '" + self.borne_date['max_date'] + "'" + " AND l.date > '" + self.borne_date['min_date'] + "'" - self.cr.execute(SOLDEINIT) + self.cr.execute("""SELECT sum(l.debit) AS sum_debit, sum(l.credit) AS sum_credit FROM account_move_line l \ + WHERE l.account_id = %s AND l.date < %s AND l.date > %s""",(move.id,self.borne_date['max_date'],self.borne_date['min_date'])) resultat = self.cr.dictfetchall() if resultat[0] : if resultat[0]['sum_debit'] == None: @@ -284,7 +276,7 @@ class general_ledger(rml_parse.rml_parse): for l in res: line = self.pool.get('account.move.line').browse(self.cr, self.uid, l['id']) l['move'] = line.move_id.name - self.cr.execute('Select id from account_invoice where move_id =%s'%(line.move_id.id)) + self.cr.execute('Select id from account_invoice where move_id =%s',(line.move_id.id,)) tmpres = self.cr.dictfetchall() if len(tmpres) > 0 : inv = self.pool.get('account.invoice').browse(self.cr, self.uid, tmpres[0]['id']) @@ -312,7 +304,7 @@ class general_ledger(rml_parse.rml_parse): self.cr.execute("SELECT sum(debit) "\ "FROM account_move_line l "\ - "WHERE l.account_id = %s AND %s "%(account.id, self.query)) + "WHERE l.account_id = %s AND "+self.query,(account.id,)) ## Add solde init to the result # sum_debit = self.cr.fetchone()[0] or 0.0 @@ -326,7 +318,7 @@ class general_ledger(rml_parse.rml_parse): self.cr.execute("SELECT sum(credit) "\ "FROM account_move_line l "\ - "WHERE l.account_id = %s AND %s "%(account.id,self.query)) + "WHERE l.account_id = %s AND "+ self.query,(account.id,)) ## Add solde init to the result # sum_credit = self.cr.fetchone()[0] or 0.0 @@ -340,7 +332,7 @@ class general_ledger(rml_parse.rml_parse): def _sum_solde_account(self, account, form): self.cr.execute("SELECT (sum(debit) - sum(credit)) as tot_solde "\ "FROM account_move_line l "\ - "WHERE l.account_id = %s AND %s"%(account.id,self.query)) + "WHERE l.account_id = %s AND "+ self.query,(account.id,)) sum_solde = self.cr.fetchone()[0] or 0.0 if form.get('soldeinit', False): sum_solde += account.init_debit - account.init_credit @@ -352,7 +344,7 @@ class general_ledger(rml_parse.rml_parse): return 0.0 self.cr.execute("SELECT sum(debit) "\ "FROM account_move_line l "\ - "WHERE l.account_id in ("+','.join(map(str, self.child_ids))+") AND "+self.query) + "WHERE l.account_id =ANY(%s) AND "+ self.query,(self.child_ids,)) sum_debit = self.cr.fetchone()[0] or 0.0 return sum_debit @@ -361,7 +353,7 @@ class general_ledger(rml_parse.rml_parse): return 0.0 self.cr.execute("SELECT sum(credit) "\ "FROM account_move_line l "\ - "WHERE l.account_id in ("+','.join(map(str, self.child_ids))+") AND "+self.query) + "WHERE l.account_id =ANY(%s) AND "+ self.query,(self.child_ids,)) ## Add solde init to the result # sum_credit = self.cr.fetchone()[0] or 0.0 @@ -372,14 +364,14 @@ class general_ledger(rml_parse.rml_parse): return 0.0 self.cr.execute("SELECT (sum(debit) - sum(credit)) as tot_solde "\ "FROM account_move_line l "\ - "WHERE l.account_id in ("+','.join(map(str, self.child_ids))+") AND "+self.query) + "WHERE l.account_id =ANY(%s) AND "+ self.query,(self.child_ids,)) sum_solde = self.cr.fetchone()[0] or 0.0 return sum_solde def _set_get_account_currency_code(self, account_id): self.cr.execute("SELECT c.code as code "\ "FROM res_currency c,account_account as ac "\ - "WHERE ac.id = %s AND ac.currency_id = c.id"%(account_id)) + "WHERE ac.id = %s AND ac.currency_id = c.id",(account_id,)) result = self.cr.fetchone() if result: self.account_currency = result[0] diff --git a/addons/account/report/general_ledger_landscape.py b/addons/account/report/general_ledger_landscape.py index c1f9a374145..c0d48ad6e0e 100644 --- a/addons/account/report/general_ledger_landscape.py +++ b/addons/account/report/general_ledger_landscape.py @@ -22,7 +22,7 @@ # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # ############################################################################## @@ -83,14 +83,14 @@ class general_ledger_landscape(rml_parse.rml_parse): # # result[account_line.id] = ' ' - num_id_move = str(account_line.move_id.id) - num_id_line = str(account_line.id) - account_id = str(account_line.account_id.id) + num_id_move = account_line.move_id.id + num_id_line = account_line.id + account_id = account_line.account_id.id # search the basic account # We have the account ID we will search all account move line from now until this time # We are in the case of we are on the top of the account move Line cr.execute('SELECT distinct(ac.code) as code_rest,ac.name as name_rest from account_account AS ac, account_move_line mv\ - where ac.id = mv.account_id and mv.move_id = ' + num_id_move +' and mv.account_id <> ' + account_id ) + where ac.id = mv.account_id and mv.move_id = %s and mv.account_id <> %s' , (num_id_move,account_id,)) res_mv = cr.dictfetchall() # we need a result more than 2 line to make the test so we will made the the on 1 because we have exclude the current line if (len(res_mv) >=1): @@ -121,15 +121,12 @@ class general_ledger_landscape(rml_parse.rml_parse): ## This function will return the most aged date periods = form['periods'][0][2] if not periods: - sql = """ - Select min(p.date_start) as start_date,max(p.date_stop) as stop_date from account_period as p where p.fiscalyear_id = """ + str(form['fiscalyear']) + """ - """ + self.cr.execute(""" + Select min(p.date_start) as start_date,max(p.date_stop) as stop_date from account_period as p where p.fiscalyear_id = %s""" ,(form['fiscalyear'],)) else: - periods_id = ','.join(map(str, periods)) - sql = """ - Select min(p.date_start) as start_date,max(p.date_stop) as stop_date from account_period as p where p.id in ( """ + periods_id + """) - """ - self.cr.execute(sql) + self.cr.execute(""" + Select min(p.date_start) as start_date,max(p.date_stop) as stop_date from account_period as p where p.id =ANY(%s)""",(periods,)) + res = self.cr.dictfetchall() borne_min = res[0]['start_date'] borne_max = res[0]['stop_date'] @@ -139,15 +136,12 @@ class general_ledger_landscape(rml_parse.rml_parse): elif form['state'] == 'all': periods = form['periods'][0][2] if not periods: - sql = """ - Select min(p.date_start) as start_date,max(p.date_stop) as stop_date from account_period as p where p.fiscalyear_id = """ + str(form['fiscalyear']) + """ - """ + self.cr.execute(""" + Select min(p.date_start) as start_date,max(p.date_stop) as stop_date from account_period as p where p.fiscalyear_id = = %s""" ,(form['fiscalyear'],)) + else: - periods_id = ','.join(map(str, periods)) - sql = """ - Select min(p.date_start) as start_date,max(p.date_stop) as stop_date from account_period as p where p.id in ( """ + periods_id + """) - """ - self.cr.execute(sql) + self.cr.execute(""" + Select min(p.date_start) as start_date,max(p.date_stop) as stop_date from account_period as p where p.id =ANY(%s)""",(periods,)) res = self.cr.dictfetchall() period_min = res[0]['start_date'] period_max = res[0]['stop_date'] @@ -178,8 +172,6 @@ class general_ledger_landscape(rml_parse.rml_parse): def get_children_accounts(self, account, form): - - print self.ids self.child_ids = self.pool.get('account.account').search(self.cr, self.uid, [('parent_id', 'child_of', self.ids)]) # @@ -233,8 +225,8 @@ class general_ledger_landscape(rml_parse.rml_parse): else: ## We will now compute solde initiaux for move in res: - SOLDEINIT = "SELECT sum(l.debit) AS sum_debit, sum(l.credit) AS sum_credit FROM account_move_line l WHERE l.account_id = " + str(move.id) + " AND l.date < '" + self.borne_date['max_date'] + "'" + " AND l.date > '" + self.borne_date['min_date'] + "'" - self.cr.execute(SOLDEINIT) + self.cr.execute("""SELECT sum(l.debit) AS sum_debit, sum(l.credit) AS sum_credit FROM account_move_line l \ + WHERE l.account_id = %s AND l.date < %s AND l.date > %s""",(move.id,self.borne_date['max_date'],self.borne_date['min_date'])) resultat = self.cr.dictfetchall() if resultat[0] : if resultat[0]['sum_debit'] == None: @@ -287,7 +279,7 @@ class general_ledger_landscape(rml_parse.rml_parse): for l in res: line = self.pool.get('account.move.line').browse(self.cr, self.uid, l['id']) l['move'] = line.move_id.name - self.cr.execute('Select id from account_invoice where move_id =%s'%(line.move_id.id)) + self.cr.execute('Select id from account_invoice where move_id =%s',(line.move_id.id,)) tmpres = self.cr.dictfetchall() if len(tmpres) > 0 : inv = self.pool.get('account.invoice').browse(self.cr, self.uid, tmpres[0]['id']) @@ -315,7 +307,7 @@ class general_ledger_landscape(rml_parse.rml_parse): self.cr.execute("SELECT sum(debit) "\ "FROM account_move_line l "\ - "WHERE l.account_id = %s AND %s "%(account.id, self.query)) + "WHERE l.account_id = %s AND "+self.query,(account.id,)) ## Add solde init to the result # sum_debit = self.cr.fetchone()[0] or 0.0 @@ -329,7 +321,7 @@ class general_ledger_landscape(rml_parse.rml_parse): self.cr.execute("SELECT sum(credit) "\ "FROM account_move_line l "\ - "WHERE l.account_id = %s AND %s "%(account.id,self.query)) + "WHERE l.account_id = %s AND "+self.query,(account.id,)) ## Add solde init to the result # sum_credit = self.cr.fetchone()[0] or 0.0 @@ -343,7 +335,7 @@ class general_ledger_landscape(rml_parse.rml_parse): def _sum_solde_account(self, account, form): self.cr.execute("SELECT (sum(debit) - sum(credit)) as tot_solde "\ "FROM account_move_line l "\ - "WHERE l.account_id = %s AND %s"%(account.id,self.query)) + "WHERE l.account_id = %s AND "+self.query,(account.id,)) sum_solde = self.cr.fetchone()[0] or 0.0 if form.get('soldeinit',False): sum_solde += account.init_debit - account.init_credit @@ -355,7 +347,7 @@ class general_ledger_landscape(rml_parse.rml_parse): return 0.0 self.cr.execute("SELECT sum(debit) "\ "FROM account_move_line l "\ - "WHERE l.account_id in ("+','.join(map(str, self.child_ids))+") AND "+self.query) + "WHERE l.account_id =ANY(%s) AND "+self.query,(self.child_ids,)) sum_debit = self.cr.fetchone()[0] or 0.0 return sum_debit @@ -364,7 +356,7 @@ class general_ledger_landscape(rml_parse.rml_parse): return 0.0 self.cr.execute("SELECT sum(credit) "\ "FROM account_move_line l "\ - "WHERE l.account_id in ("+','.join(map(str, self.child_ids))+") AND "+self.query) + "WHERE l.account_id =ANY(%s) AND "+self.query,(self.child_ids,)) ## Add solde init to the result # sum_credit = self.cr.fetchone()[0] or 0.0 @@ -375,14 +367,14 @@ class general_ledger_landscape(rml_parse.rml_parse): return 0.0 self.cr.execute("SELECT (sum(debit) - sum(credit)) as tot_solde "\ "FROM account_move_line l "\ - "WHERE l.account_id in ("+','.join(map(str, self.child_ids))+") AND "+self.query) + "WHERE l.account_id =ANY(%s) AND "+self.query,(self.child_ids,)) sum_solde = self.cr.fetchone()[0] or 0.0 return sum_solde def _set_get_account_currency_code(self, account_id): self.cr.execute("SELECT c.code as code "\ "FROM res_currency c,account_account as ac "\ - "WHERE ac.id = %s AND ac.currency_id = c.id"%(account_id)) + "WHERE ac.id = %s AND ac.currency_id = c.id",(account_id,)) result = self.cr.fetchone() if result: self.account_currency = result[0] diff --git a/addons/account/report/partner_balance.py b/addons/account/report/partner_balance.py index 421696f6d25..d0dcb0962a6 100755 --- a/addons/account/report/partner_balance.py +++ b/addons/account/report/partner_balance.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 . # ############################################################################## @@ -166,27 +166,26 @@ class partner_balance(report_sxw.rml_parse): ## self.date_lst_string ='' if self.date_lst: - self.date_lst_string = '\'' + '\',\''.join(map(str, self.date_lst)) + '\'' - + self.date_lst_string = '\'' + '\',\''.join(map(str, self.date_lst)) + '\'' ## Compute Code account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line') # if (data['form']['result_selection'] == 'customer' ): - self.ACCOUNT_TYPE = "('receivable')" + self.ACCOUNT_TYPE = ['receivable'] elif (data['form']['result_selection'] == 'supplier'): - self.ACCOUNT_TYPE = "('payable')" + self.ACCOUNT_TYPE = ['payable'] else: - self.ACCOUNT_TYPE = "('payable','receivable')" + self.ACCOUNT_TYPE = ['payable','receivable'] # self.cr.execute("SELECT a.id " \ "FROM account_account a " \ "LEFT JOIN account_account_type t " \ "ON (a.type = t.code) " \ "WHERE a.company_id = %s " \ - "AND a.type IN " + self.ACCOUNT_TYPE + " " \ - "AND a.active", (data['form']['company_id'],)) - self.account_ids = ','.join([str(a) for (a,) in self.cr.fetchall()]) + "AND a.type =ANY(%s) "\ + "AND a.active", (data['form']['company_id'],self.ACCOUNT_TYPE,)) + self.account_ids = [a for (a,) in self.cr.fetchall()] super(partner_balance, self).set_context(objects, data, ids, report_type) @@ -214,11 +213,11 @@ class partner_balance(report_sxw.rml_parse): ") AS enlitige " \ "FROM account_move_line l LEFT JOIN res_partner p ON (l.partner_id=p.id) " \ "JOIN account_account ac ON (l.account_id = ac.id)" \ - "WHERE ac.type IN " + self.ACCOUNT_TYPE + " " \ + "WHERE ac.type =ANY(%s) " "AND l.date IN (" + self.date_lst_string + ") " \ - "AND ac.company_id = "+ str(data['form']['company_id']) +" " \ + "AND ac.company_id = %s" \ "GROUP BY p.id, p.ref, p.name,l.account_id,ac.name,ac.code " \ - "ORDER BY l.account_id,p.name") + "ORDER BY l.account_id,p.name",(self.ACCOUNT_TYPE,data['form']['company_id'],)) res = self.cr.dictfetchall() for r in res: full_account.append(r) @@ -355,8 +354,8 @@ class partner_balance(report_sxw.rml_parse): self.cr.execute( "SELECT sum(debit) " \ "FROM account_move_line AS l " \ - "WHERE l.account_id IN (" + self.account_ids + ") " \ - "AND l.date IN (" + self.date_lst_string + ") " ) + "WHERE l.account_id =ANY(%s)" \ + "AND l.date IN (" + self.date_lst_string + ")" ,(self.account_ids,)) temp_res = float(self.cr.fetchone()[0] or 0.0) result_tmp = result_tmp + temp_res @@ -373,8 +372,8 @@ class partner_balance(report_sxw.rml_parse): self.cr.execute( "SELECT sum(credit) " \ "FROM account_move_line AS l " \ - "WHERE l.account_id IN (" + self.account_ids + ") " \ - "AND l.date IN (" + self.date_lst_string + ") " ) + "WHERE l.account_id =ANY(%s)" \ + "AND l.date IN (" + self.date_lst_string + ")" ,(self.account_ids,)) temp_res = float(self.cr.fetchone()[0] or 0.0) result_tmp = result_tmp + temp_res @@ -390,9 +389,9 @@ class partner_balance(report_sxw.rml_parse): self.cr.execute( "SELECT sum(debit-credit) " \ "FROM account_move_line AS l " \ - "WHERE l.account_id IN (" + self.account_ids + ") " \ - "AND l.date IN (" + self.date_lst_string + ") " \ - "AND l.blocked=TRUE " ) + "WHERE l.account_id =ANY(%s)" \ + "AND l.date IN (" + self.date_lst_string + ")"\ + "AND l.blocked=TRUE " ,(self.account_ids,)) temp_res = float(self.cr.fetchone()[0] or 0.0) result_tmp = result_tmp + temp_res @@ -411,9 +410,9 @@ class partner_balance(report_sxw.rml_parse): "ELSE 0 " \ "END " \ "FROM account_move_line AS l " \ - "WHERE l.account_id IN (" + self.account_ids + ") " \ - "AND l.date IN (" + self.date_lst_string + ") " \ - "GROUP BY l.partner_id") + "WHERE l.account_id =ANY(%s)" \ + "AND l.date IN (" + self.date_lst_string + ")" \ + "GROUP BY l.partner_id",(self.account_ids,)) a = self.cr.fetchone()[0] if self.cr.fetchone() != None: @@ -438,9 +437,9 @@ class partner_balance(report_sxw.rml_parse): "ELSE 0 " \ "END " \ "FROM account_move_line AS l " \ - "WHERE l.account_id IN (" + self.account_ids + ") " \ - "AND l.date IN (" + self.date_lst_string + ") " \ - "GROUP BY l.partner_id") + "WHERE l.account_id =ANY(%s)" \ + "AND l.date IN (" + self.date_lst_string + ")" \ + "GROUP BY l.partner_id",(self.account_ids,)) a = self.cr.fetchone()[0] or 0.0 if self.cr.fetchone() != None: diff --git a/addons/account/report/tax_report.py b/addons/account/report/tax_report.py index 4e9e252be2c..a559f2b2af6 100644 --- a/addons/account/report/tax_report.py +++ b/addons/account/report/tax_report.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 . # ############################################################################## @@ -41,25 +41,25 @@ class tax_report(rml_parse.rml_parse): 'get_lines' : self._get_lines, }) - + def _get_lines(self, based_on,period_list,company_id=False, parent=False, level=0): res = self._get_codes(based_on,company_id,parent,level,period_list) - + if period_list[0][2] : res = self._add_codes(based_on,res,period_list) else : self.cr.execute ("select id from account_fiscalyear") fy = self.cr.fetchall() - self.cr.execute ("select id from account_period where fiscalyear_id = %d"%(fy[0][0])) + self.cr.execute ("select id from account_period where fiscalyear_id = %s",(fy[0][0],)) periods = self.cr.fetchall() for p in periods : period_list[0][2].append(p[0]) res = self._add_codes(based_on,res,period_list) - + i = 0 top_result = [] while i < len(res): - + res_dict = { 'code' : res[i][1].code, 'name' : res[i][1].name, 'debit' : 0, @@ -69,7 +69,7 @@ class tax_report(rml_parse.rml_parse): 'level' : res[i][0], 'pos' : 0 } - + top_result.append(res_dict) res_general = self._get_general(res[i][1].id,period_list,company_id,based_on) ind_general = 0 @@ -89,7 +89,6 @@ class tax_report(rml_parse.rml_parse): def _get_general(self, tax_code_id,period_list ,company_id, based_on): res=[] - period_sql_list = ','.join(map(str, period_list[0][2])) if based_on == 'payments': self.cr.execute('SELECT SUM(line.tax_amount) AS tax_amount, \ SUM(line.debit) AS debit, \ @@ -108,11 +107,11 @@ class tax_report(rml_parse.rml_parse): AND line.account_id = account.id \ AND account.company_id = %s \ AND move.id = line.move_id \ - AND line.period_id IN ('+ period_sql_list +') \ + AND line.period_id =ANY(%s) \ AND ((invoice.state = %s) \ OR (invoice.id IS NULL)) \ GROUP BY account.id,account.name,account.code', ('draft',tax_code_id, - company_id, 'paid')) + company_id, period_list[0][2],'paid',)) else : self.cr.execute('SELECT SUM(line.tax_amount) AS tax_amount, \ @@ -128,14 +127,14 @@ class tax_report(rml_parse.rml_parse): AND line.tax_code_id = %s \ AND line.account_id = account.id \ AND account.company_id = %s \ - AND line.period_id IN ('+ period_sql_list +') \ + AND line.period_id =ANY(%s)\ AND account.active \ GROUP BY account.id,account.name,account.code', ('draft',tax_code_id, - company_id)) + company_id,period_list[0][2],)) res = self.cr.dictfetchall() - + #AND line.period_id IN ('+ period_sql_list +') \ - + i = 0 while i= int(accounts[bcl_rup_ind]['level']) and bcl_rup_ind >= 0 ): tot_elem = copy.copy(accounts[bcl_rup_ind]) res_tot = { 'code' : accounts[bcl_rup_ind]['code'], @@ -202,21 +201,21 @@ class tax_report(rml_parse.rml_parse): 'level' : 0, 'pos' : 0 } - + if res_tot['type'] == 1: # on change le type pour afficher le total res_tot['type'] = 2 result_accounts.append(res_tot) bcl_current_level = accounts[bcl_rup_ind]['level'] bcl_rup_ind -= 1 - + old_level = account_elem['level'] result_accounts.append(account_elem) ind+=1 - - + + return result_accounts - + report_sxw.report_sxw('report.account.vat.declaration', 'account.tax.code', 'addons/account/report/tax_report.rml', parser=tax_report, header=False) diff --git a/addons/account/report/third_party_ledger.py b/addons/account/report/third_party_ledger.py index 5c38819ba83..f17a91b1bed 100644 --- a/addons/account/report/third_party_ledger.py +++ b/addons/account/report/third_party_ledger.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 . # ############################################################################## @@ -142,7 +142,8 @@ class third_party_ledger(rml_parse.rml_parse): if (data['model'] == 'res.partner'): ## Si on imprime depuis les partenaires if ids: - PARTNER_REQUEST = "AND line.partner_id IN (" + ','.join(map(str, ids)) + ")" + #PARTNER_REQUEST = "AND line.partner_id IN (" + ','.join(map(str, ids)) + ")" + PARTNER_REQUEST = "AND line.partner_id =ANY(%s)" %ids # Transformation des date # # @@ -166,11 +167,11 @@ class third_party_ledger(rml_parse.rml_parse): # #new_ids = [id for (id,) in self.cr.fetchall()] if data['form']['result_selection'] == 'supplier': - self.ACCOUNT_TYPE = "('receivable')" + self.ACCOUNT_TYPE = ['receivable'] elif data['form']['result_selection'] == 'customer': - self.ACCOUNT_TYPE = "('payable')" + self.ACCOUNT_TYPE = ['payable'] elif data['form']['result_selection'] == 'all': - self.ACCOUNT_TYPE = "('payable','receivable')" + self.ACCOUNT_TYPE = ['payable','receivable'] self.cr.execute( "SELECT a.id " \ @@ -178,9 +179,9 @@ class third_party_ledger(rml_parse.rml_parse): "LEFT JOIN account_account_type t " \ "ON (a.type=t.code) " \ "WHERE a.company_id = %s " \ - 'AND a.type IN ' + self.ACCOUNT_TYPE + " " \ - "AND a.active", (data['form']['company_id'],)) - self.account_ids = ','.join([str(a) for (a,) in self.cr.fetchall()]) + 'AND a.type =ANY(%s)' \ + "AND a.active", (data['form']['company_id'],self.ACCOUNT_TYPE,)) + self.account_ids = [a for (a,) in self.cr.fetchall()] account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line') partner_to_use = [] @@ -195,11 +196,11 @@ class third_party_ledger(rml_parse.rml_parse): "AND line.date >= %s " \ "AND line.date <= %s " \ "AND line.reconcile_id IS NULL " \ - "AND line.account_id IN (" + self.account_ids + ") " \ + "AND line.account_id =ANY(%s)" \ " " + PARTNER_REQUEST + " " \ "AND account.company_id = %s " \ "AND account.active " , - (self.date_lst[0],self.date_lst[len(self.date_lst)-1],data['form']['company_id'])) + (self.date_lst[0],self.date_lst[len(self.date_lst)-1],self.account_ids,data['form']['company_id'],)) # else: # # self.cr.execute( @@ -220,7 +221,8 @@ class third_party_ledger(rml_parse.rml_parse): partner_to_use.append(res_line['partner_id']) new_ids = partner_to_use - self.partner_ids = ','.join(map(str, new_ids)) + #self.partner_ids = ','.join(map(str, new_ids)) + self.partner_ids = new_ids objects = self.pool.get('res.partner').browse(self.cr, self.uid, new_ids) super(third_party_ledger, self).set_context(objects, data, new_ids, report_type) @@ -259,11 +261,11 @@ class third_party_ledger(rml_parse.rml_parse): "LEFT JOIN account_journal j " \ "ON (l.journal_id = j.id) " \ "WHERE l.partner_id = %s " \ - "AND l.account_id IN (" + self.account_ids + ") " \ - "AND l.date IN (" + self.date_lst_string + ") " \ + "AND l.account_id =ANY(%s)"\ + "AND l.date IN (" + self.date_lst_string + ")" " " + RECONCILE_TAG + " "\ "ORDER BY l.id", - (partner.id,)) + (partner.id,self.account_ids,)) res = self.cr.dictfetchall() sum = 0.0 for r in res: @@ -286,10 +288,10 @@ class third_party_ledger(rml_parse.rml_parse): "SELECT sum(debit) " \ "FROM account_move_line " \ "WHERE partner_id = %s " \ - "AND account_id IN (" + self.account_ids + ") " \ + "AND account_id =ANY(%s)" \ "AND reconcile_id IS NULL " \ "AND date < %s " , - (partner.id, self.date_lst[0],)) + (partner.id, self.account_ids,self.date_lst[0],)) contemp = self.cr.fetchone() if contemp != None: result_tmp = contemp[0] or 0.0 @@ -301,10 +303,10 @@ class third_party_ledger(rml_parse.rml_parse): "SELECT sum(debit) " \ "FROM account_move_line " \ "WHERE partner_id = %s " \ - "AND account_id IN (" + self.account_ids + ") " \ + "AND account_id =ANY(%s)" \ " " + RECONCILE_TAG + " " \ - "AND date IN (" + self.date_lst_string + ") " , - (partner.id,)) + "AND date IN (" + self.date_lst_string + ")" , + (partner.id,self.account_ids,)) contemp = self.cr.fetchone() if contemp != None: @@ -325,10 +327,10 @@ class third_party_ledger(rml_parse.rml_parse): "SELECT sum(credit) " \ "FROM account_move_line " \ "WHERE partner_id=%s " \ - "AND account_id IN (" + self.account_ids + ") " \ + "AND account_id =ANY(%s)" \ "AND reconcile_id IS NULL " \ "AND date < %s " , - (partner.id,self.date_lst[0],)) + (partner.id,self.account_ids,self.date_lst[0],)) contemp = self.cr.fetchone() if contemp != None: result_tmp = contemp[0] or 0.0 @@ -340,10 +342,10 @@ class third_party_ledger(rml_parse.rml_parse): "SELECT sum(credit) " \ "FROM account_move_line " \ "WHERE partner_id=%s " \ - "AND account_id IN (" + self.account_ids + ") " \ + "AND account_id =ANY(%s)" \ " " + RECONCILE_TAG + " " \ - "AND date IN (" + self.date_lst_string + ") " , - (partner.id,)) + "AND date IN (" + self.date_lst_string + ")", + (partner.id,self.account_ids,)) contemp = self.cr.fetchone() if contemp != None: @@ -365,11 +367,11 @@ class third_party_ledger(rml_parse.rml_parse): self.cr.execute( "SELECT sum(debit) " \ "FROM account_move_line " \ - "WHERE partner_id IN (" + self.partner_ids + ") " \ - "AND account_id IN (" + self.account_ids + ") " \ + "WHERE partner_id =ANY(%s)" \ + "AND account_id =ANY(%s)" \ "AND reconcile_id IS NULL " \ "AND date < %s " , - (self.date_lst[0],)) + (self.partner_ids,self.account_ids,self.date_lst[0],)) contemp = self.cr.fetchone() if contemp != None: result_tmp = contemp[0] or 0.0 @@ -380,12 +382,10 @@ class third_party_ledger(rml_parse.rml_parse): self.cr.execute( "SELECT sum(debit) " \ "FROM account_move_line " \ - "WHERE partner_id IN (" + self.partner_ids + ") " \ - "AND account_id IN (" + self.account_ids + ") " \ + "WHERE partner_id =ANY(%s)" \ + "AND account_id =ANY(%s)" \ " " + RECONCILE_TAG + " " \ - "AND date IN (" + self.date_lst_string + ") " - ) - + "AND date IN (" + self.date_lst_string + ")",(self.partner_ids,self.account_ids,)) contemp = self.cr.fetchone() if contemp != None: result_tmp = contemp[0] or 0.0 @@ -408,11 +408,11 @@ class third_party_ledger(rml_parse.rml_parse): self.cr.execute( "SELECT sum(credit) " \ "FROM account_move_line " \ - "WHERE partner_id IN (" + self.partner_ids + ") " \ - "AND account_id IN (" + self.account_ids + ") " \ + "WHERE partner_id =ANY(%s)" \ + "AND account_id =ANY(%s)" \ "AND reconcile_id IS NULL " \ "AND date < %s " , - (self.date_lst[0],)) + (self.partner_ids,self.account_ids,self.date_lst[0],)) contemp = self.cr.fetchone() if contemp != None: result_tmp = contemp[0] or 0.0 @@ -423,11 +423,10 @@ class third_party_ledger(rml_parse.rml_parse): self.cr.execute( "SELECT sum(credit) " \ "FROM account_move_line " \ - "WHERE partner_id IN (" + self.partner_ids + ") " \ - "AND account_id IN (" + self.account_ids + ") " \ + "WHERE partner_id =ANY(%s)" \ + "AND account_id =ANY(%s)" \ " " + RECONCILE_TAG + " " \ - "AND date IN (" + self.date_lst_string + ") " - ) + "AND date IN (" + self.date_lst_string + ")",(self.partner_ids,self.account_ids,)) contemp = self.cr.fetchone() if contemp != None: result_tmp = contemp[0] or 0.0 diff --git a/addons/account/wizard/wizard_account_balance_report.py b/addons/account/wizard/wizard_account_balance_report.py index e3fa44b7a97..af16b66439b 100644 --- a/addons/account/wizard/wizard_account_balance_report.py +++ b/addons/account/wizard/wizard_account_balance_report.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 . # ############################################################################## @@ -102,7 +102,7 @@ class wizard_report(wizard.interface): # else : # data['form']['fiscalyear'] = 1 return data['form'] - + def _check_path(self, cr, uid, data, context): if data['model'] == 'account.account': return 'checktype' @@ -111,8 +111,8 @@ class wizard_report(wizard.interface): def _check_date(self, cr, uid, data, context): sql = """ - SELECT f.id, f.date_start, f.date_stop FROM account_fiscalyear f Where '%s' between f.date_start and f.date_stop """%(data['form']['date_from']) - cr.execute(sql) + SELECT f.id, f.date_start, f.date_stop FROM account_fiscalyear f Where %s between f.date_start and f.date_stop """ + cr.execute(sql,(data['form']['date_from'],)) res = cr.dictfetchall() if res: if (data['form']['date_to'] > res[0]['date_stop'] or data['form']['date_to'] < res[0]['date_start']): diff --git a/addons/account/wizard/wizard_fiscalyear_close.py b/addons/account/wizard/wizard_fiscalyear_close.py index 27b69bb9d76..9ef04147c36 100644 --- a/addons/account/wizard/wizard_fiscalyear_close.py +++ b/addons/account/wizard/wizard_fiscalyear_close.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 . # ############################################################################## @@ -56,14 +56,12 @@ def _data_save(self, cr, uid, data, context): fy_id = data['form']['fy_id'] period_ids = pool.get('account.period').search(cr, uid, [('fiscalyear_id', '=', fy_id)]) - fy_period_set = ','.join(map(str, period_ids)) periods_fy2 = pool.get('account.period').search(cr, uid, [('fiscalyear_id', '=', data['form']['fy2_id'])]) - fy2_period_set = ','.join(map(str, periods_fy2)) period = pool.get('account.period').browse(cr, uid, data['form']['period_id'], context=context) new_fyear = pool.get('account.fiscalyear').browse(cr, uid, data['form']['fy2_id'], context=context) old_fyear = pool.get('account.fiscalyear').browse(cr, uid, data['form']['fy_id'], context=context) - + new_journal = data['form']['journal_id'] new_journal = pool.get('account.journal').browse(cr, uid, new_journal, context=context) @@ -87,7 +85,7 @@ def _data_save(self, cr, uid, data, context): ids = map(lambda x: x[0], cr.fetchall()) for account in pool.get('account.account').browse(cr, uid, ids, context={'fiscalyear': fy_id}): - + accnt_type_data = account.user_type if not accnt_type_data: continue @@ -133,7 +131,7 @@ def _data_save(self, cr, uid, data, context): }) offset += limit - #We have also to consider all move_lines that were reconciled + #We have also to consider all move_lines that were reconciled #on another fiscal year, and report them too offset = 0 limit = 100 @@ -147,10 +145,10 @@ def _data_save(self, cr, uid, data, context): 'WHERE b.account_id = %s ' \ 'AND b.reconcile_id is NOT NULL ' \ 'AND a.reconcile_id = b.reconcile_id ' \ - 'AND b.period_id IN ('+fy_period_set+') ' \ - 'AND a.period_id IN ('+fy2_period_set+') ' \ + 'AND b.period_id =ANY(%s)'\ + 'AND a.period_id =ANY(%s)' \ 'ORDER BY id ' \ - 'LIMIT %s OFFSET %s', (account.id, limit, offset)) + 'LIMIT %s OFFSET %s', (account.id,period_ids,periods_fy2,limit, offset)) result = cr.dictfetchall() if not result: break @@ -178,7 +176,7 @@ def _data_save(self, cr, uid, data, context): 'AND ' + query_line + ' ' \ 'ORDER BY id ' \ 'LIMIT %s OFFSET %s', (account.id, limit, offset)) - + result = cr.dictfetchall() if not result: break @@ -208,7 +206,6 @@ def _data_save(self, cr, uid, data, context): cr.execute('UPDATE account_fiscalyear ' \ 'SET end_journal_period_id = %s ' \ 'WHERE id = %s', (ids[0], old_fyear.id)) - return {} class wiz_journal_close(wizard.interface): diff --git a/addons/account/wizard/wizard_general_ledger_report.py b/addons/account/wizard/wizard_general_ledger_report.py index a1655037b0d..f123afbb047 100644 --- a/addons/account/wizard/wizard_general_ledger_report.py +++ b/addons/account/wizard/wizard_general_ledger_report.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 . # ############################################################################## @@ -46,7 +46,7 @@ period_form = ''' - + @@ -65,10 +65,10 @@ period_form = ''' - - - - + + + + ''' period_fields = { @@ -103,10 +103,10 @@ def _check(self, cr, uid, data, context): return 'report' def _check_date(self, cr, uid, data, context): - + sql = """ - SELECT f.id, f.date_start, f.date_stop FROM account_fiscalyear f Where '%s' between f.date_start and f.date_stop """%(data['form']['date_from']) - cr.execute(sql) + SELECT f.id, f.date_start, f.date_stop FROM account_fiscalyear f Where %s between f.date_start and f.date_stop """ + cr.execute(sql,(data['form']['date_from'],)) res = cr.dictfetchall() if res: if (data['form']['date_to'] > res[0]['date_stop'] or data['form']['date_to'] < res[0]['date_start']): @@ -116,14 +116,14 @@ def _check_date(self, cr, uid, data, context): else: raise wizard.except_wizard(_('UserError'),_('Date not in a defined fiscal year')) - + def _check_state(self, cr, uid, data, context): if data['form']['state'] == 'bydate': _check_date(self, cr, uid, data, context) # data['form']['fiscalyear'] = 0 # else : -# +# # data['form']['fiscalyear'] = 1 return data['form'] @@ -137,7 +137,7 @@ class wizard_report(wizard.interface): company_id = pooler.get_pool(cr.dbname).get('res.company').search(cr, uid, [('parent_id', '=', False)])[0] data['form']['company_id'] = company_id fiscalyear_obj = pooler.get_pool(cr.dbname).get('account.fiscalyear') - + data['form']['fiscalyear'] = fiscalyear_obj.find(cr, uid) #periods_obj=pooler.get_pool(cr.dbname).get('account.period') #data['form']['periods'] =periods_obj.search(cr, uid, [('fiscalyear_id','=',data['form']['fiscalyear'])]) diff --git a/addons/account/wizard/wizard_open_closed_fiscalyear.py b/addons/account/wizard/wizard_open_closed_fiscalyear.py index 91201d9f85e..7b9c3f8e88b 100644 --- a/addons/account/wizard/wizard_open_closed_fiscalyear.py +++ b/addons/account/wizard/wizard_open_closed_fiscalyear.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 . # ############################################################################## @@ -43,7 +43,7 @@ def _remove_entries(self, cr, uid, data, context): period_journal = data_fyear.end_journal_period_id ids_move = pool.get('account.move').search(cr,uid,[('journal_id','=',period_journal.journal_id.id),('period_id','=',period_journal.period_id.id)]) if ids_move: - cr.execute('delete from account_move where id in ('+','.join(map(str, ids_move))+')') + cr.execute('delete from account_move where id =ANY(%s)',(ids_move,)) #cr.execute('UPDATE account_journal_period ' \ # 'SET state = %s ' \ # 'WHERE period_id IN (SELECT id FROM account_period WHERE fiscalyear_id = %s)', @@ -60,17 +60,17 @@ class open_closed_fiscal(wizard.interface): 'init' : { 'actions' : [], 'result': { - 'type': 'form', + 'type': 'form', 'arch': form, - 'fields': fields, + 'fields': fields, 'state':[('end','Cancel'),('open','Open')] } }, 'open': { 'actions': [], 'result': { - 'type':'action', - 'action':_remove_entries, + 'type':'action', + 'action':_remove_entries, 'state':'end' }, }, diff --git a/addons/account/wizard/wizard_partner_balance_report.py b/addons/account/wizard/wizard_partner_balance_report.py index 54300e582d4..307a4eafcc3 100644 --- a/addons/account/wizard/wizard_partner_balance_report.py +++ b/addons/account/wizard/wizard_partner_balance_report.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 . # ############################################################################## @@ -74,14 +74,14 @@ period_fields = { } class wizard_report(wizard.interface): - + def _get_defaults(self,cr,uid,data,context): user = pooler.get_pool(cr.dbname).get('res.users').browse(cr, uid, uid, context=context) if user.company_id: company_id = user.company_id.id else: company_id = pooler.get_pool(cr.dbname).get('res.company').search(cr, uid, [('parent_id', '=', False)])[0] - + fiscalyear_obj = pooler.get_pool(cr.dbname).get('account.fiscalyear') periods_obj=pooler.get_pool(cr.dbname).get('account.period') data['form']['fiscalyear'] = fiscalyear_obj.find(cr, uid) @@ -91,25 +91,24 @@ class wizard_report(wizard.interface): data['form']['fiscalyear'] = False data['form']['result_selection'] = 'all' return data['form'] - + def _check_state(self, cr, uid, data, context): - + if data['form']['state'] == 'bydate' : self._check_date(cr, uid, data, context) return data['form'] - + def _check_date(self, cr, uid, data, context): - sql = """ - SELECT f.id, f.date_start, f.date_stop FROM account_fiscalyear f Where '%s' between f.date_start and f.date_stop """%(data['form']['date1']) - cr.execute(sql) + SELECT f.id, f.date_start, f.date_stop FROM account_fiscalyear f Where %s between f.date_start and f.date_stop """ + cr.execute(sql,(data['form']['date1'],)) res = cr.dictfetchall() if res: if (data['form']['date2'] > res[0]['date_stop'] or data['form']['date2'] < res[0]['date_start']): raise wizard.except_wizard(_('UserError'),_('Date to must be set between %s and %s') % (str(res[0]['date_start']), str(res[0]['date_stop']))) else: return 'report' - + else: raise wizard.except_wizard(_('UserError'),_('Date not in a defined fiscal year')) @@ -118,7 +117,7 @@ class wizard_report(wizard.interface): 'actions': [_get_defaults], 'result': {'type':'form', 'arch':period_form, 'fields':period_fields, 'state':[('end','Cancel','gtk-cancel'),('report','Print','gtk-print')]} }, - + 'report': { 'actions': [_check_state], 'result': {'type':'print', 'report':'account.partner.balance', 'state':'end'} diff --git a/addons/account/wizard/wizard_refund.py b/addons/account/wizard/wizard_refund.py index a92b38c67f3..3ac0b86809d 100644 --- a/addons/account/wizard/wizard_refund.py +++ b/addons/account/wizard/wizard_refund.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 . # ############################################################################## @@ -80,17 +80,14 @@ class wiz_refund(wizard.interface): #in multi company mode cr.execute("""SELECT id from account_period where date('%s') - between date_start AND date_stop and company_id = %s limit 1 """%( - form['date'], - pool.get('res.users').browse(cr,uid,uid).company_id.id - )) + between date_start AND date_stop and company_id = %s limit 1 """, + (form['date'],pool.get('res.users').browse(cr,uid,uid).company_id.id,)) else: #in mono company mode cr.execute("""SELECT id from account_period where date('%s') - between date_start AND date_stop limit 1 """%( - form['date'], - )) + between date_start AND date_stop limit 1 """, + (form['date'],)) res = cr.fetchone() if res: period = res[0] @@ -101,10 +98,10 @@ class wiz_refund(wizard.interface): description = form['description'] else: description = inv.name - + if not period: raise wizard.except_wizard(_('Data Insufficient !'), _('No Period found on Invoice!')) - + refund_id = pool.get('account.invoice').refund(cr, uid, [inv.id],date, period, description) refund = pool.get('account.invoice').browse(cr, uid, refund_id[0]) # we compute due date @@ -112,7 +109,7 @@ class wiz_refund(wizard.interface): pool.get('account.invoice').write(cr, uid, [refund.id],{'date_due':date,'check_total':inv.check_total}) # to make the taxes calculated pool.get('account.invoice').button_compute(cr, uid, refund_id) - + created_inv.append(refund_id[0]) #if inv is paid we unreconcile if mode in ('cancel','modify'): diff --git a/addons/account/wizard/wizard_third_party_ledger.py b/addons/account/wizard/wizard_third_party_ledger.py index a5581b8dd77..938fb39b429 100755 --- a/addons/account/wizard/wizard_third_party_ledger.py +++ b/addons/account/wizard/wizard_third_party_ledger.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 . # ############################################################################## @@ -113,8 +113,8 @@ class wizard_report(wizard.interface): def _check_date(self, cr, uid, data, context): sql = """ - SELECT f.id, f.date_start, f.date_stop FROM account_fiscalyear f Where '%s' between f.date_start and f.date_stop """%(data['form']['date1']) - cr.execute(sql) + SELECT f.id, f.date_start, f.date_stop FROM account_fiscalyear f Where %s between f.date_start and f.date_stop """ + cr.execute(sql,(data['form']['date1'])) res = cr.dictfetchall() if res: if (data['form']['date2'] > res[0]['date_stop'] or data['form']['date2'] < res[0]['date_start']): From f99cf9a615d8a4ebb2857440acecd4fac0ab9543 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Sun, 31 Jan 2010 16:55:08 +0100 Subject: [PATCH 42/53] [fix] very badly broken HttpSDaemon bzr revid: xmo@tinyerp.com-20100131155508-3uh7b9ahkwrsusat --- bin/service/http_server.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/service/http_server.py b/bin/service/http_server.py index 9cbb49571dc..a35701dc9e5 100644 --- a/bin/service/http_server.py +++ b/bin/service/http_server.py @@ -161,11 +161,11 @@ class HttpDaemon(BaseHttpDaemon): super(HttpDaemon, self).__init__(interface, port, handler=MultiHandler2) -class HttpSDaemon(threading.Thread, netsvc.Server): +class HttpSDaemon(BaseHttpDaemon): def __init__(self, interface, port): try: - super(HttpDaemon, self).__init__(interface, port, - handler=SecureMultiHandler2) + super(HttpSDaemon, self).__init__(interface, port, + handler=SecureMultiHandler2) except SSLError, e: netsvc.Logger().notifyChannel( 'httpd-ssl', netsvc.LOG_CRITICAL, From aa429328a2413a75fa801eb6bfe05eb6a0c2e9c1 Mon Sep 17 00:00:00 2001 From: Launchpad Code Hosting Date: Mon, 1 Feb 2010 04:45:36 +0000 Subject: [PATCH 43/53] Launchpad automatic translations update. bzr revid: codehost@crowberry-20100201044536-6q6020kbnmm70l03 --- addons/base_contact/i18n/lv.po | 8 ++++---- addons/report_analytic/i18n/it.po | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/addons/base_contact/i18n/lv.po b/addons/base_contact/i18n/lv.po index 9afb9c5b56d..584612133cc 100644 --- a/addons/base_contact/i18n/lv.po +++ b/addons/base_contact/i18n/lv.po @@ -8,13 +8,13 @@ msgstr "" "Project-Id-Version: openobject-addons\n" "Report-Msgid-Bugs-To: FULL NAME \n" "POT-Creation-Date: 2009-08-28 16:01+0000\n" -"PO-Revision-Date: 2009-10-08 08:06+0000\n" -"Last-Translator: Fabien (Open ERP) \n" +"PO-Revision-Date: 2010-01-31 20:05+0000\n" +"Last-Translator: Rinalds \n" "Language-Team: Latvian \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"X-Launchpad-Export-Date: 2009-12-16 05:08+0000\n" +"X-Launchpad-Export-Date: 2010-02-01 04:45+0000\n" "X-Generator: Launchpad (build Unknown)\n" #. module: base_contact @@ -195,7 +195,7 @@ msgstr "Kategorijas" #. module: base_contact #: field:res.partner.contact,function_id:0 msgid "Main Function" -msgstr "" +msgstr "Pamatfunkcija" #. module: base_contact #: model:process.transition,note:base_contact.process_transition_partnertoaddress0 diff --git a/addons/report_analytic/i18n/it.po b/addons/report_analytic/i18n/it.po index 9806151e130..280eb6186a6 100644 --- a/addons/report_analytic/i18n/it.po +++ b/addons/report_analytic/i18n/it.po @@ -7,13 +7,13 @@ msgstr "" "Project-Id-Version: OpenERP Server 5.0.0\n" "Report-Msgid-Bugs-To: support@openerp.com\n" "POT-Creation-Date: 2009-08-28 16:01+0000\n" -"PO-Revision-Date: 2009-09-08 16:12+0000\n" -"Last-Translator: Marius Marolla \n" +"PO-Revision-Date: 2010-01-31 08:53+0000\n" +"Last-Translator: Daniel Eric Maier \n" "Language-Team: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"X-Launchpad-Export-Date: 2009-12-16 05:06+0000\n" +"X-Launchpad-Export-Date: 2010-02-01 04:45+0000\n" "X-Generator: Launchpad (build Unknown)\n" #. module: report_analytic @@ -62,7 +62,7 @@ msgstr "Nome di modulo non valido nella definizione dell'azione." #. module: report_analytic #: model:ir.module.module,shortdesc:report_analytic.module_meta_information msgid "Analytic Account Reporting" -msgstr "" +msgstr "Relatório de Conta Analítica" #. module: report_analytic #: field:report.analytic.account.close,partner_id:0 From 8d466990b0de0e5d5f1c220934883cf41df0c842 Mon Sep 17 00:00:00 2001 From: "nch@tinyerp.com" <> Date: Mon, 1 Feb 2010 10:23:06 +0530 Subject: [PATCH 44/53] [FIX]:removed bad commit bzr revid: nch@tinyerp.com-20100201045306-7cr1d6m2jkdjewgh --- addons/product/product.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/product/product.py b/addons/product/product.py index b2e70cab81d..08729a44d7d 100644 --- a/addons/product/product.py +++ b/addons/product/product.py @@ -245,7 +245,7 @@ class product_template(osv.osv): 'description': fields.text('Description',translate=True), 'description_purchase': fields.text('Purchase Description',translate=True), 'description_sale': fields.text('Sale Description',translate=True), - 'type': fields.selection([('product','Stockable Product'),('rima','Rima'),('consu', 'Consumable'),('service','Service')], 'Product Type', required=True, help="Will change the way requisitions are processed. Consumables are stockable products with infinite stock, or for use when you have no inventory management in the system."), + 'type': fields.selection([('product','Stockable Product'),('consu', 'Consumable'),('service','Service')], 'Product Type', required=True, help="Will change the way requisitions are processed. Consumables are stockable products with infinite stock, or for use when you have no inventory management in the system."), 'supply_method': fields.selection([('produce','Produce'),('buy','Buy')], 'Supply method', required=True, help="Produce will generate production order or tasks, according to the product type. Purchase will trigger purchase orders when requested."), 'sale_delay': fields.float('Customer Lead Time', help="This is the average time between the confirmation of the customer order and the delivery of the finished products. It's the time you promise to your customers."), 'produce_delay': fields.float('Manufacturing Lead Time', help="Average time to produce this product. This is only for the production order and, if it is a multi-level bill of material, it's only for the level of this product. Different lead times will be summed for all levels and purchase orders."), From da5c8f95840f8ac57584b55edfa727ae4e4bef1a Mon Sep 17 00:00:00 2001 From: "Harry (Open ERP)" Date: Mon, 1 Feb 2010 11:32:19 +0530 Subject: [PATCH 45/53] [FIX] caldav: call super method twise in virtual report pool bzr revid: hmo@tinyerp.com-20100201060219-a6jrqx05uqhj4udx --- addons/caldav/caldav.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/addons/caldav/caldav.py b/addons/caldav/caldav.py index 2d988456da2..5741f645b1e 100644 --- a/addons/caldav/caldav.py +++ b/addons/caldav/caldav.py @@ -864,8 +864,7 @@ class virtual_report_spool(web_services.report_spool): new_ids = [] for id in ids: new_ids.append(caldav_id2real_id(id)) - datas['id'] = caldav_id2real_id(datas['id']) - super(virtual_report_spool, self).exp_report(db, uid, object, new_ids, datas, context) + datas['id'] = caldav_id2real_id(datas['id']) return super(virtual_report_spool, self).exp_report(db, uid, object, new_ids, datas, context) virtual_report_spool() From a31a105e3329f55c28a5d289f152091a1bf1cc31 Mon Sep 17 00:00:00 2001 From: Fabien Pinckaers Date: Mon, 1 Feb 2010 09:21:18 +0100 Subject: [PATCH 46/53] [IMP] removing contextial access rights (setting as default values for searches) bzr revid: fp@tinyerp.com-20100201082118-fql37t0rbk3sbhtu --- addons/crm/crm.py | 3 +- addons/crm/crm_view.xml | 160 +++++++++--------- addons/crm/security/crm_security.xml | 89 ---------- addons/crm_hr/security/crm_hr_security.xml | 11 -- addons/hr/hr_department.py | 4 +- addons/sale_crm/sale_crm.py | 9 +- .../sale_crm/security/sale_crm_security.xml | 20 --- 7 files changed, 86 insertions(+), 210 deletions(-) diff --git a/addons/crm/crm.py b/addons/crm/crm.py index f1b4eab309b..c84c96e3abc 100644 --- a/addons/crm/crm.py +++ b/addons/crm/crm.py @@ -908,8 +908,7 @@ class users(osv.osv): _description = "Users" _columns = { 'context_section_id': fields.selection(_section_get, 'Sales Section'), - } - + } users() diff --git a/addons/crm/crm_view.xml b/addons/crm/crm_view.xml index 02a2984a0a2..2c8dc9209a9 100644 --- a/addons/crm/crm_view.xml +++ b/addons/crm/crm_view.xml @@ -48,41 +48,41 @@ - # ------------------------------------------------------ - # Stage - # ------------------------------------------------------ - - crm.case.stage.tree - crm.case.stage - tree - - - - - - - - - - crm.case.stage.form - crm.case.stage - form - -
- - - - - - -
- - Stages - crm.case.stage - form - - - + # ------------------------------------------------------ + # Stage + # ------------------------------------------------------ + + crm.case.stage.tree + crm.case.stage + tree + + + + + + + + + + crm.case.stage.form + crm.case.stage + form + +
+ + + + + + +
+ + Stages + crm.case.stage + form + + + crm.case.categ.form @@ -92,7 +92,7 @@
- + @@ -116,7 +116,7 @@ form
- + @@ -185,8 +185,8 @@ + + --> @@ -243,11 +243,11 @@ + attrs="{ 'required' : [('name','=','user')]}" + on_change="change_email(user_id, partner_id)"/> + attrs="{'required' : [('name','=','partner')]}" + on_change="change_email(user_id, partner_id)"/>