Merge lp:~xmo-deactivatedaccount/openobject-addons/5.0-sql-fixes into lp:openobject-addons/5.0

Proposed by Xavier (Open ERP)
Status: Merged
Merged at revision: 2746
Proposed branch: lp:~xmo-deactivatedaccount/openobject-addons/5.0-sql-fixes
Merge into: lp:openobject-addons/5.0
Diff against target: 4074 lines (+1024/-1065) (has conflicts)
70 files modified
.bzrignore (+1/-0)
account/account.py (+109/-57)
account/account_move_line.py (+9/-7)
account/invoice.py (+15/-9)
account/partner.py (+41/-32)
account/project/project.py (+84/-62)
account/project/report/analytic_balance.py (+17/-105)
account/project/report/analytic_check.py (+0/-37)
account/project/report/cost_ledger.py (+8/-4)
account/project/report/inverted_analytic_balance.py (+26/-10)
account/project/report/quantity_cost_ledger.py (+12/-17)
account/report/account_balance.py (+1/-25)
account/report/aged_trial_balance.py (+199/-193)
account/report/general_journal.py (+50/-27)
account/report/general_ledger.py (+28/-13)
account/report/general_ledger_landscape.py (+19/-14)
account/report/partner_balance.py (+30/-31)
account/report/tax_report.py (+7/-7)
account/wizard/wizard_account_balance_report.py (+2/-2)
account/wizard/wizard_general_ledger_report.py (+2/-2)
account/wizard/wizard_open_closed_fiscalyear.py (+1/-10)
account/wizard/wizard_partner_balance_report.py (+2/-2)
account/wizard/wizard_third_party_ledger.py (+2/-2)
account_analytic_plans/report/crossovered_analytic.py (+40/-14)
account_payment/account_move_line.py (+7/-5)
account_payment/payment.py (+2/-93)
account_voucher/account.py (+5/-3)
account_voucher/voucher.py (+2/-1)
auction/auction.py (+16/-5)
auction/report/auction_objects.py (+0/-13)
auction/report/auction_total_rml.py (+4/-1)
auction/report/buyer_list.py (+10/-6)
base_module_quality/speed_test/speed_test.py (+3/-1)
crm/crm.py (+3/-1)
crm/report/report_businessopp.py (+7/-1)
crm_profiling/crm_profiling.py (+20/-18)
document/document.py (+4/-2)
event/event.py (+4/-4)
event_project/event.py (+2/-2)
hr/hr.py (+4/-2)
hr/hr_department.py (+3/-2)
hr_attendance/hr_attendance.py (+3/-3)
hr_attendance/wizard/print_attendance_error.py (+6/-3)
hr_expense/hr_expense.py (+12/-8)
hr_holidays/hr.py (+1/-1)
hr_timesheet_invoice/wizard/hr_timesheet_invoice_create.py (+12/-10)
hr_timesheet_sheet/hr_timesheet_sheet.py (+7/-7)
idea/idea.py (+14/-14)
l10n_be/wizard/wizard_vat_intra.py (+16/-23)
membership/membership.py (+3/-3)
membership/wizard/invoice_membership.py (+2/-3)
mrp/mrp.py (+1/-1)
mrp/report/workcenter_load.py (+3/-4)
point_of_sale/pos.py (+3/-4)
product/pricelist.py (+7/-11)
product/product.py (+1/-1)
product_margin/product_margin.py (+39/-40)
project/project.py (+5/-5)
purchase/purchase.py (+3/-2)
report_account/report_receivable.py (+3/-3)
report_analytic_planning/report_analytic_planning.py (+8/-6)
report_crm/report_crm.py (+14/-15)
report_timesheet/report_timesheet.py (+2/-2)
sale/sale.py (+3/-3)
scrum/report/_burndown.py (+4/-7)
scrum/report/task_burndown.py (+4/-4)
stock/product.py (+22/-16)
stock/stock.py (+20/-18)
stock/wizard/inventory_merge_zero.py (+2/-2)
wiki/wizard/make_index.py (+3/-4)
Text conflict in account/account.py
To merge this branch: bzr merge lp:~xmo-deactivatedaccount/openobject-addons/5.0-sql-fixes
Reviewer Review Type Date Requested Status
Christophe Simonis (OpenERP) Needs Fixing
Olivier Dony (Odoo) Pending
Stephane Wirtel (OpenERP) Pending
Review via email: mp+20726@code.launchpad.net

Description of the change

Fixes sql moche, potentiellement injectable.

To post a comment you must log in.
Revision history for this message
Christophe Simonis (OpenERP) (kangol) wrote :

In order to be consistent with the rest of stable branch, can you please use netsvc.notifyChannel instead of logging?

(For trunk it is ok)

review: Needs Fixing
Revision history for this message
Xavier (Open ERP) (xmo-deactivatedaccount) wrote :

Done, logging.getLogger calls were moved back to netsvc.Logger.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file '.bzrignore'
2--- .bzrignore 1970-01-01 00:00:00 +0000
3+++ .bzrignore 2010-03-17 11:50:49 +0000
4@@ -0,0 +1,1 @@
5+./.ropeproject
6
7=== modified file 'account/account.py'
8--- account/account.py 2010-03-16 09:19:35 +0000
9+++ account/account.py 2010-03-17 11:50:49 +0000
10@@ -20,8 +20,10 @@
11 #
12 ##############################################################################
13 import time
14+
15+from operator import itemgetter
16+
17 import netsvc
18-
19 from osv import fields, osv
20
21 from tools.misc import currency
22@@ -32,6 +34,26 @@
23
24 from tools import config
25
26+def check_cycle(self, cr, uid, ids):
27+ """ climbs the ``self._table.parent_id`` chains for 100 levels or
28+ until it can't find any more parent(s)
29+
30+ Returns true if it runs out of parents (no cycle), false if
31+ it can recurse 100 times without ending all chains
32+ """
33+ level = 100
34+ while len(ids):
35+ cr.execute('SELECT DISTINCT parent_id '\
36+ 'FROM '+self._table+' '\
37+ 'WHERE id IN %s '\
38+ 'AND parent_id IS NOT NULL',
39+ (tuple(ids),))
40+ ids = map(itemgetter(0), cr.fetchall())
41+ if not level:
42+ return False
43+ level -= 1
44+ return True
45+
46 class account_payment_term(osv.osv):
47 _name = "account.payment.term"
48 _description = "Payment Term"
49@@ -149,6 +171,7 @@
50 _name = "account.account"
51 _description = "Account"
52 _parent_store = True
53+ logger = netsvc.Logger()
54
55 def search(self, cr, uid, args, offset=0, limit=None, order=None,
56 context=None, count=False):
57@@ -195,19 +218,33 @@
58 ids3 = self._get_children_and_consol(cr, uid, ids3, context)
59 return ids2 + ids3
60
61- def __compute(self, cr, uid, ids, field_names, arg, context={}, query=''):
62- #compute the balance/debit/credit accordingly to the value of field_name for the given account ids
63+ def __compute(self, cr, uid, ids, field_names, arg=None, context=None,
64+ query='', query_params=()):
65+ """ compute the balance, debit and/or credit for the provided
66+ account ids
67+
68+ Arguments:
69+ `ids`: account ids
70+ `field_names`: the fields to compute (a list of any of
71+ 'balance', 'debit' and 'credit')
72+ `arg`: unused fields.function stuff
73+ `query`: additional query filter (as a string)
74+ `query_params`: parameters for the provided query string
75+ (__compute will handle their escaping) as a
76+ tuple
77+ """
78 mapping = {
79- 'balance': "COALESCE(SUM(l.debit),0) - COALESCE(SUM(l.credit), 0) as balance ",
80- 'debit': "COALESCE(SUM(l.debit), 0) as debit ",
81- 'credit': "COALESCE(SUM(l.credit), 0) as credit "
82+ 'balance': "COALESCE(SUM(l.debit),0) " \
83+ "- COALESCE(SUM(l.credit), 0) as balance",
84+ 'debit': "COALESCE(SUM(l.debit), 0) as debit",
85+ 'credit': "COALESCE(SUM(l.credit), 0) as credit"
86 }
87 #get all the necessary accounts
88- ids2 = self._get_children_and_consol(cr, uid, ids, context)
89- acc_set = ",".join(map(str, ids2))
90+ children_and_consolidated = self._get_children_and_consol(
91+ cr, uid, ids, context=context)
92 #compute for each account the balance/debit/credit from the move lines
93 accounts = {}
94- if ids2:
95+ if children_and_consolidated:
96 aml_query = self.pool.get('account.move.line')._query_get(cr, uid, context=context)
97
98 wheres = [""]
99@@ -215,23 +252,33 @@
100 wheres.append(query.strip())
101 if aml_query:
102 wheres.append(aml_query.strip())
103- query = " AND ".join(wheres)
104-
105- cr.execute(("SELECT l.account_id as id, " +\
106- ' , '.join(map(lambda x: mapping[x], field_names)) +
107- "FROM " \
108- "account_move_line l " \
109- "WHERE " \
110- "l.account_id IN (%s) " \
111- + query +
112- " GROUP BY l.account_id") % (acc_set, ))
113+ filters = " AND ".join(wheres)
114+ self.logger.notifyChannel('addons.'+self._name, netsvc.LOG_DEBUG,
115+ 'Filters: %s'%filters)
116+ # IN might not work ideally in case there are too many
117+ # children_and_consolidated, in that case join on a
118+ # values() e.g.:
119+ # SELECT l.account_id as id FROM account_move_line l
120+ # INNER JOIN (VALUES (id1), (id2), (id3), ...) AS tmp (id)
121+ # ON l.account_id = tmp.id
122+ # or make _get_children_and_consol return a query and join on that
123+ request = ("SELECT l.account_id as id, " +\
124+ ' , '.join(map(mapping.__getitem__, field_names)) +
125+ " FROM account_move_line l" \
126+ " WHERE l.account_id IN %s " \
127+ + filters +
128+ " GROUP BY l.account_id")
129+ params = (tuple(children_and_consolidated),) + query_params
130+ cr.execute(request, params)
131+ self.logger.notifyChannel('addons.'+self._name, netsvc.LOG_DEBUG,
132+ 'Status: %s'%cr.statusmessage)
133
134 for res in cr.dictfetchall():
135 accounts[res['id']] = res
136
137-
138 # consolidate accounts with direct children
139- brs = list(self.browse(cr, uid, ids2, context=context))
140+ brs = list(self.browse(cr, uid, children_and_consolidated,
141+ context=context))
142 sums = {}
143 while brs:
144 current = brs[0]
145@@ -341,8 +388,10 @@
146 if (obj_self in obj_self.child_consol_ids) or (p_id and (p_id is obj_self.id)):
147 return False
148 while(ids):
149- cr.execute('select distinct child_id from account_account_consol_rel where parent_id in ('+','.join(map(str, ids))+')')
150- child_ids = filter(None, map(lambda x: x[0], cr.fetchall()))
151+ cr.execute('SELECT DISTINCT child_id '\
152+ 'FROM account_account_consol_rel '\
153+ 'WHERE parent_id IN %s', (tuple(ids),))
154+ child_ids = map(itemgetter(0), cr.fetchall())
155 c_ids = child_ids
156 if (p_id and (p_id in c_ids)) or (obj_self.id in c_ids):
157 return False
158@@ -767,7 +816,10 @@
159
160 def _amount_compute(self, cr, uid, ids, name, args, context, where =''):
161 if not ids: return {}
162- cr.execute('select move_id,sum(debit) from account_move_line where move_id in ('+','.join(map(str,ids))+') group by move_id')
163+ cr.execute('SELECT move_id, SUM(debit) '\
164+ 'FROM account_move_line '\
165+ 'WHERE move_id IN %s '\
166+ 'GROUP BY move_id', (tuple(ids),))
167 result = dict(cr.fetchall())
168 for id in ids:
169 result.setdefault(id, 0.0)
170@@ -862,7 +914,10 @@
171 if new_name:
172 self.write(cr, uid, [move.id], {'name':new_name})
173
174- cr.execute('update account_move set state=%s where id in ('+','.join(map(str,ids))+')', ('posted',))
175+ cr.execute('UPDATE account_move '\
176+ 'SET state=%s '\
177+ 'WHERE id IN %s',
178+ ('posted', tuple(ids)))
179 else:
180 raise osv.except_osv(_('Integrity Error !'), _('You can not validate a non-balanced entry !'))
181 return True
182@@ -875,7 +930,9 @@
183 if not line.journal_id.update_posted:
184 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.'))
185 if len(ids):
186- cr.execute('update account_move set state=%s where id in ('+','.join(map(str,ids))+')', ('draft',))
187+ cr.execute('UPDATE account_move '\
188+ 'SET state=%s '\
189+ 'WHERE id IN %s', ('draft', tuple(ids)))
190 return True
191
192 def write(self, cr, uid, ids, vals, context={}):
193@@ -995,7 +1052,10 @@
194 else:
195 line_id2 = 0
196
197- cr.execute('select sum('+mode+') from account_move_line where move_id=%s and id<>%s', (move.id, line_id2))
198+ cr.execute('SELECT SUM(%s) '\
199+ 'FROM account_move_line '\
200+ 'WHERE move_id=%s AND id<>%s',
201+ (mode, move.id, line_id2))
202 result = cr.fetchone()[0] or 0.0
203 cr.execute('update account_move_line set '+mode2+'=%s where id=%s', (result, line_id))
204 return True
205@@ -1143,25 +1203,28 @@
206
207 This code is used for some tax declarations.
208 """
209- def _sum(self, cr, uid, ids, name, args, context, where =''):
210- ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)])
211- acc_set = ",".join(map(str, ids2))
212+ def _sum(self, cr, uid, ids, name, args, context,
213+ where ='', where_params=()):
214+ parent_ids = tuple(self.search(
215+ cr, uid, [('parent_id', 'child_of', ids)]))
216 if context.get('based_on', 'invoices') == 'payments':
217 cr.execute('SELECT line.tax_code_id, sum(line.tax_amount) \
218 FROM account_move_line AS line, \
219 account_move AS move \
220 LEFT JOIN account_invoice invoice ON \
221 (invoice.move_id = move.id) \
222- WHERE line.tax_code_id in ('+acc_set+') '+where+' \
223+ WHERE line.tax_code_id in %s '+where+' \
224 AND move.id = line.move_id \
225 AND ((invoice.state = \'paid\') \
226 OR (invoice.id IS NULL)) \
227- GROUP BY line.tax_code_id')
228+ GROUP BY line.tax_code_id',
229+ (parent_ids,)+where_params)
230 else:
231 cr.execute('SELECT line.tax_code_id, sum(line.tax_amount) \
232 FROM account_move_line AS line \
233- WHERE line.tax_code_id in ('+acc_set+') '+where+' \
234- GROUP BY line.tax_code_id')
235+ WHERE line.tax_code_id in %s '+where+' \
236+ GROUP BY line.tax_code_id',
237+ (parent_ids,)+where_params)
238 res=dict(cr.fetchall())
239 for record in self.browse(cr, uid, ids, context):
240 def _rec_get(record):
241@@ -1178,12 +1241,14 @@
242 else:
243 fiscalyear_id = self.pool.get('account.fiscalyear').find(cr, uid, exception=False)
244 where = ''
245+ where_params = ()
246 if fiscalyear_id:
247 pids = map(lambda x: str(x.id), self.pool.get('account.fiscalyear').browse(cr, uid, fiscalyear_id).period_ids)
248 if pids:
249- where = ' and period_id in (' + (','.join(pids))+')'
250+ where = ' and period_id in %s'
251+ where_params = (tuple(pids),)
252 return self._sum(cr, uid, ids, name, args, context,
253- where=where)
254+ where=where, where_params=where_params)
255
256 def _sum_period(self, cr, uid, ids, name, args, context):
257 if 'period_id' in context and context['period_id']:
258@@ -1194,7 +1259,8 @@
259 return dict.fromkeys(ids, 0.0)
260 period_id = period_id[0]
261 return self._sum(cr, uid, ids, name, args, context,
262- where=' and line.period_id='+str(period_id))
263+ where=' and line.period_id=%s',
264+ where_params=(period_id,))
265
266 _name = 'account.tax.code'
267 _description = 'Tax Code'
268@@ -1240,6 +1306,7 @@
269 'sign': lambda *args: 1.0,
270 'notprintable': lambda *a: False,
271 }
272+<<<<<<< TREE
273 def _check_recursion(self, cr, uid, ids):
274 level = 100
275 while len(ids):
276@@ -1257,6 +1324,9 @@
277 default.update({'line_ids': []})
278 return super(account_tax_code, self).copy(cr, uid, id, default, context)
279
280+=======
281+ _check_recursion = check_cycle
282+>>>>>>> MERGE-SOURCE
283 _constraints = [
284 (_check_recursion, 'Error ! You can not create recursive accounts.', ['parent_id'])
285 ]
286@@ -1869,16 +1939,7 @@
287 'type' : lambda *a :'view',
288 }
289
290- def _check_recursion(self, cr, uid, ids):
291- level = 100
292- while len(ids):
293- cr.execute('select parent_id from account_account_template where id in ('+','.join(map(str,ids))+')')
294- ids = filter(None, map(lambda x:x[0], cr.fetchall()))
295- if not level:
296- return False
297- level -= 1
298- return True
299-
300+ _check_recursion = check_cycle
301 _constraints = [
302 (_check_recursion, 'Error ! You can not create recursive account templates.', ['parent_id'])
303 ]
304@@ -1928,16 +1989,7 @@
305 return [(x['id'], (x['code'] and x['code'] + ' - ' or '') + x['name']) \
306 for x in reads]
307
308- def _check_recursion(self, cr, uid, ids):
309- level = 100
310- while len(ids):
311- cr.execute('select distinct parent_id from account_tax_code_template where id in ('+','.join(map(str,ids))+')')
312- ids = filter(None, map(lambda x:x[0], cr.fetchall()))
313- if not level:
314- return False
315- level -= 1
316- return True
317-
318+ _check_recursion = check_cycle
319 _constraints = [
320 (_check_recursion, 'Error ! You can not create recursive Tax Codes.', ['parent_id'])
321 ]
322
323=== modified file 'account/account_move_line.py'
324--- account/account_move_line.py 2010-03-04 11:50:58 +0000
325+++ account/account_move_line.py 2010-03-17 11:50:49 +0000
326@@ -257,9 +257,10 @@
327 for line_id in ids:
328 res[line_id] = False
329 cursor.execute('SELECT l.id, i.id ' \
330- 'FROM account_move_line l, account_invoice i ' \
331- 'WHERE l.move_id = i.move_id ' \
332- 'AND l.id in (' + ','.join([str(x) for x in ids]) + ')')
333+ 'FROM account_move_line l, account_invoice i ' \
334+ 'WHERE l.move_id = i.move_id ' \
335+ 'AND l.id in %s',
336+ (tuple(ids),))
337 invoice_ids = []
338 for line_id, invoice_id in cursor.fetchall():
339 res[line_id] = invoice_id
340@@ -566,10 +567,11 @@
341 else:
342 date = time.strftime('%Y-%m-%d')
343
344- cr.execute('SELECT account_id, reconcile_id \
345- FROM account_move_line \
346- WHERE id IN ('+id_set+') \
347- GROUP BY account_id,reconcile_id')
348+ cr.execute('SELECT account_id, reconcile_id '\
349+ 'FROM account_move_line '\
350+ 'WHERE id IN %s '\
351+ 'GROUP BY account_id,reconcile_id',
352+ (tuple(ids),))
353 r = cr.fetchall()
354 #TODO: move this check to a constraint in the account_move_reconcile object
355 if (len(r) != 1) and not context.get('fy_closing', False):
356
357=== modified file 'account/invoice.py'
358--- account/invoice.py 2010-03-09 12:49:07 +0000
359+++ account/invoice.py 2010-03-17 11:50:49 +0000
360@@ -21,6 +21,8 @@
361 ##############################################################################
362
363 import time
364+from operator import itemgetter
365+
366 import netsvc
367 from osv import fields, osv
368 import pooler
369@@ -428,12 +430,13 @@
370 def move_line_id_payment_get(self, cr, uid, ids, *args):
371 res = []
372 if not ids: return res
373- cr.execute('select \
374- l.id \
375- from account_move_line l \
376- left join account_invoice i on (i.move_id=l.move_id) \
377- where i.id in ('+','.join(map(str,ids))+') and l.account_id=i.account_id')
378- res = map(lambda x: x[0], cr.fetchall())
379+ cr.execute('SELECT l.id '\
380+ 'FROM account_move_line l '\
381+ 'LEFT JOIN account_invoice i ON (i.move_id=l.move_id) '\
382+ 'WHERE i.id IN %s '\
383+ 'AND l.account_id=i.account_id',
384+ (tuple(ids),))
385+ res = map(itemgetter(0), cr.fetchall())
386 return res
387
388 def copy(self, cr, uid, id, default=None, context=None):
389@@ -714,8 +717,9 @@
390
391 def action_number(self, cr, uid, ids, *args):
392 cr.execute('SELECT id, type, number, move_id, reference ' \
393- 'FROM account_invoice ' \
394- 'WHERE id IN ('+','.join(map(str,ids))+')')
395+ 'FROM account_invoice ' \
396+ 'WHERE id IN %s',
397+ (tuple(ids),))
398 obj_inv = self.browse(cr, uid, ids)[0]
399 for (id, invtype, number, move_id, reference) in cr.fetchall():
400 if not number:
401@@ -949,7 +953,9 @@
402 line_ids = []
403 total = 0.0
404 line = self.pool.get('account.move.line')
405- cr.execute('select id from account_move_line where move_id in ('+str(move_id)+','+str(invoice.move_id.id)+')')
406+ cr.execute('SELECT id FROM account_move_line '\
407+ 'WHERE move_id in %s',
408+ ((move_id, invoice.move_id.id),))
409 lines = line.browse(cr, uid, map(lambda x: x[0], cr.fetchall()) )
410 for l in lines+invoice.payment_ids:
411 if l.account_id.id==src_account_id:
412
413=== modified file 'account/partner.py'
414--- account/partner.py 2010-01-08 11:38:58 +0000
415+++ account/partner.py 2010-03-17 11:50:49 +0000
416@@ -19,6 +19,7 @@
417 # along with this program. If not, see <http://www.gnu.org/licenses/>.
418 #
419 ##############################################################################
420+from operator import itemgetter
421
422 from osv import fields, osv
423 import ir
424@@ -89,22 +90,19 @@
425 _name = 'res.partner'
426 _inherit = 'res.partner'
427 _description = 'Partner'
428+
429 def _credit_debit_get(self, cr, uid, ids, field_names, arg, context):
430 query = self.pool.get('account.move.line')._query_get(cr, uid, context=context)
431- cr.execute(("""select
432- l.partner_id, a.type, sum(l.debit-l.credit)
433- from
434- account_move_line l
435- left join
436- account_account a on (l.account_id=a.id)
437- where
438- a.type in ('receivable','payable') and
439- l.partner_id in (%s) and
440- l.reconcile_id is null and
441- """ % (','.join(map(str, ids)),))+query+"""
442- group by
443- l.partner_id, a.type
444- """)
445+ cr.execute("""SELECT l.partner_id, a.type, SUM(l.debit-l.credit)
446+ FROM account_move_line l
447+ LEFT JOIN account_account a ON (l.account_id=a.id)
448+ WHERE a.type IN ('receivable','payable')
449+ AND l.partner_id in %s
450+ AND l.reconcile_id IS NULL
451+ AND """ + query + """
452+ GROUP BY l.partner_id, a.type
453+ """,
454+ (tuple(ids),))
455 tinvert = {
456 'credit': 'receivable',
457 'debit': 'payable'
458@@ -118,27 +116,38 @@
459 res[pid][maps[type]] = (type=='receivable') and val or -val
460 return res
461
462+ def _asset_difference_search(self, cr, uid, obj, name, type, args,
463+ context=None):
464+ if not len(args):
465+ return []
466+ having_values = tuple(map(itemgetter(2), args))
467+ where = ' AND '.join(
468+ map(lambda x: '(SUM(debit-credit) %(operator)s %%s)' % {
469+ 'operator':x[1]},
470+ args))
471+ query = self.pool.get('account.move.line')._query_get(cr, uid,
472+ context=context)
473+ cr.execute(('SELECT partner_id FROM account_move_line l '\
474+ 'WHERE account_id IN '\
475+ '(SELECT id FROM account_account '\
476+ 'WHERE type=%s AND active) '\
477+ 'AND reconcile_id IS NULL '\
478+ 'AND '+query+' '\
479+ 'AND partner_id IS NOT NULL '\
480+ 'GROUP BY partner_id HAVING '+where),
481+ (type,) + having_values)
482+ res = cr.fetchall()
483+ if not len(res):
484+ return [('id','=','0')]
485+ return [('id','in',map(itemgetter(0), res))]
486+
487 def _credit_search(self, cr, uid, obj, name, args, context):
488- if not len(args):
489- return []
490- where = ' and '.join(map(lambda x: '(sum(debit-credit)'+x[1]+str(x[2])+')',args))
491- query = self.pool.get('account.move.line')._query_get(cr, uid, context={})
492- cr.execute(('select partner_id from account_move_line l where account_id in (select id from account_account where type=%s and active) and reconcile_id is null and '+query+' and partner_id is not null group by partner_id having '+where), ('receivable',) )
493- res = cr.fetchall()
494- if not len(res):
495- return [('id','=','0')]
496- return [('id','in',map(lambda x:x[0], res))]
497+ return self._asset_difference_search(
498+ cr, uid, obj, name, 'receivable', args, context=context)
499
500 def _debit_search(self, cr, uid, obj, name, args, context):
501- if not len(args):
502- return []
503- query = self.pool.get('account.move.line')._query_get(cr, uid, context={})
504- where = ' and '.join(map(lambda x: '(sum(debit-credit)'+x[1]+str(x[2])+')',args))
505- cr.execute(('select partner_id from account_move_line l where account_id in (select id from account_account where type=%s and active) and reconcile_id is null and '+query+' and partner_id is not null group by partner_id having '+where), ('payable',) )
506- res = cr.fetchall()
507- if not len(res):
508- return [('id','=','0')]
509- return [('id','in',map(lambda x:x[0], res))]
510+ return self._asset_difference_search(
511+ cr, uid, obj, name, 'payable', args, context=context)
512
513 _columns = {
514 'credit': fields.function(_credit_debit_get,
515
516=== modified file 'account/project/project.py'
517--- account/project/project.py 2010-02-15 07:17:01 +0000
518+++ account/project/project.py 2010-03-17 11:50:49 +0000
519@@ -1,7 +1,7 @@
520 # -*- encoding: utf-8 -*-
521 ##############################################################################
522 #
523-# OpenERP, Open Source Management Solution
524+# OpenERP, Open Source Management Solution
525 # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
526 # $Id$
527 #
528@@ -19,10 +19,10 @@
529 # along with this program. If not, see <http://www.gnu.org/licenses/>.
530 #
531 ##############################################################################
532-
533 import time
534 import operator
535
536+import netsvc
537 from osv import fields
538 from osv import osv
539
540@@ -33,47 +33,52 @@
541 class account_analytic_account(osv.osv):
542 _name = 'account.analytic.account'
543 _description = 'Analytic Accounts'
544+ logger = netsvc.Logger()
545
546 def _credit_calc(self, cr, uid, ids, name, arg, context={}):
547- r = {}
548- acc_set = ",".join(map(str, ids))
549-
550- for i in ids:
551- r.setdefault(i,0.0)
552-
553- if not acc_set:
554- return r
555+ self.logger.notifyChannel('addons.'+self._name, netsvc.LOG_DEBUG,
556+ 'Entering _credit_calc; ids:%s'%ids)
557+ if not ids: return {}
558
559 where_date = ''
560- if context.get('from_date',False):
561- where_date += " AND l.date >= '" + context['from_date'] + "'"
562- if context.get('to_date',False):
563- where_date += " AND l.date <= '" + context['to_date'] + "'"
564-
565- 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))
566+ if context.get('from_date'):
567+ where_date += " AND l.date >= %(from_date)s"
568+ if context.get('to_date'):
569+ where_date += " AND l.date <= %(to_date)s"
570+
571+ cr.execute("SELECT a.id, COALESCE(SUM(l.amount), 0) "
572+ "FROM account_analytic_account a "
573+ "LEFT JOIN account_analytic_line l ON (a.id=l.account_id %s)"
574+ " WHERE l.amount < 0 AND a.id IN %%(ids)s "
575+ "GROUP BY a.id" % (where_date),
576+ dict(context, ids=tuple(ids)))
577 r = dict(cr.fetchall())
578+ self.logger.notifyChannel('addons.'+self._name, netsvc.LOG_DEBUG,
579+ '_credit_calc results: %s'%r)
580 for i in ids:
581 r.setdefault(i,0.0)
582 return r
583
584 def _debit_calc(self, cr, uid, ids, name, arg, context={}):
585- r = {}
586- acc_set = ",".join(map(str, ids))
587+ self.logger.notifyChannel('addons.'+self._name, netsvc.LOG_DEBUG,
588+ 'Entering _debit_calc; ids:%s'%ids)
589+ if not ids: return {}
590
591- for i in ids:
592- r.setdefault(i,0.0)
593-
594- if not acc_set:
595- return r
596-
597 where_date = ''
598- if context.get('from_date',False):
599- where_date += " AND l.date >= '" + context['from_date'] + "'"
600- if context.get('to_date',False):
601- where_date += " AND l.date <= '" + context['to_date'] + "'"
602-
603- 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))
604- r= dict(cr.fetchall())
605+ if context.get('from_date'):
606+ where_date += " AND l.date >= %(from_date)s"
607+ if context.get('to_date'):
608+ where_date += " AND l.date <= %(to_date)s"
609+
610+ cr.execute("SELECT a.id, COALESCE(SUM(l.amount), 0) "
611+ "FROM account_analytic_account a "
612+ "LEFT JOIN account_analytic_line l ON (a.id=l.account_id %s)"
613+ " WHERE l.amount > 0 AND a.id IN %%(ids)s "
614+ "GROUP BY a.id" % (where_date),
615+ dict(context, ids=tuple(ids)))
616+ r = dict(cr.fetchall())
617+ self.logger.notifyChannel('addons.'+self._name, netsvc.LOG_DEBUG,
618+ '_debut_calc results: %s'%r)
619 for i in ids:
620 r.setdefault(i,0.0)
621 return r
622@@ -81,35 +86,49 @@
623 def _balance_calc(self, cr, uid, ids, name, arg, context={}):
624 res = {}
625 ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)])
626- acc_set = ",".join(map(str, ids2))
627-
628+ self.logger.notifyChannel('addons.'+self._name, netsvc.LOG_DEBUG,
629+ 'Entering _balance_calc; ids:%s; ids2:%s'%(
630+ ids, ids2))
631+
632 for i in ids:
633 res.setdefault(i,0.0)
634-
635- if not acc_set:
636+
637+ if not ids2:
638 return res
639-
640+
641 where_date = ''
642- if context.get('from_date',False):
643- where_date += " AND l.date >= '" + context['from_date'] + "'"
644- if context.get('to_date',False):
645- where_date += " AND l.date <= '" + context['to_date'] + "'"
646-
647- 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))
648-
649+ if context.get('from_date'):
650+ where_date += " AND l.date >= %(from_date)s"
651+ if context.get('to_date'):
652+ where_date += " AND l.date <= %(to_date)s"
653+
654+ cr.execute("SELECT a.id, COALESCE(SUM(l.amount),0) "
655+ "FROM account_analytic_account a "
656+ "LEFT JOIN account_analytic_line l ON (a.id=l.account_id %s)"
657+ " WHERE a.id IN %%(ids)s "
658+ "GROUP BY a.id" % (where_date),
659+ dict(context, ids=tuple(ids)))
660+
661 for account_id, sum in cr.fetchall():
662 res[account_id] = sum
663-
664- 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)
665-
666- currency= dict(cr.fetchall())
667+ self.logger.notifyChannel('addons.'+self._name, netsvc.LOG_DEBUG,
668+ '_balance_calc, (id, sum): %s'%res)
669+
670+ cr.execute("SELECT a.id, r.currency_id "
671+ "FROM account_analytic_account a "
672+ "INNER JOIN res_company r ON (a.company_id = r.id) "
673+ "WHERE a.id in %s", (tuple(ids),))
674+
675+ currency = dict(cr.fetchall())
676+ self.logger.notifyChannel('addons.'+self._name, netsvc.LOG_DEBUG,
677+ '_balance_calc currency: %s'%currency)
678
679 res_currency= self.pool.get('res.currency')
680 for id in ids:
681 if id not in ids2:
682 continue
683 for child in self.search(cr, uid, [('parent_id', 'child_of', [id])]):
684- if child <> id:
685+ if child != id:
686 res.setdefault(id, 0.0)
687 if currency[child]<>currency[id]:
688 res[id] += res_currency.compute(cr, uid, currency[child], currency[id], res.get(child, 0.0), context=context)
689@@ -125,36 +144,40 @@
690 return dict([(i, res[i]) for i in ids ])
691
692 def _quantity_calc(self, cr, uid, ids, name, arg, context={}):
693+ self.logger.notifyChannel('addons.'+self._name, netsvc.LOG_DEBUG,
694+ '_quantity_calc ids:%s'%ids)
695 #XXX must convert into one uom
696 res = {}
697 ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)])
698- acc_set = ",".join(map(str, ids2))
699-
700+
701 for i in ids:
702 res.setdefault(i,0.0)
703-
704- if not acc_set:
705+
706+ if not ids2:
707 return res
708-
709+
710 where_date = ''
711- if context.get('from_date',False):
712- where_date += " AND l.date >= '" + context['from_date'] + "'"
713- if context.get('to_date',False):
714- where_date += " AND l.date <= '" + context['to_date'] + "'"
715-
716+ if context.get('from_date'):
717+ where_date += " AND l.date >= %(from_date)s"
718+ if context.get('to_date'):
719+ where_date += " AND l.date <= %(to_date)s"
720+
721 cr.execute('SELECT a.id, COALESCE(SUM(l.unit_amount), 0) \
722 FROM account_analytic_account a \
723- LEFT JOIN account_analytic_line l ON (a.id = l.account_id ' + where_date + ') \
724- WHERE a.id IN ('+acc_set+') GROUP BY a.id')
725+ LEFT JOIN account_analytic_line l ON (a.id = l.account_id %s) \
726+ WHERE a.id IN %%(ids)s GROUP BY a.id'%(where_date),
727+ dict(context, ids=tuple(ids2)))
728
729 for account_id, sum in cr.fetchall():
730 res[account_id] = sum
731+ self.logger.notifyChannel('addons.'+self._name, netsvc.LOG_DEBUG,
732+ '_quantity_calc, (id, sum): %s'%res)
733
734 for id in ids:
735 if id not in ids2:
736 continue
737 for child in self.search(cr, uid, [('parent_id', 'child_of', [id])]):
738- if child <> id:
739+ if child != id:
740 res.setdefault(id, 0.0)
741 res[id] += res.get(child, 0.0)
742 return dict([(i, res[i]) for i in ids])
743@@ -299,4 +322,3 @@
744 account_journal()
745
746 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
747-
748
749=== modified file 'account/project/report/analytic_balance.py'
750--- account/project/report/analytic_balance.py 2009-10-09 11:49:00 +0000
751+++ account/project/report/analytic_balance.py 2010-03-17 11:50:49 +0000
752@@ -33,15 +33,9 @@
753 'get_objects': self._get_objects,
754 'lines_g': self._lines_g,
755 'move_sum': self._move_sum,
756-# 'move_sum_debit': self._move_sum_debit,
757-# 'move_sum_credit': self._move_sum_credit,
758 'sum_all': self._sum_all,
759-# 'sum_debit': self._sum_debit,
760-# 'sum_credit': self._sum_credit,
761 'sum_balance': self._sum_balance,
762-# 'sum_quantity': self._sum_quantity,
763 'move_sum_balance': self._move_sum_balance,
764-# 'move_sum_quantity': self._move_sum_quantity,
765 })
766 self.acc_ids = []
767 self.read_data = []
768@@ -82,10 +76,10 @@
769 sum(aal.amount) AS balance, sum(aal.unit_amount) AS quantity \
770 FROM account_analytic_line AS aal, account_account AS aa \
771 WHERE (aal.general_account_id=aa.id) \
772- AND (aal.account_id in (" + ','.join(map(str, ids)) + "))\
773+ AND (aal.account_id in %s)\
774 AND (date>=%s) AND (date<=%s) AND aa.active \
775 GROUP BY aal.general_account_id, aa.name, aa.code, aal.code \
776- ORDER BY aal.code", (date1, date2))
777+ ORDER BY aal.code", (tuple(ids), date1, date2))
778 res = self.cr.dictfetchall()
779
780 for r in res:
781@@ -108,62 +102,26 @@
782 self.acc_data_dict[account_id] = ids
783 else:
784 ids = self.acc_data_dict[account_id]
785-
786+
787+ query_params = (tuple(ids), date1, date2)
788 if option == "credit" :
789 self.cr.execute("SELECT -sum(amount) FROM account_analytic_line \
790- WHERE account_id in ("+ ','.join(map(str, ids)) +") \
791- AND date>=%s AND date<=%s AND amount<0",
792- (date1, date2))
793+ WHERE account_id in %s \
794+ AND date>=%s AND date<=%s AND amount<0", query_params)
795 elif option == "debit" :
796 self.cr.execute("SELECT sum(amount) FROM account_analytic_line \
797- WHERE account_id in ("+ ','.join(map(str, ids)) +") \
798- AND date>=%s AND date<=%s AND amount>0",
799- (date1, date2))
800+ WHERE account_id in %s \
801+ AND date>=%s AND date<=%s AND amount>0", query_params)
802 elif option == "quantity" :
803 self.cr.execute("SELECT sum(unit_amount) FROM account_analytic_line \
804- WHERE account_id in ("+ ','.join(map(str, ids)) +") \
805- AND date>=%s AND date<=%s",
806- (date1, date2))
807+ WHERE account_id in %s \
808+ AND date>=%s AND date<=%s", query_params)
809 return self.cr.fetchone()[0] or 0.0
810-
811
812-# def _move_sum_debit(self, account_id, date1, date2):
813-# account_analytic_obj = self.pool.get('account.analytic.account')
814-# ids = account_analytic_obj.search(self.cr, self.uid,
815-# [('parent_id', 'child_of', [account_id])])
816-# self.cr.execute("SELECT sum(amount) \
817-# FROM account_analytic_line \
818-# WHERE account_id in ("+ ','.join(map(str, ids)) +") \
819-# AND date>=%s AND date<=%s AND amount>0",
820-# (date1, date2))
821-# return self.cr.fetchone()[0] or 0.0
822-#
823-# def _move_sum_credit(self, account_id, date1, date2):
824-# account_analytic_obj = self.pool.get('account.analytic.account')
825-# ids = account_analytic_obj.search(self.cr, self.uid,
826-# [('parent_id', 'child_of', [account_id])])
827-# self.cr.execute("SELECT -sum(amount) \
828-# FROM account_analytic_line \
829-# WHERE account_id in ("+ ','.join(map(str, ids)) +") \
830-# AND date>=%s AND date<=%s AND amount<0",
831-# (date1, date2))
832-# return self.cr.fetchone()[0] or 0.0
833-#
834 def _move_sum_balance(self, account_id, date1, date2):
835 debit = self._move_sum(account_id, date1, date2, 'debit')
836 credit = self._move_sum(account_id, date1, date2, 'credit')
837 return (debit-credit)
838-
839-# def _move_sum_quantity(self, account_id, date1, date2):
840-# account_analytic_obj = self.pool.get('account.analytic.account')
841-# ids = account_analytic_obj.search(self.cr, self.uid,
842-# [('parent_id', 'child_of', [account_id])])
843-# self.cr.execute("SELECT sum(unit_amount) \
844-# FROM account_analytic_line \
845-# WHERE account_id in ("+ ','.join(map(str, ids)) +") \
846-# AND date>=%s AND date<=%s",
847-# (date1, date2))
848-# return self.cr.fetchone()[0] or 0.0
849
850 def _sum_all(self, accounts, date1, date2, option):
851 ids = map(lambda x: x['id'], accounts)
852@@ -178,72 +136,26 @@
853 else:
854 ids2 = self.acc_sum_list
855
856+ query_params = (tuple(ids2), date1, date2)
857 if option == "debit" :
858 self.cr.execute("SELECT sum(amount) FROM account_analytic_line \
859- WHERE account_id IN ("+','.join(map(str, ids2))+") \
860- AND date>=%s AND date<=%s AND amount>0",
861- (date1, date2))
862+ WHERE account_id IN %s \
863+ AND date>=%s AND date<=%s AND amount>0", query_params)
864 elif option == "credit" :
865 self.cr.execute("SELECT -sum(amount) FROM account_analytic_line \
866- WHERE account_id IN ("+','.join(map(str, ids2))+") \
867- AND date>=%s AND date<=%s AND amount<0",
868- (date1, date2))
869+ WHERE account_id IN %s \
870+ AND date>=%s AND date<=%s AND amount<0", query_params)
871 elif option == "quantity" :
872 self.cr.execute("SELECT sum(unit_amount) FROM account_analytic_line \
873- WHERE account_id IN ("+','.join(map(str, ids2))+") \
874- AND date>=%s AND date<=%s",
875- (date1, date2))
876+ WHERE account_id IN %s \
877+ AND date>=%s AND date<=%s", query_params)
878 return self.cr.fetchone()[0] or 0.0
879
880-
881-# def _sum_debit(self, accounts, date1, date2):
882-# ids = map(lambda x: x['id'], accounts)
883-# if not len(ids):
884-# return 0.0
885-# account_analytic_obj = self.pool.get('account.analytic.account')
886-# ids2 = account_analytic_obj.search(self.cr, self.uid,
887-# [('parent_id', 'child_of', ids)])
888-# self.cr.execute("SELECT sum(amount) \
889-# FROM account_analytic_line \
890-# WHERE account_id IN ("+','.join(map(str, ids2))+") \
891-# AND date>=%s AND date<=%s AND amount>0",
892-# (date1, date2))
893-# return self.cr.fetchone()[0] or 0.0
894-#
895-# def _sum_credit(self, accounts, date1, date2):
896-# ids = map(lambda x: x['id'], accounts)
897-# if not len(ids):
898-# return 0.0
899-# ids = map(lambda x: x['id'], accounts)
900-# account_analytic_obj = self.pool.get('account.analytic.account')
901-# ids2 = account_analytic_obj.search(self.cr, self.uid,
902-# [('parent_id', 'child_of', ids)])
903-# self.cr.execute("SELECT -sum(amount) \
904-# FROM account_analytic_line \
905-# WHERE account_id IN ("+','.join(map(str, ids2))+") \
906-# AND date>=%s AND date<=%s AND amount<0",
907-# (date1, date2))
908-# return self.cr.fetchone()[0] or 0.0
909-
910 def _sum_balance(self, accounts, date1, date2):
911 debit = self._sum_all(accounts, date1, date2, 'debit') or 0.0
912 credit = self._sum_all(accounts, date1, date2, 'credit') or 0.0
913 return (debit-credit)
914
915-# def _sum_quantity(self, accounts, date1, date2):
916-# ids = map(lambda x: x['id'], accounts)
917-# if not len(ids):
918-# return 0.0
919-# account_analytic_obj = self.pool.get('account.analytic.account')
920-# ids2 = account_analytic_obj.search(self.cr, self.uid,
921-# [('parent_id', 'child_of', ids)])
922-# self.cr.execute("SELECT sum(unit_amount) \
923-# FROM account_analytic_line \
924-# WHERE account_id IN ("+','.join(map(str, ids2))+") \
925-# AND date>=%s AND date<=%s",
926-# (date1, date2))
927-# return self.cr.fetchone()[0] or 0.0
928-
929 report_sxw.report_sxw('report.account.analytic.account.balance',
930 'account.analytic.account', 'addons/account/project/report/analytic_balance.rml',
931 parser=account_analytic_balance, header=False)
932
933=== modified file 'account/project/report/analytic_check.py'
934--- account/project/report/analytic_check.py 2010-02-24 10:46:58 +0000
935+++ account/project/report/analytic_check.py 2010-03-17 11:50:49 +0000
936@@ -44,7 +44,6 @@
937 def _lines_p(self, date1, date2):
938 res = []
939 acc_obj = self.pool.get('account.account')
940- # print"3333333acc_obj3333333",acc_obj.read(self.cr, self.uid, self.ids, ['name', 'code','user_type'])
941
942 for a in acc_obj.read(self.cr, self.uid, self.ids, ['name', 'code']):
943 self.cr.execute("SELECT sum(debit), sum(credit) \
944@@ -79,41 +78,6 @@
945
946 return res
947
948-# def _lines_p(self, date1, date2):
949-# res = []
950-# acc_obj = self.pool.get('account.account')
951-# for a in acc_obj.read(self.cr, self.uid, self.ids, ['name', 'code','sign']):
952-# self.cr.execute("SELECT sum(debit), sum(credit) \
953-# FROM account_move_line \
954-# WHERE date>=%s AND date<=%s AND state<>'draft' AND account_id = %s", (date1, date2, a['id']))
955-# (gd, gc) = self.cr.fetchone()
956-# gd = gd or 0.0
957-# gc = gc or 0.0
958-#
959-# self.cr.execute("SELECT abs(sum(amount)) AS balance \
960-# FROM account_analytic_line \
961-# WHERE date>=%s AND date<=%s AND amount*%s>0 AND general_account_id = %s", (date1, date2, a['sign'], a['id']))
962-# (ad,) = self.cr.fetchone()
963-# ad = ad or 0.0
964-# self.cr.execute("SELECT abs(sum(amount)) AS balance \
965-# FROM account_analytic_line \
966-# WHERE date>=%s AND date<=%s AND amount*%s<0 AND general_account_id = %s", (date1, date2, a['sign'], a['id']))
967-# (ac,) = self.cr.fetchone()
968-# ac = ac or 0.0
969-#
970-# res.append({'code': a['code'], 'name': a['name'],
971-# 'gen_debit': gd,
972-# 'gen_credit': gc,
973-# 'ana_debit': ad,
974-# 'ana_credit': ac,
975-# 'delta_debit': gd - ad,
976-# 'delta_credit': gc - ac,})
977-# self.sum_gen_deb += gd
978-# self.sum_gen_cred += gc
979-# self.sum_ana_deb += ad
980-# self.sum_ana_cred += ac
981-# return res
982-
983 def _gen_deb(self, date1, date2):
984 return self.sum_gen_deb
985
986@@ -134,5 +98,4 @@
987
988 report_sxw.report_sxw('report.account.analytic.account.analytic.check', 'account.analytic.account', 'addons/account/project/report/analytic_check.rml',parser=account_analytic_analytic_check, header=False)
989
990-
991 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
992
993=== modified file 'account/project/report/cost_ledger.py'
994--- account/project/report/cost_ledger.py 2009-10-09 11:49:00 +0000
995+++ account/project/report/cost_ledger.py 2010-03-17 11:50:49 +0000
996@@ -94,15 +94,20 @@
997 ids = map(lambda x: x.id, accounts)
998 if not len(ids):
999 return 0.0
1000- 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))
1001+ self.cr.execute("SELECT SUM(amount) FROM account_analytic_line "
1002+ "WHERE account_id IN %s "
1003+ "AND date>=%s AND date<=%s AND amount>0",
1004+ (tuple(ids), date1, date2))
1005 return self.cr.fetchone()[0] or 0.0
1006
1007 def _sum_credit(self, accounts, date1, date2):
1008 ids = map(lambda x: x.id, accounts)
1009 if not len(ids):
1010 return 0.0
1011- ids = map(lambda x: x.id, accounts)
1012- 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))
1013+ self.cr.execute("SELECT -SUM(amount) FROM account_analytic_line "
1014+ "WHERE account_id IN %s "
1015+ "AND date>=%s AND date<=%s AND amount<0",
1016+ (tuple(ids), date1, date2))
1017 return self.cr.fetchone()[0] or 0.0
1018
1019 def _sum_balance(self, accounts, date1, date2):
1020@@ -112,6 +117,5 @@
1021
1022 report_sxw.report_sxw('report.account.analytic.account.cost_ledger', 'account.analytic.account', 'addons/account/project/report/cost_ledger.rml',parser=account_analytic_cost_ledger, header=False)
1023
1024-
1025 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
1026
1027
1028=== modified file 'account/project/report/inverted_analytic_balance.py'
1029--- account/project/report/inverted_analytic_balance.py 2009-10-09 11:49:00 +0000
1030+++ account/project/report/inverted_analytic_balance.py 2010-03-17 11:50:49 +0000
1031@@ -39,10 +39,16 @@
1032
1033 def _lines_g(self, accounts, date1, date2):
1034 ids = map(lambda x: x.id, accounts)
1035- 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 \
1036+ self.cr.execute("SELECT aa.name AS name, aa.code AS code, "
1037+ "sum(aal.amount) AS balance, "
1038+ "sum(aal.unit_amount) AS quantity, aa.id AS id \
1039 FROM account_analytic_line AS aal, account_account AS aa \
1040- 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 \
1041- GROUP BY aal.general_account_id, aa.name, aa.code, aal.code, aa.id ORDER BY aal.code", (date1, date2))
1042+ WHERE (aal.general_account_id=aa.id) "
1043+ "AND (aal.account_id IN %s) "
1044+ "AND (date>=%s) AND (date<=%s) AND aa.active \
1045+ GROUP BY aal.general_account_id, aa.name, aa.code, aal.code, aa.id "
1046+ "ORDER BY aal.code",
1047+ (tuple(ids), date1, date2))
1048 res = self.cr.dictfetchall()
1049
1050 for r in res:
1051@@ -59,10 +65,17 @@
1052
1053 def _lines_a(self, accounts, general_account_id, date1, date2):
1054 ids = map(lambda x: x.id, accounts)
1055- 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 \
1056- FROM account_analytic_line AS aal, account_analytic_account AS aaa \
1057- 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 \
1058- GROUP BY aal.account_id, general_account_id, aaa.code, aaa.name ORDER BY aal.account_id", (general_account_id, date1, date2))
1059+ self.cr.execute("SELECT sum(aal.amount) AS balance, "
1060+ "sum(aal.unit_amount) AS quantity, "
1061+ "aaa.code AS code, aaa.name AS name, account_id \
1062+ FROM account_analytic_line AS aal, "
1063+ "account_analytic_account AS aaa \
1064+ WHERE aal.account_id=aaa.id AND aal.account_id IN %s "
1065+ "AND aal.general_account_id=%s AND aal.date>=%s "
1066+ "AND aal.date<=%s \
1067+ GROUP BY aal.account_id, general_account_id, aaa.code, aaa.name "
1068+ "ORDER BY aal.account_id",
1069+ (tuple(ids), general_account_id, date1, date2))
1070 res = self.cr.dictfetchall()
1071
1072 aaa_obj = self.pool.get('account.analytic.account')
1073@@ -87,14 +100,16 @@
1074 ids = map(lambda x: x.id, accounts)
1075 self.cr.execute("SELECT sum(amount) \
1076 FROM account_analytic_line \
1077- WHERE account_id IN ("+','.join(map(str, ids))+") AND date>=%s AND date<=%s AND amount>0", (date1, date2))
1078+ WHERE account_id IN %s AND date>=%s AND date<=%s AND amount>0",
1079+ (tuple(ids), date1, date2))
1080 return self.cr.fetchone()[0] or 0.0
1081
1082 def _sum_credit(self, accounts, date1, date2):
1083 ids = map(lambda x: x.id, accounts)
1084 self.cr.execute("SELECT -sum(amount) \
1085 FROM account_analytic_line \
1086- WHERE account_id IN ("+','.join(map(str, ids))+") AND date>=%s AND date<=%s AND amount<0", (date1, date2))
1087+ WHERE account_id IN %s AND date>=%s AND date<=%s AND amount<0",
1088+ (tuple(ids), date1, date2))
1089 return self.cr.fetchone()[0] or 0.0
1090
1091 def _sum_balance(self, accounts, date1, date2):
1092@@ -106,7 +121,8 @@
1093 ids = map(lambda x: x.id, accounts)
1094 self.cr.execute("SELECT sum(unit_amount) \
1095 FROM account_analytic_line \
1096- WHERE account_id IN ("+','.join(map(str, ids))+") AND date>=%s AND date<=%s", (date1, date2))
1097+ WHERE account_id IN %s AND date>=%s AND date<=%s",
1098+ (tuple(ids), date1, date2))
1099 return self.cr.fetchone()[0] or 0.0
1100
1101 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)
1102
1103=== modified file 'account/project/report/quantity_cost_ledger.py'
1104--- account/project/report/quantity_cost_ledger.py 2009-10-09 11:49:00 +0000
1105+++ account/project/report/quantity_cost_ledger.py 2010-03-17 11:50:49 +0000
1106@@ -53,10 +53,9 @@
1107 WHERE (aal.account_id=%s) AND (aal.date>=%s) \
1108 AND (aal.date<=%s) AND (aal.general_account_id=aa.id) \
1109 AND aa.active \
1110- AND (aal.journal_id IN (" +
1111- ','.join(map(str, journal_ids)) + ")) \
1112+ AND (aal.journal_id IN %s) \
1113 GROUP BY aa.code, aa.name, aa.id ORDER BY aa.code",
1114- (account_id, date1, date2))
1115+ (account_id, date1, date2, tuple(journal_ids)))
1116 res = self.cr.dictfetchall()
1117 return res
1118
1119@@ -81,10 +80,10 @@
1120 account_analytic_journal AS aaj \
1121 WHERE (aal.general_account_id=%s) AND (aal.account_id=%s) \
1122 AND (aal.date>=%s) AND (aal.date<=%s) \
1123- AND (aal.journal_id=aaj.id) AND (aaj.id IN (" +
1124- ','.join(map(str, journal_ids)) + ")) \
1125+ AND (aal.journal_id=aaj.id) AND (aaj.id IN %s) \
1126 ORDER BY aal.date, aaj.code, aal.code",
1127- (general_account_id, account_id, date1, date2))
1128+ (general_account_id, account_id,
1129+ date1, date2, tuple(journal_ids)))
1130 res = self.cr.dictfetchall()
1131 return res
1132
1133@@ -99,9 +98,8 @@
1134 self.cr.execute("SELECT sum(unit_amount) \
1135 FROM account_analytic_line \
1136 WHERE account_id = %s AND date >= %s AND date <= %s \
1137- AND journal_id IN (" +
1138- ','.join(map(str, journal_ids)) + ")",
1139- (account_id, date1, date2))
1140+ AND journal_id IN %s",
1141+ (account_id, date1, date2, tuple(journal_ids)))
1142 return self.cr.fetchone()[0] or 0.0
1143
1144 def _sum_quantity(self, accounts, date1, date2, journals):
1145@@ -111,18 +109,15 @@
1146 if not journals or not journals[0][2]:
1147 self.cr.execute("SELECT sum(unit_amount) \
1148 FROM account_analytic_line \
1149- WHERE account_id IN (" +
1150- ','.join(map(str, ids)) + ") AND date>=%s AND date<=%s",
1151- (date1, date2))
1152+ WHERE account_id IN %s AND date>=%s AND date<=%s",
1153+ (tuple(ids), date1, date2))
1154 else:
1155 journal_ids = journals[0][2]
1156 self.cr.execute("SELECT sum(unit_amount) \
1157 FROM account_analytic_line \
1158- WHERE account_id IN (" +
1159- ','.join(map(str, ids)) + ") AND date >= %s AND date <= %s \
1160- AND journal_id IN (" +
1161- ','.join(map(str, journal_ids)) + ")",
1162- (date1, date2))
1163+ WHERE account_id IN %s AND date >= %s AND date <= %s \
1164+ AND journal_id IN %s",
1165+ (tuple(ids), date1, date2, tuple(journal_ids)))
1166 return self.cr.fetchone()[0] or 0.0
1167
1168 report_sxw.report_sxw('report.account.analytic.account.quantity_cost_ledger',
1169
1170=== modified file 'account/report/account_balance.py'
1171--- account/report/account_balance.py 2009-10-09 11:49:00 +0000
1172+++ account/report/account_balance.py 2010-03-17 11:50:49 +0000
1173@@ -104,10 +104,7 @@
1174 ctx['periods'] = form['periods'][0][2]
1175 ctx['date_from'] = form['date_from']
1176 ctx['date_to'] = form['date_to']
1177-# accounts = self.pool.get('account.account').browse(self.cr, self.uid, ids, ctx)
1178-# def cmp_code(x, y):
1179-# return cmp(x.code, y.code)
1180-# accounts.sort(cmp_code)
1181+
1182 child_ids = self.pool.get('account.account')._get_children_and_consol(self.cr, self.uid, ids, ctx)
1183 if child_ids:
1184 ids = child_ids
1185@@ -131,18 +128,7 @@
1186 }
1187 self.sum_debit += account['debit']
1188 self.sum_credit += account['credit']
1189-# if account.child_id:
1190-# def _check_rec(account):
1191-# if not account.child_id:
1192-# return bool(account.credit or account.debit)
1193-# for c in account.child_id:
1194-# if not _check_rec(c) or _check_rec(c):
1195-# return True
1196-# return False
1197-# if not _check_rec(account) :
1198-# continue
1199 if account['parent_id']:
1200-# acc = self.pool.get('account.account').read(self.cr, self.uid, [ account['parent_id'][0] ] ,['name'], ctx)
1201 for r in result_acc:
1202 if r['id'] == account['parent_id'][0]:
1203 res['level'] = r['level'] + 1
1204@@ -155,16 +141,6 @@
1205 result_acc.append(res)
1206 else:
1207 result_acc.append(res)
1208-# if account.child_id:
1209-# acc_id = [acc.id for acc in account.child_id]
1210-# lst_string = ''
1211-# lst_string = '\'' + '\',\''.join(map(str,acc_id)) + '\''
1212-# self.cr.execute("select code,id from account_account where id IN (%s)"%(lst_string))
1213-# a_id = self.cr.fetchall()
1214-# a_id.sort()
1215-# ids2 = [x[1] for x in a_id]
1216-#
1217-# result_acc += self.lines(form, ids2, done, level+1)
1218 return result_acc
1219
1220 def _sum_credit(self):
1221
1222=== modified file 'account/report/aged_trial_balance.py'
1223--- account/report/aged_trial_balance.py 2009-10-09 11:49:00 +0000
1224+++ account/report/aged_trial_balance.py 2010-03-17 11:50:49 +0000
1225@@ -1,7 +1,7 @@
1226 # -*- encoding: utf-8 -*-
1227 ##############################################################################
1228 #
1229-# OpenERP, Open Source Management Solution
1230+# OpenERP, Open Source Management Solution
1231 # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
1232 # $Id$
1233 #
1234@@ -21,207 +21,213 @@
1235 ##############################################################################
1236
1237 import time
1238+from operator import itemgetter
1239 import pooler
1240 import rml_parse
1241 from report import report_sxw
1242
1243 class aged_trial_report(rml_parse.rml_parse):
1244
1245- def __init__(self, cr, uid, name, context):
1246- super(aged_trial_report, self).__init__(cr, uid, name, context=context)
1247- self.line_query = ''
1248- self.total_account = []
1249-
1250-
1251- self.localcontext.update({
1252- 'time': time,
1253- 'get_lines': self._get_lines,
1254- 'get_total': self._get_total,
1255- 'get_direction': self._get_direction,
1256- 'get_for_period': self._get_for_period,
1257- 'get_company': self._get_company,
1258- 'get_currency': self._get_currency,
1259-
1260- })
1261-
1262-
1263- def _get_lines(self, form):
1264-
1265- if (form['result_selection'] == 'customer' ):
1266- self.ACCOUNT_TYPE = "('receivable')"
1267- elif (form['result_selection'] == 'supplier'):
1268- self.ACCOUNT_TYPE = "('payable')"
1269- else:
1270- self.ACCOUNT_TYPE = "('payable','receivable')"
1271-
1272-
1273- res = []
1274- account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
1275- self.line_query = account_move_line_obj._query_get(self.cr, self.uid, obj='line',
1276- context={'fiscalyear': form['fiscalyear']})
1277- self.cr.execute("""SELECT DISTINCT res_partner.id AS id,
1278- res_partner.name AS name
1279- FROM res_partner,account_move_line AS line, account_account
1280- WHERE (line.account_id=account_account.id)
1281- AND ((reconcile_id IS NULL)
1282- OR (reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > '%s' )))
1283- AND (line.partner_id=res_partner.id)
1284- AND (account_account.company_id = %s)
1285- ORDER BY res_partner.name""" % (form['date1'],form['company_id']))
1286- partners = self.cr.dictfetchall()
1287- ## mise a 0 du total
1288- for i in range(7):
1289- self.total_account.append(0)
1290- #
1291-
1292- # Build a string like (1,2,3) for easy use in SQL query
1293- partner_ids = '(' + ','.join( [str(x['id']) for x in partners] ) + ')'
1294-
1295- # This dictionary will store the debit-credit for all partners, using partner_id as key.
1296- totals = {}
1297- self.cr.execute("""SELECT partner_id, SUM(debit-credit)
1298- FROM account_move_line AS line, account_account
1299- WHERE (line.account_id = account_account.id)
1300- AND (account_account.type IN %s)
1301- AND (partner_id in %s)
1302- AND ((reconcile_id IS NULL)
1303- OR (reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > '%s' )))
1304- AND (account_account.company_id = %s)
1305- AND account_account.active
1306- GROUP BY partner_id""" % (self.ACCOUNT_TYPE, partner_ids,form['date1'],form['company_id']))
1307- t = self.cr.fetchall()
1308- for i in t:
1309- totals[i[0]] = i[1]
1310-
1311- # This dictionary will store the future or past of all partners
1312- future_past = {}
1313- if form['direction_selection'] == 'future':
1314- self.cr.execute("""SELECT partner_id, SUM(debit-credit)
1315- FROM account_move_line AS line, account_account
1316- WHERE (line.account_id=account_account.id)
1317- AND (account_account.type IN %s)
1318- AND (COALESCE(date_maturity,date) < '%s')
1319- AND (partner_id in %s)
1320- AND ((reconcile_id IS NULL)
1321- OR (reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > '%s' )))
1322- AND (account_account.company_id = %s)
1323- AND account_account.active
1324- GROUP BY partner_id"""% (self.ACCOUNT_TYPE, form['date1'], partner_ids,form['date1'], form['company_id']))
1325- t = self.cr.fetchall()
1326- for i in t:
1327- future_past[i[0]] = i[1]
1328- elif form['direction_selection'] == 'past': # Using elif so people could extend without this breaking
1329- self.cr.execute("""SELECT partner_id, SUM(debit-credit)
1330- FROM account_move_line AS line, account_account
1331- WHERE (line.account_id=account_account.id)
1332- AND (account_account.type IN %s)
1333- AND (COALESCE(date_maturity,date) > '%s')
1334- AND (partner_id in %s)
1335- AND ((reconcile_id IS NULL)
1336- OR (reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > '%s' )))
1337- AND (account_account.company_id = %s)
1338- AND account_account.active
1339- GROUP BY partner_id""" % (self.ACCOUNT_TYPE, form['date1'], partner_ids, form['date1'], form['company_id']))
1340- t = self.cr.fetchall()
1341- for i in t:
1342- future_past[i[0]] = i[1]
1343-
1344- # Use one query per period and store results in history (a list variable)
1345- # Each history will contain : history[1] = {'<partner_id>': <partner_debit-credit>}
1346- history = []
1347- for i in range(5):
1348- self.cr.execute("""SELECT partner_id, SUM(debit-credit)
1349- FROM account_move_line AS line, account_account
1350- WHERE (line.account_id=account_account.id)
1351- AND (account_account.type IN %s)
1352- AND (COALESCE(date_maturity,date) BETWEEN '%s' AND '%s')
1353- AND (partner_id in %s )
1354- AND ((reconcile_id IS NULL)
1355- OR (reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > '%s' )))
1356- AND (account_account.company_id = %s)
1357- AND account_account.active
1358- GROUP BY partner_id""" % (self.ACCOUNT_TYPE, form[str(i)]['start'], form[str(i)]['stop'],partner_ids ,form['date1'] ,form['company_id']))
1359-
1360- t = self.cr.fetchall()
1361- d = {}
1362- for i in t:
1363- d[i[0]] = i[1]
1364- history.append(d)
1365-
1366- for partner in partners:
1367- values = {}
1368- ## If choise selection is in the future
1369- if form['direction_selection'] == 'future':
1370- # Query here is replaced by one query which gets the all the partners their 'before' value
1371- before = False
1372- if future_past.has_key(partner['id']):
1373- before = [ future_past[partner['id']] ]
1374-
1375- self.total_account[6] = self.total_account[6] + (before and before[0] or 0.0)
1376-
1377- values['direction'] = before and before[0] or 0.0
1378- elif form['direction_selection'] == 'past': # Changed this so people could in the future create new direction_selections
1379- # Query here is replaced by one query which gets the all the partners their 'after' value
1380- after = False
1381- if future_past.has_key(partner['id']): # Making sure this partner actually was found by the query
1382- after = [ future_past[partner['id']] ]
1383-
1384- self.total_account[6] = self.total_account[6] + (after and after[0] or 0.0)
1385- values['direction'] = after and after[0] or ""
1386-
1387- for i in range(5):
1388- during = False
1389- if history[i].has_key(partner['id']):
1390- during = [ history[i][partner['id']] ]
1391- # Ajout du compteur
1392- self.total_account[(i)] = self.total_account[(i)] + (during and during[0] or 0)
1393- values[str(i)] = during and during[0] or ""
1394-
1395- total = False
1396- if totals.has_key( partner['id'] ):
1397- total = [ totals[partner['id']] ]
1398- values['total'] = total and total[0] or 0.0
1399- ## Add for total
1400- self.total_account[(i+1)] = self.total_account[(i+1)] + (total and total[0] or 0.0)
1401- values['name'] = partner['name']
1402- #t = 0.0
1403- #for i in range(5)+['direction']:
1404- # t+= float(values.get(str(i), 0.0) or 0.0)
1405- #values['total'] = t
1406-
1407- if values['total']:
1408- res.append(values)
1409-
1410- total = 0.0
1411- totals = {}
1412- for r in res:
1413- total += float(r['total'] or 0.0)
1414- for i in range(5)+['direction']:
1415- totals.setdefault(str(i), 0.0)
1416- totals[str(i)] += float(r[str(i)] or 0.0)
1417- return res
1418-
1419- def _get_total(self,pos):
1420- period = self.total_account[int(pos)]
1421- return period
1422-
1423- def _get_direction(self,pos):
1424- period = self.total_account[int(pos)]
1425- return period
1426-
1427- def _get_for_period(self,pos):
1428- period = self.total_account[int(pos)]
1429- return period
1430-
1431- def _get_company(self, form):
1432- return pooler.get_pool(self.cr.dbname).get('res.company').browse(self.cr, self.uid, form['company_id']).name
1433-
1434- def _get_currency(self, form):
1435- return pooler.get_pool(self.cr.dbname).get('res.company').browse(self.cr, self.uid, form['company_id']).currency_id.name
1436+ def __init__(self, cr, uid, name, context):
1437+ super(aged_trial_report, self).__init__(cr, uid, name, context=context)
1438+ self.line_query = ''
1439+ self.total_account = []
1440+
1441+
1442+ self.localcontext.update({
1443+ 'time': time,
1444+ 'get_lines': self._get_lines,
1445+ 'get_total': self._get_total,
1446+ 'get_direction': self._get_direction,
1447+ 'get_for_period': self._get_for_period,
1448+ 'get_company': self._get_company,
1449+ 'get_currency': self._get_currency,
1450+
1451+ })
1452+
1453+
1454+ def _get_lines(self, form):
1455+
1456+ if (form['result_selection'] == 'customer' ):
1457+ self.ACCOUNT_TYPE = "('receivable')"
1458+ elif (form['result_selection'] == 'supplier'):
1459+ self.ACCOUNT_TYPE = "('payable')"
1460+ else:
1461+ self.ACCOUNT_TYPE = "('payable','receivable')"
1462+
1463+
1464+ res = []
1465+ account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
1466+ self.line_query = account_move_line_obj._query_get(self.cr, self.uid, obj='line',
1467+ context={'fiscalyear': form['fiscalyear']})
1468+ self.cr.execute("""SELECT DISTINCT res_partner.id AS id,
1469+ res_partner.name AS name
1470+ FROM res_partner,account_move_line AS line, account_account
1471+ WHERE (line.account_id=account_account.id)
1472+ AND ((reconcile_id IS NULL)
1473+ OR (reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > '%s' )))
1474+ AND (line.partner_id=res_partner.id)
1475+ AND (account_account.company_id = %s)
1476+ ORDER BY res_partner.name""" % (form['date1'],form['company_id']))
1477+ partners = self.cr.dictfetchall()
1478+ ## mise a 0 du total
1479+ for i in range(7):
1480+ self.total_account.append(0)
1481+
1482+ partner_ids = tuple(map(attrgetter('id'), partners))
1483+ # This dictionary will store the debit-credit for all partners, using partner_id as key.
1484+ totals = {}
1485+ self.cr.execute("""SELECT partner_id, SUM(debit-credit)
1486+ FROM account_move_line AS line, account_account
1487+ WHERE (line.account_id = account_account.id)
1488+ AND (account_account.type IN %s)
1489+ AND (partner_id in %s)
1490+ AND ((reconcile_id IS NULL)
1491+ OR (reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > %s )))
1492+ AND (account_account.company_id = %s)
1493+ AND account_account.active
1494+ GROUP BY partner_id""" , (
1495+ self.ACCOUNT_TYPE, partner_ids,
1496+ form['date1'],form['company_id']))
1497+ t = self.cr.fetchall()
1498+ for i in t:
1499+ totals[i[0]] = i[1]
1500+
1501+ # This dictionary will store the future or past of all partners
1502+ future_past = {}
1503+ if form['direction_selection'] == 'future':
1504+ self.cr.execute("""SELECT partner_id, SUM(debit-credit)
1505+ FROM account_move_line AS line, account_account
1506+ WHERE (line.account_id=account_account.id)
1507+ AND (account_account.type IN %s)
1508+ AND (COALESCE(date_maturity,date) < %s)
1509+ AND (partner_id in %s)
1510+ AND ((reconcile_id IS NULL)
1511+ OR (reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > %s )))
1512+ AND (account_account.company_id = %s)
1513+ AND account_account.active
1514+ GROUP BY partner_id""", (
1515+ self.ACCOUNT_TYPE, form['date1'], partner_ids,
1516+ form['date1'], form['company_id']))
1517+ t = self.cr.fetchall()
1518+ for i in t:
1519+ future_past[i[0]] = i[1]
1520+ elif form['direction_selection'] == 'past': # Using elif so people could extend without this breaking
1521+ self.cr.execute("""SELECT partner_id, SUM(debit-credit)
1522+ FROM account_move_line AS line, account_account
1523+ WHERE (line.account_id=account_account.id)
1524+ AND (account_account.type IN %s)
1525+ AND (COALESCE(date_maturity,date) > %s)
1526+ AND (partner_id in %s)
1527+ AND ((reconcile_id IS NULL)
1528+ OR (reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > %s )))
1529+ AND (account_account.company_id = %s)
1530+ AND account_account.active
1531+ GROUP BY partner_id""" , (
1532+ self.ACCOUNT_TYPE, form['date1'], partner_ids,
1533+ form['date1'], form['company_id']))
1534+ t = self.cr.fetchall()
1535+ for i in t:
1536+ future_past[i[0]] = i[1]
1537+
1538+ # Use one query per period and store results in history (a list variable)
1539+ # Each history will contain : history[1] = {'<partner_id>': <partner_debit-credit>}
1540+ history = []
1541+ for i in range(5):
1542+ self.cr.execute("""SELECT partner_id, SUM(debit-credit)
1543+ FROM account_move_line AS line, account_account
1544+ WHERE (line.account_id=account_account.id)
1545+ AND (account_account.type IN %s)
1546+ AND (COALESCE(date_maturity,date) BETWEEN %s AND %s)
1547+ AND (partner_id in %s )
1548+ AND ((reconcile_id IS NULL)
1549+ OR (reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > %s )))
1550+ AND (account_account.company_id = %s)
1551+ AND account_account.active
1552+ GROUP BY partner_id""" , (
1553+ self.ACCOUNT_TYPE, form[str(i)]['start'], form[str(i)]['stop'],
1554+ partner_ids ,form['date1'] ,form['company_id']))
1555+
1556+ t = self.cr.fetchall()
1557+ d = {}
1558+ for i in t:
1559+ d[i[0]] = i[1]
1560+ history.append(d)
1561+
1562+ for partner in partners:
1563+ values = {}
1564+ ## If choise selection is in the future
1565+ if form['direction_selection'] == 'future':
1566+ # Query here is replaced by one query which gets the all the partners their 'before' value
1567+ before = False
1568+ if future_past.has_key(partner['id']):
1569+ before = [ future_past[partner['id']] ]
1570+
1571+ self.total_account[6] = self.total_account[6] + (before and before[0] or 0.0)
1572+
1573+ values['direction'] = before and before[0] or 0.0
1574+ elif form['direction_selection'] == 'past': # Changed this so people could in the future create new direction_selections
1575+ # Query here is replaced by one query which gets the all the partners their 'after' value
1576+ after = False
1577+ if future_past.has_key(partner['id']): # Making sure this partner actually was found by the query
1578+ after = [ future_past[partner['id']] ]
1579+
1580+ self.total_account[6] = self.total_account[6] + (after and after[0] or 0.0)
1581+ values['direction'] = after and after[0] or ""
1582+
1583+ for i in range(5):
1584+ during = False
1585+ if history[i].has_key(partner['id']):
1586+ during = [ history[i][partner['id']] ]
1587+ # Ajout du compteur
1588+ self.total_account[(i)] = self.total_account[(i)] + (during and during[0] or 0)
1589+ values[str(i)] = during and during[0] or ""
1590+
1591+ total = False
1592+ if totals.has_key( partner['id'] ):
1593+ total = [ totals[partner['id']] ]
1594+ values['total'] = total and total[0] or 0.0
1595+ ## Add for total
1596+ self.total_account[(i+1)] = self.total_account[(i+1)] + (total and total[0] or 0.0)
1597+ values['name'] = partner['name']
1598+ #t = 0.0
1599+ #for i in range(5)+['direction']:
1600+ # t+= float(values.get(str(i), 0.0) or 0.0)
1601+ #values['total'] = t
1602+
1603+ if values['total']:
1604+ res.append(values)
1605+
1606+ total = 0.0
1607+ totals = {}
1608+ for r in res:
1609+ total += float(r['total'] or 0.0)
1610+ for i in range(5)+['direction']:
1611+ totals.setdefault(str(i), 0.0)
1612+ totals[str(i)] += float(r[str(i)] or 0.0)
1613+ return res
1614+
1615+ def _get_total(self,pos):
1616+ period = self.total_account[int(pos)]
1617+ return period
1618+
1619+ def _get_direction(self,pos):
1620+ period = self.total_account[int(pos)]
1621+ return period
1622+
1623+ def _get_for_period(self,pos):
1624+ period = self.total_account[int(pos)]
1625+ return period
1626+
1627+ def _get_company(self, form):
1628+ return pooler.get_pool(self.cr.dbname).get('res.company').browse(self.cr, self.uid, form['company_id']).name
1629+
1630+ def _get_currency(self, form):
1631+ return pooler.get_pool(self.cr.dbname).get('res.company').browse(self.cr, self.uid, form['company_id']).currency_id.name
1632
1633
1634 report_sxw.report_sxw('report.account.aged_trial_balance', 'res.partner',
1635- 'addons/account/report/aged_trial_balance.rml',parser=aged_trial_report,header=False)
1636+ 'addons/account/report/aged_trial_balance.rml',parser=aged_trial_report,header=False)
1637
1638
1639 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
1640
1641=== modified file 'account/report/general_journal.py'
1642--- account/report/general_journal.py 2009-10-09 11:49:00 +0000
1643+++ account/report/general_journal.py 2010-03-17 11:50:49 +0000
1644@@ -19,7 +19,7 @@
1645 # along with this program. If not, see <http://www.gnu.org/licenses/>.
1646 #
1647 ##############################################################################
1648-
1649+from operator import itemgetter
1650 import pooler
1651 import time
1652 from report import report_sxw
1653@@ -42,10 +42,12 @@
1654
1655 def set_context(self, objects, data, ids, report_type = None):
1656 super(journal_print, self).set_context(objects, data, ids, report_type)
1657- self.cr.execute('select period_id, journal_id from account_journal_period where id in (' + ','.join([str(id) for id in ids]) + ')')
1658+ self.cr.execute('SELECT period_id, journal_id '
1659+ 'FROM account_journal_period '
1660+ 'WHERE id IN %s',
1661+ (tuple(ids),))
1662 res = self.cr.fetchall()
1663- self.period_ids = ','.join([str(x[0]) for x in res])
1664- self.journal_ids = ','.join([str(x[1]) for x in res])
1665+ self.period_ids, self.journal_ids = zip(*res)
1666
1667 # returns a list of period objs
1668 def periods(self, journal_period_objs):
1669@@ -75,7 +77,14 @@
1670 periods.append(data.period_id.id)
1671 for period in periods:
1672 period_data = self.pool.get('account.period').browse(self.cr, self.uid, period)
1673- 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,))
1674+ self.cr.execute(
1675+ 'SELECT j.code, j.name, '
1676+ 'SUM(l.debit) AS debit, SUM(l.credit) AS credit '
1677+ 'FROM account_move_line l '
1678+ 'LEFT JOIN account_journal j ON (l.journal_id=j.id) '
1679+ 'WHERE period_id=%s AND journal_id IN %s '
1680+ 'AND l.state<>\'draft\' '
1681+ 'GROUP BY j.id, j.code, j.name', (period, tuple(journal_id)))
1682 res = self.cr.dictfetchall()
1683 res[0].update({'period_name':period_data.name})
1684 res[0].update({'pid':period})
1685@@ -83,45 +92,59 @@
1686 return lines_data
1687 if not self.journal_ids:
1688 return []
1689- 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,))
1690+ self.cr.execute('SELECT j.code, j.name, '
1691+ 'SUM(l.debit) AS debit, SUM(l.credit) AS credit '
1692+ 'FROM account_move_line l '
1693+ 'LEFT JOIN account_journal j ON (l.journal_id=j.id) '
1694+ 'WHERE period_id=%s AND journal_id IN %s '
1695+ 'AND l.state<>\'draft\' '
1696+ 'GROUP BY j.id, j.code, j.name'
1697+ (period_id,tuple(self.journal_ids)))
1698 res = self.cr.dictfetchall()
1699 return res
1700
1701 def _sum_debit_period(self, period_id,journal_id=None):
1702- if type(journal_id)==type([]):
1703- 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,))
1704- return self.cr.fetchone()[0] or 0.0
1705- if not self.journal_ids:
1706+ journals = journal_id or self.journal_ids
1707+ if not journals:
1708 return 0.0
1709- 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,))
1710-
1711+ self.cr.execute('SELECT SUM(debit) FROM account_move_line '
1712+ 'WHERE period_id=%s AND journal_id IN %s '
1713+ 'AND state<>\'draft\'',
1714+ (period_id, tuple(journals)))
1715 return self.cr.fetchone()[0] or 0.0
1716
1717 def _sum_credit_period(self, period_id,journal_id=None):
1718- if type(journal_id)==type([]):
1719- 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,))
1720- return self.cr.fetchone()[0] or 0.0
1721- if not self.journal_ids:
1722+ journals = journal_id or self.journal_ids
1723+ if not journals:
1724 return 0.0
1725- 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,))
1726+ self.cr.execute('SELECT SUM(credit) FROM account_move_line '
1727+ 'WHERE period_id=%s AND journal_id IN %s '
1728+ 'AND state<>\'draft\'',
1729+ (period_id,tuple(journals)))
1730 return self.cr.fetchone()[0] or 0.0
1731
1732 def _sum_debit(self,period_id=None,journal_id=None):
1733- if type(period_id)==type([]):
1734- 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\'')
1735- return self.cr.fetchone()[0] or 0.0
1736- if not self.journal_ids or not self.period_ids:
1737+ journals = journal_id or self.journal_ids
1738+ periods = period_id or self.period_ids
1739+ if not (journals and periods):
1740 return 0.0
1741- 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\'')
1742+ self.cr.execute('SELECT SUM(debit) FROM account_move_line '
1743+ 'WHERE period_id IN %s '
1744+ 'AND journal_id IN %s '
1745+ 'AND state<>\'draft\'',
1746+ (tuple(periods), tuple(journals)))
1747 return self.cr.fetchone()[0] or 0.0
1748
1749 def _sum_credit(self,period_id=None,journal_id=None):
1750- if type(period_id)==type([]):
1751- 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\'')
1752- return self.cr.fetchone()[0] or 0.0
1753- if not self.journal_ids or not self.period_ids:
1754+ periods = period_id or self.period_ids
1755+ journals = journal_id or self.journal_ids
1756+ if not (periods and journals):
1757 return 0.0
1758- 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\'')
1759+ self.cr.execute('SELECT SUM(credit) FROM account_move_line '
1760+ 'WHERE period_id IN %s '
1761+ 'AND journal_id IN %s '
1762+ 'AND state<>\'draft\'',
1763+ (tuple(periods), tuple(journals)))
1764 return self.cr.fetchone()[0] or 0.0
1765 report_sxw.report_sxw('report.account.general.journal', 'account.journal.period', 'addons/account/report/general_journal.rml',parser=journal_print)
1766 report_sxw.report_sxw('report.account.general.journal.wiz', 'account.journal.period', 'addons/account/report/wizard_general_journal.rml',parser=journal_print, header=False)
1767
1768=== modified file 'account/report/general_ledger.py'
1769--- account/report/general_ledger.py 2010-01-18 07:47:33 +0000
1770+++ account/report/general_ledger.py 2010-03-17 11:50:49 +0000
1771@@ -123,14 +123,15 @@
1772 periods = form['periods'][0][2]
1773 if not periods:
1774 sql = """
1775- 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']) + """
1776+ 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
1777 """
1778+ sqlargs = (form['fiscalyear'],)
1779 else:
1780- periods_id = ','.join(map(str, periods))
1781 sql = """
1782- 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 + """)
1783+ Select min(p.date_start) as start_date,max(p.date_stop) as stop_date from account_period as p where p.id in %s
1784 """
1785- self.cr.execute(sql)
1786+ sqlargs = (tuple(periods),)
1787+ self.cr.execute(sql, sqlargs)
1788 res = self.cr.dictfetchall()
1789 borne_min = res[0]['start_date']
1790 borne_max = res[0]['stop_date']
1791@@ -141,14 +142,21 @@
1792 periods = form['periods'][0][2]
1793 if not periods:
1794 sql = """
1795- 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']) + """
1796+ SELECT MIN(p.date_start) AS start_date,
1797+ MAX(p.date_stop) AS stop_date
1798+ FROM account_period AS p
1799+ WHERE p.fiscalyear_id = %s
1800 """
1801+ sqlargs = (form['fiscalyear'],)
1802 else:
1803- periods_id = ','.join(map(str, periods))
1804 sql = """
1805- 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 + """)
1806+ SELECT MIN(p.date_start) AS start_date,
1807+ MAX(p.date_stop) AS stop_date
1808+ FROM account_period AS p
1809+ WHERE p.id IN %s
1810 """
1811- self.cr.execute(sql)
1812+ sqlargs = (tuple(periods),)
1813+ self.cr.execute(sql, sqlargs)
1814 res = self.cr.dictfetchall()
1815 period_min = res[0]['start_date']
1816 period_max = res[0]['stop_date']
1817@@ -232,8 +240,12 @@
1818 else:
1819 ## We will now compute solde initiaux
1820 for move in res:
1821- 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'] + "'"
1822- self.cr.execute(SOLDEINIT)
1823+ SOLDEINIT = "SELECT SUM(l.debit) AS sum_debit,"\
1824+ " SUM(l.credit) AS sum_credit "\
1825+ "FROM account_move_line l "\
1826+ "WHERE l.account_id = %s "\
1827+ "AND l.date < %s AND l.date > %s"
1828+ self.cr.execute(SOLDEINIT, (move.id, self.borne_date['max_date'],self.borne_date['min_date']))
1829 resultat = self.cr.dictfetchall()
1830 if resultat[0] :
1831 if resultat[0]['sum_debit'] == None:
1832@@ -354,7 +366,8 @@
1833 return 0.0
1834 self.cr.execute("SELECT sum(debit) "\
1835 "FROM account_move_line l "\
1836- "WHERE l.account_id in ("+','.join(map(str, self.child_ids))+") AND "+self.query)
1837+ "WHERE l.account_id in %s AND "+self.query,
1838+ (tuple(self.child_ids),))
1839 sum_debit = self.cr.fetchone()[0] or 0.0
1840 return sum_debit
1841
1842@@ -363,7 +376,8 @@
1843 return 0.0
1844 self.cr.execute("SELECT sum(credit) "\
1845 "FROM account_move_line l "\
1846- "WHERE l.account_id in ("+','.join(map(str, self.child_ids))+") AND "+self.query)
1847+ "WHERE l.account_id in %s AND "+self.query,
1848+ (tuple(self.child_ids),))
1849 ## Add solde init to the result
1850 #
1851 sum_credit = self.cr.fetchone()[0] or 0.0
1852@@ -374,7 +388,8 @@
1853 return 0.0
1854 self.cr.execute("SELECT (sum(debit) - sum(credit)) as tot_solde "\
1855 "FROM account_move_line l "\
1856- "WHERE l.account_id in ("+','.join(map(str, self.child_ids))+") AND "+self.query)
1857+ "WHERE l.account_id in %s AND "+self.query,
1858+ (tuple(self.child_ids),))
1859 sum_solde = self.cr.fetchone()[0] or 0.0
1860 return sum_solde
1861
1862
1863=== modified file 'account/report/general_ledger_landscape.py'
1864--- account/report/general_ledger_landscape.py 2010-01-18 07:47:33 +0000
1865+++ account/report/general_ledger_landscape.py 2010-03-17 11:50:49 +0000
1866@@ -122,14 +122,15 @@
1867 periods = form['periods'][0][2]
1868 if not periods:
1869 sql = """
1870- 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']) + """
1871+ 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
1872 """
1873+ sqlargs = (form['fiscalyear'],)
1874 else:
1875- periods_id = ','.join(map(str, periods))
1876 sql = """
1877- 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 + """)
1878+ Select min(p.date_start) as start_date,max(p.date_stop) as stop_date from account_period as p where p.id in %s
1879 """
1880- self.cr.execute(sql)
1881+ sqlargs = (tuple(periods),)
1882+ self.cr.execute(sql, sqlargs)
1883 res = self.cr.dictfetchall()
1884 borne_min = res[0]['start_date']
1885 borne_max = res[0]['stop_date']
1886@@ -140,14 +141,15 @@
1887 periods = form['periods'][0][2]
1888 if not periods:
1889 sql = """
1890- 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']) + """
1891+ 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
1892 """
1893+ sqlargs = (form['fiscalyear'],)
1894 else:
1895- periods_id = ','.join(map(str, periods))
1896 sql = """
1897- 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 + """)
1898+ Select min(p.date_start) as start_date,max(p.date_stop) as stop_date from account_period as p where p.id in %s
1899 """
1900- self.cr.execute(sql)
1901+ sqlargs = (tuple(periods),)
1902+ self.cr.execute(sql, sqlargs)
1903 res = self.cr.dictfetchall()
1904 period_min = res[0]['start_date']
1905 period_max = res[0]['stop_date']
1906@@ -233,8 +235,8 @@
1907 else:
1908 ## We will now compute solde initiaux
1909 for move in res:
1910- 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'] + "'"
1911- self.cr.execute(SOLDEINIT)
1912+ SOLDEINIT = "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"
1913+ self.cr.execute(SOLDEINIT, (move.id, self.borne_date['max_date'], self.borne_date['min_date']))
1914 resultat = self.cr.dictfetchall()
1915 if resultat[0] :
1916 if resultat[0]['sum_debit'] == None:
1917@@ -287,7 +289,7 @@
1918 for l in res:
1919 line = self.pool.get('account.move.line').browse(self.cr, self.uid, l['id'])
1920 l['move'] = line.move_id.name
1921- self.cr.execute('Select id from account_invoice where move_id =%s'%(line.move_id.id))
1922+ self.cr.execute('Select id from account_invoice where move_id =%s',(line.move_id.id,))
1923 tmpres = self.cr.dictfetchall()
1924 if len(tmpres) > 0 :
1925 inv = self.pool.get('account.invoice').browse(self.cr, self.uid, tmpres[0]['id'])
1926@@ -355,7 +357,8 @@
1927 return 0.0
1928 self.cr.execute("SELECT sum(debit) "\
1929 "FROM account_move_line l "\
1930- "WHERE l.account_id in ("+','.join(map(str, self.child_ids))+") AND "+self.query)
1931+ "WHERE l.account_id in %s AND "+self.query,
1932+ (tuple(self.child_ids),))
1933 sum_debit = self.cr.fetchone()[0] or 0.0
1934 return sum_debit
1935
1936@@ -364,7 +367,8 @@
1937 return 0.0
1938 self.cr.execute("SELECT sum(credit) "\
1939 "FROM account_move_line l "\
1940- "WHERE l.account_id in ("+','.join(map(str, self.child_ids))+") AND "+self.query)
1941+ "WHERE l.account_id in %s AND "+self.query,
1942+ (tuple(self.child_ids),))
1943 ## Add solde init to the result
1944 #
1945 sum_credit = self.cr.fetchone()[0] or 0.0
1946@@ -375,7 +379,8 @@
1947 return 0.0
1948 self.cr.execute("SELECT (sum(debit) - sum(credit)) as tot_solde "\
1949 "FROM account_move_line l "\
1950- "WHERE l.account_id in ("+','.join(map(str, self.child_ids))+") AND "+self.query)
1951+ "WHERE l.account_id in %s AND "+self.query,
1952+ (tuple(self.child_ids),))
1953 sum_solde = self.cr.fetchone()[0] or 0.0
1954 return sum_solde
1955
1956
1957=== modified file 'account/report/partner_balance.py'
1958--- account/report/partner_balance.py 2009-10-09 11:49:00 +0000
1959+++ account/report/partner_balance.py 2010-03-17 11:50:49 +0000
1960@@ -30,7 +30,6 @@
1961 def __init__(self, cr, uid, name, context):
1962 super(partner_balance, self).__init__(cr, uid, name, context=context)
1963 self.date_lst = []
1964- self.date_lst_string = ''
1965 self.account_ids = ''
1966 self.localcontext.update( {
1967 'time': time,
1968@@ -164,29 +163,23 @@
1969
1970 self.transform_both_into_date_array(data)
1971
1972- ##
1973- self.date_lst_string =''
1974- if self.date_lst:
1975- self.date_lst_string = '\'' + '\',\''.join(map(str,self.date_lst)) + '\''
1976-
1977-
1978 ## Compute Code
1979 account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
1980 #
1981 if (data['form']['result_selection'] == 'customer' ):
1982- self.ACCOUNT_TYPE = "('receivable')"
1983+ self.ACCOUNT_TYPE = ('receivable',)
1984 elif (data['form']['result_selection'] == 'supplier'):
1985- self.ACCOUNT_TYPE = "('payable')"
1986+ self.ACCOUNT_TYPE = ('payable',)
1987 else:
1988- self.ACCOUNT_TYPE = "('payable','receivable')"
1989+ self.ACCOUNT_TYPE = ('payable','receivable')
1990 #
1991 self.cr.execute("SELECT a.id " \
1992 "FROM account_account a " \
1993 "LEFT JOIN account_account_type t " \
1994 "ON (a.type = t.code) " \
1995 "WHERE a.company_id = %s " \
1996- "AND a.type IN " + self.ACCOUNT_TYPE + " " \
1997- "AND a.active", (data['form']['company_id'],))
1998+ "AND a.type IN %s " \
1999+ "AND a.active", (data['form']['company_id'],self.ACCOUNT_TYPE))
2000 self.account_ids = ','.join([str(a) for (a,) in self.cr.fetchall()])
2001
2002 super(partner_balance, self).set_context(objects, data, ids, report_type)
2003@@ -196,7 +189,7 @@
2004 account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
2005 full_account = []
2006 result_tmp = 0.0
2007- if self.date_lst_string:
2008+ if self.date_lst:
2009 self.cr.execute(
2010 "SELECT p.ref,l.account_id,ac.name as account_name,ac.code as code ,p.name, sum(debit) as debit, sum(credit) as credit, " \
2011 "CASE WHEN sum(debit) > sum(credit) " \
2012@@ -210,16 +203,17 @@
2013 "(SELECT sum(debit-credit) " \
2014 "FROM account_move_line l " \
2015 "WHERE partner_id = p.id " \
2016- "AND l.date IN (" + self.date_lst_string + ") " \
2017+ "AND l.date IN %s " \
2018 "AND blocked = TRUE " \
2019 ") AS enlitige " \
2020 "FROM account_move_line l LEFT JOIN res_partner p ON (l.partner_id=p.id) " \
2021 "JOIN account_account ac ON (l.account_id = ac.id)" \
2022- "WHERE ac.type IN " + self.ACCOUNT_TYPE + " " \
2023- "AND l.date IN (" + self.date_lst_string + ") " \
2024- "AND ac.company_id = "+ str(data['form']['company_id']) +" " \
2025+ "WHERE ac.type IN %s " \
2026+ "AND l.date IN %s " \
2027+ "AND ac.company_id = %s " \
2028 "GROUP BY p.id, p.ref, p.name,l.account_id,ac.name,ac.code " \
2029- "ORDER BY l.account_id,p.name")
2030+ "ORDER BY l.account_id,p.name",
2031+ (tuple(self.date_lst), self.ACCOUNT_TYPE, tuple(self.date_lst), data['form']['company_id']))
2032 res = self.cr.dictfetchall()
2033 for r in res:
2034 full_account.append(r)
2035@@ -352,12 +346,13 @@
2036 account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
2037 result_tmp = 0.0
2038 temp_res = 0.0
2039- if self.date_lst_string:
2040+ if self.date_lst:
2041 self.cr.execute(
2042 "SELECT sum(debit) " \
2043 "FROM account_move_line AS l " \
2044 "WHERE l.account_id IN (" + self.account_ids + ") " \
2045- "AND l.date IN (" + self.date_lst_string + ") " )
2046+ "AND l.date IN %s",
2047+ (tuple(self.date_lst),))
2048 temp_res = float(self.cr.fetchone()[0] or 0.0)
2049 result_tmp = result_tmp + temp_res
2050
2051@@ -370,12 +365,13 @@
2052
2053 result_tmp = 0.0
2054 temp_res = 0.0
2055- if self.date_lst_string:
2056+ if self.date_lst:
2057 self.cr.execute(
2058 "SELECT sum(credit) " \
2059 "FROM account_move_line AS l " \
2060 "WHERE l.account_id IN (" + self.account_ids + ") " \
2061- "AND l.date IN (" + self.date_lst_string + ") " )
2062+ "AND l.date IN %s",
2063+ (tuple(self.date_lst),))
2064 temp_res = float(self.cr.fetchone()[0] or 0.0)
2065 result_tmp = result_tmp + temp_res
2066
2067@@ -387,13 +383,14 @@
2068 account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
2069 result_tmp = 0.0
2070 temp_res = 0.0
2071- if self.date_lst_string:
2072+ if self.date_lst:
2073 self.cr.execute(
2074 "SELECT sum(debit-credit) " \
2075 "FROM account_move_line AS l " \
2076 "WHERE l.account_id IN (" + self.account_ids + ") " \
2077- "AND l.date IN (" + self.date_lst_string + ") " \
2078- "AND l.blocked=TRUE " )
2079+ "AND l.date IN %s " \
2080+ "AND l.blocked=TRUE ",
2081+ (tuple(self.date_lst),))
2082 temp_res = float(self.cr.fetchone()[0] or 0.0)
2083 result_tmp = result_tmp + temp_res
2084
2085@@ -405,7 +402,7 @@
2086 account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
2087 result_tmp = 0.0
2088 a = 0.0
2089- if self.date_lst_string:
2090+ if self.date_lst:
2091 self.cr.execute(
2092 "SELECT CASE WHEN sum(debit) > sum(credit) " \
2093 "THEN sum(debit) - sum(credit) " \
2094@@ -413,8 +410,9 @@
2095 "END " \
2096 "FROM account_move_line AS l " \
2097 "WHERE l.account_id IN (" + self.account_ids + ") " \
2098- "AND l.date IN (" + self.date_lst_string + ") " \
2099- "GROUP BY l.partner_id")
2100+ "AND l.date IN %s " \
2101+ "GROUP BY l.partner_id",
2102+ (tuple(self.date_lst),))
2103 a = self.cr.fetchone()[0]
2104
2105 if self.cr.fetchone() != None:
2106@@ -432,7 +430,7 @@
2107
2108 result_tmp = 0.0
2109 a = 0.0
2110- if self.date_lst_string:
2111+ if self.date_lst:
2112 self.cr.execute(
2113 "SELECT CASE WHEN sum(debit) < sum(credit) " \
2114 "THEN sum(credit) - sum(debit) " \
2115@@ -440,8 +438,9 @@
2116 "END " \
2117 "FROM account_move_line AS l " \
2118 "WHERE l.account_id IN (" + self.account_ids + ") " \
2119- "AND l.date IN (" + self.date_lst_string + ") " \
2120- "GROUP BY l.partner_id")
2121+ "AND l.date IN %s " \
2122+ "GROUP BY l.partner_id",
2123+ (tuple(self.date_lst),))
2124 a = self.cr.fetchone()[0] or 0.0
2125
2126 if self.cr.fetchone() != None:
2127
2128=== modified file 'account/report/tax_report.py'
2129--- account/report/tax_report.py 2009-10-09 11:49:00 +0000
2130+++ account/report/tax_report.py 2010-03-17 11:50:49 +0000
2131@@ -90,7 +90,7 @@
2132
2133 def _get_general(self, tax_code_id,period_list ,company_id, based_on):
2134 res=[]
2135- period_sql_list = ','.join(map(str, period_list[0][2]))
2136+ periods_ids = tuple(period_list[0][2])
2137 if based_on == 'payments':
2138 self.cr.execute('SELECT SUM(line.tax_amount) AS tax_amount, \
2139 SUM(line.debit) AS debit, \
2140@@ -109,11 +109,11 @@
2141 AND line.account_id = account.id \
2142 AND account.company_id = %s \
2143 AND move.id = line.move_id \
2144- AND line.period_id IN ('+ period_sql_list +') \
2145+ AND line.period_id IN %s \
2146 AND ((invoice.state = %s) \
2147 OR (invoice.id IS NULL)) \
2148- GROUP BY account.id,account.name,account.code', ('draft',tax_code_id,
2149- company_id, 'paid'))
2150+ GROUP BY account.id,account.name,account.code',
2151+ ('draft',tax_code_id,company_id,periods_ids,'paid'))
2152
2153 else :
2154 self.cr.execute('SELECT SUM(line.tax_amount) AS tax_amount, \
2155@@ -129,10 +129,10 @@
2156 AND line.tax_code_id = %s \
2157 AND line.account_id = account.id \
2158 AND account.company_id = %s \
2159- AND line.period_id IN ('+ period_sql_list +') \
2160+ AND line.period_id IN %s \
2161 AND account.active \
2162- GROUP BY account.id,account.name,account.code', ('draft',tax_code_id,
2163- company_id))
2164+ GROUP BY account.id,account.name,account.code',
2165+ ('draft',tax_code_id,company_id,periods_ids))
2166 res = self.cr.dictfetchall()
2167
2168 #AND line.period_id IN ('+ period_sql_list +') \
2169
2170=== modified file 'account/wizard/wizard_account_balance_report.py'
2171--- account/wizard/wizard_account_balance_report.py 2009-09-07 07:09:31 +0000
2172+++ account/wizard/wizard_account_balance_report.py 2010-03-17 11:50:49 +0000
2173@@ -112,8 +112,8 @@
2174
2175 def _check_date(self, cr, uid, data, context):
2176 sql = """
2177- 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'])
2178- cr.execute(sql)
2179+ SELECT f.id, f.date_start, f.date_stop FROM account_fiscalyear f Where %s between f.date_start and f.date_stop """
2180+ cr.execute(sql, (data['form']['date_from'],))
2181 res = cr.dictfetchall()
2182 if res:
2183 if (data['form']['date_to'] > res[0]['date_stop'] or data['form']['date_to'] < res[0]['date_start']):
2184
2185=== modified file 'account/wizard/wizard_general_ledger_report.py'
2186--- account/wizard/wizard_general_ledger_report.py 2009-09-07 07:09:31 +0000
2187+++ account/wizard/wizard_general_ledger_report.py 2010-03-17 11:50:49 +0000
2188@@ -106,8 +106,8 @@
2189 def _check_date(self, cr, uid, data, context):
2190
2191 sql = """
2192- 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'])
2193- cr.execute(sql)
2194+ SELECT f.id, f.date_start, f.date_stop FROM account_fiscalyear f Where %s between f.date_start and f.date_stop """
2195+ cr.execute(sql, (data['form']['date_from'],))
2196 res = cr.dictfetchall()
2197 if res:
2198 if (data['form']['date_to'] > res[0]['date_stop'] or data['form']['date_to'] < res[0]['date_start']):
2199
2200=== modified file 'account/wizard/wizard_open_closed_fiscalyear.py'
2201--- account/wizard/wizard_open_closed_fiscalyear.py 2009-01-27 11:15:46 +0000
2202+++ account/wizard/wizard_open_closed_fiscalyear.py 2010-03-17 11:50:49 +0000
2203@@ -43,16 +43,7 @@
2204 period_journal = data_fyear.end_journal_period_id
2205 ids_move = pool.get('account.move').search(cr,uid,[('journal_id','=',period_journal.journal_id.id),('period_id','=',period_journal.period_id.id)])
2206 if ids_move:
2207- cr.execute('delete from account_move where id in ('+','.join(map(str,ids_move))+')')
2208- #cr.execute('UPDATE account_journal_period ' \
2209- # 'SET state = %s ' \
2210- # 'WHERE period_id IN (SELECT id FROM account_period WHERE fiscalyear_id = %s)',
2211- # ('draft',data_fyear))
2212- #cr.execute('UPDATE account_period SET state = %s ' \
2213- # 'WHERE fiscalyear_id = %s', ('draft',data_fyear))
2214- #cr.execute('UPDATE account_fiscalyear ' \
2215- # 'SET state = %s, end_journal_period_id = null '\
2216- # 'WHERE id = %s', ('draft',data_fyear))
2217+ cr.execute('delete from account_move where id in %s', (tuple(ids_move),))
2218 return {}
2219
2220 class open_closed_fiscal(wizard.interface):
2221
2222=== modified file 'account/wizard/wizard_partner_balance_report.py'
2223--- account/wizard/wizard_partner_balance_report.py 2009-04-29 07:42:01 +0000
2224+++ account/wizard/wizard_partner_balance_report.py 2010-03-17 11:50:49 +0000
2225@@ -102,8 +102,8 @@
2226 def _check_date(self, cr, uid, data, context):
2227
2228 sql = """
2229- 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'])
2230- cr.execute(sql)
2231+ SELECT f.id, f.date_start, f.date_stop FROM account_fiscalyear f Where %s between f.date_start and f.date_stop """
2232+ cr.execute(sql, (data['form']['date1'],))
2233 res = cr.dictfetchall()
2234 if res:
2235 if (data['form']['date2'] > res[0]['date_stop'] or data['form']['date2'] < res[0]['date_start']):
2236
2237=== modified file 'account/wizard/wizard_third_party_ledger.py'
2238--- account/wizard/wizard_third_party_ledger.py 2009-05-29 11:35:52 +0000
2239+++ account/wizard/wizard_third_party_ledger.py 2010-03-17 11:50:49 +0000
2240@@ -114,8 +114,8 @@
2241 def _check_date(self, cr, uid, data, context):
2242
2243 sql = """
2244- 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'])
2245- cr.execute(sql)
2246+ SELECT f.id, f.date_start, f.date_stop FROM account_fiscalyear f Where %s between f.date_start and f.date_stop """
2247+ cr.execute(sql, (data['form']['date1'],))
2248 res = cr.dictfetchall()
2249 if res:
2250 if (data['form']['date2'] > res[0]['date_stop'] or data['form']['date2'] < res[0]['date_start']):
2251
2252=== modified file 'account_analytic_plans/report/crossovered_analytic.py'
2253--- account_analytic_plans/report/crossovered_analytic.py 2009-10-09 11:49:00 +0000
2254+++ account_analytic_plans/report/crossovered_analytic.py 2010-03-17 11:50:49 +0000
2255@@ -72,13 +72,19 @@
2256
2257 self.dict_acc_ref = {}
2258 if form['journal_ids'][0][2]:
2259- journal = " in (" + ','.join(map(lambda x: str(x), form['journal_ids'][0][2])) + ")"
2260+ journal_filter = "in %s"
2261+ sql_args = (tuple(form['journal_ids'][0][2]),)
2262 else:
2263- journal = 'is not null'
2264-
2265- query_general = "select id from account_analytic_line where (journal_id " + journal +") AND date>='"+ str(form['date1']) +"'"" AND date<='" + str(form['date2']) + "'"
2266-
2267- self.cr.execute(query_general)
2268+ journal_filter = 'is not null'
2269+ sql_args = ()
2270+
2271+ query_general = "SELECT id FROM account_analytic_line "\
2272+ "WHERE (journal_id %s) "\
2273+ "AND date>=%%s "\
2274+ "AND date<=%%s"%(
2275+ journal_filter)
2276+
2277+ self.cr.execute(query_general, sql_args + (form['date1'], form['date2']))
2278 l_ids=self.cr.fetchall()
2279 line_ids = [x[0] for x in l_ids]
2280
2281@@ -98,10 +104,16 @@
2282 self.final_list = children_list
2283 selected_ids = line_pool.search(self.cr,self.uid,[('account_id','in',self.final_list)])
2284
2285- query="SELECT sum(aal.amount) AS amt, sum(aal.unit_amount) AS qty FROM account_analytic_line AS aal, account_analytic_account AS aaa \
2286- WHERE aal.account_id=aaa.id AND aal.id IN ("+','.join(map(str,selected_ids))+") AND (aal.journal_id " + journal +") AND aal.date>='"+ str(form['date1']) +"'"" AND aal.date<='" + str(form['date2']) + "'"
2287+ query="SELECT SUM(aal.amount) AS amt, SUM(aal.unit_amount) AS qty "\
2288+ "FROM account_analytic_line AS aal, account_analytic_account AS aaa "\
2289+ "WHERE aal.account_id=aaa.id "\
2290+ "AND aal.id IN %%s "\
2291+ "AND (aal.journal_id %s) "\
2292+ "AND aal.date>=%%s "\
2293+ "AND aal.date<=%%s"%(journal_filter)
2294
2295- self.cr.execute(query)
2296+ self.cr.execute(
2297+ query, (tuple(selected_ids),) + sql_args + (form['date1'],form['date2']))
2298 info=self.cr.dictfetchall()
2299
2300 res['ref_qty']=info[0]['qty']
2301@@ -116,9 +128,11 @@
2302 ids = self.ids
2303
2304 if form['journal_ids'][0][2]:
2305- journal=" in (" + ','.join(map(lambda x: str(x), form['journal_ids'][0][2])) + ")"
2306+ journal_filter = " in %s"
2307+ sql_args = (tuple(form['journal_ids'][0][2]),)
2308 else:
2309- journal= 'is not null'
2310+ journal_filter = 'is not null'
2311+ sql_args = ()
2312
2313 acc_pool = self.pool.get('account.analytic.account')
2314 line_pool=self.pool.get('account.analytic.line')
2315@@ -132,10 +146,22 @@
2316 for acc_id in self.final_list:
2317 selected_ids = line_pool.search(self.cr,self.uid,[('account_id','=',acc_id),('move_id','in',self.dict_acc_ref[form['ref']])])
2318 if selected_ids:
2319- query="SELECT aaa.code as code , sum(aal.amount) AS amt, sum(aal.unit_amount) AS qty,aaa.name as acc_name,aal.account_id as id FROM account_analytic_line AS aal, account_analytic_account AS aaa \
2320- WHERE aal.account_id=aaa.id AND aal.id IN ("+','.join(map(str,selected_ids))+") AND (aal.journal_id " + journal +") AND aal.date>='"+ str(form['date1']) +"'"" AND aal.date<='" + str(form['date2']) + "'"" GROUP BY aal.account_id,aaa.name,aaa.code ORDER BY aal.account_id"
2321+ query="SELECT aaa.code as code , SUM(aal.amount) AS amt, "\
2322+ "SUM(aal.unit_amount) AS qty, aaa.name AS acc_name, "\
2323+ "aal.account_id AS id "\
2324+ "FROM account_analytic_line AS aal, account_analytic_account AS aaa "\
2325+ "WHERE aal.account_id=aaa.id "\
2326+ "AND aal.id IN %%s "\
2327+ "AND (aal.journal_id %s) "\
2328+ "AND aal.date>=%%s "\
2329+ "AND aal.date<=%%s "\
2330+ "GROUP BY aal.account_id, aaa.name, aaa.code "\
2331+ "ORDER BY aal.account_id" % (
2332+ journal_filter
2333+ )
2334
2335- self.cr.execute(query)
2336+ self.cr.execute(query, (tuple(selected_ids),) + sql_args \
2337+ + (form['date1'], form['date2']))
2338 res = self.cr.dictfetchall()
2339 if res:
2340 for element in res:
2341
2342=== modified file 'account_payment/account_move_line.py'
2343--- account_payment/account_move_line.py 2010-01-08 11:38:58 +0000
2344+++ account_payment/account_move_line.py 2010-03-17 11:50:49 +0000
2345@@ -19,7 +19,7 @@
2346 # along with this program. If not, see <http://www.gnu.org/licenses/>.
2347 #
2348 ##############################################################################
2349-
2350+from operator import itemgetter
2351 from osv import fields, osv
2352 from tools.translate import _
2353
2354@@ -43,7 +43,7 @@
2355 WHERE move_line_id = ml.id
2356 AND po.state != 'cancel') as amount
2357 FROM account_move_line ml
2358- WHERE id in (%s)""" % (",".join(map(str, ids))))
2359+ WHERE id in %s""", (tuple(ids),))
2360 r=dict(cr.fetchall())
2361 return r
2362
2363@@ -59,8 +59,10 @@
2364 END - coalesce(sum(pl.amount_currency), 0)
2365 FROM payment_line pl
2366 INNER JOIN payment_order po ON (pl.order_id = po.id)
2367- WHERE move_line_id = l.id AND po.state != 'cancel')''' \
2368- + x[1] + str(x[2])+' ',args))
2369+ WHERE move_line_id = l.id
2370+ AND po.state != 'cancel'
2371+ ) %(operator)s %%s ''' % {'operator': x[1]}, args))
2372+ sql_args = tuple(map(itemgetter(2), args))
2373
2374 cr.execute(('''select id
2375 from account_move_line l
2376@@ -69,7 +71,7 @@
2377 where type=%s and active)
2378 and reconcile_id is null
2379 and credit > 0
2380- and ''' + where + ' and ' + query), ('payable',) )
2381+ and ''' + where + ' and ' + query), ('payable',)+sql_args )
2382
2383 res = cr.fetchall()
2384 if not len(res):
2385
2386=== modified file 'account_payment/payment.py'
2387--- account_payment/payment.py 2009-02-26 14:31:43 +0000
2388+++ account_payment/payment.py 2010-03-17 11:50:49 +0000
2389@@ -65,8 +65,6 @@
2390 join payment_mode pm on (pm.type = pt.id)
2391 where pm.id = %s """, [payment_code])
2392 return [x[0] for x in cr.fetchall()]
2393-
2394-
2395 payment_mode()
2396
2397
2398@@ -150,19 +148,8 @@
2399 _name = 'payment.line'
2400 _description = 'Payment Line'
2401
2402- #~ def partner_payable(self, cr, uid, ids, name, args, context={}):
2403- #~ if not ids: return {}
2404- #~ partners= self.read(cr, uid, ids, ['partner_id'], context)
2405- #~ partners= dict(map(lambda x: (x['id'], x['partner_id'][0]), partners))
2406- #~ debit = self.pool.get('res.partner')._debit_get(cr, uid,
2407- #~ partners.values(), name, args, context)
2408- #~ for i in partners:
2409- #~ partners[i] = debit[partners[i]]
2410- #~ return partners
2411-
2412 def translate(self, orig):
2413 return {
2414-# "to_pay": "credit",
2415 "due_date": "date_maturity",
2416 "reference": "ref"}.get(orig, orig)
2417
2418@@ -224,8 +211,8 @@
2419 from account_move_line ml
2420 inner join payment_line pl
2421 on (ml.id = pl.move_line_id)
2422- where pl.id in (%s)"""%
2423- (self.translate(name), ','.join(map(str,ids))) )
2424+ where pl.id in %%s"""% self.translate(name),
2425+ (tuple(ids),))
2426 res = dict(cr.fetchall())
2427
2428 if name == 'partner_id':
2429@@ -244,61 +231,6 @@
2430 res.setdefault(id, (False, ""))
2431 return res
2432
2433-# def _currency(self, cursor, user, ids, name, args, context=None):
2434-# if not ids:
2435-# return {}
2436-# res = {}
2437-#
2438-# currency_obj = self.pool.get('res.currency')
2439-# account_obj = self.pool.get('account.account')
2440-# cursor.execute('''SELECT pl.id, ml.currency_id, ml.account_id
2441-# FROM account_move_line ml
2442-# INNER JOIN payment_line pl
2443-# ON (ml.id = pl.move_line_id)
2444-# WHERE pl.id in (''' + ','.join([str(x) for x in ids]) + ')')
2445-#
2446-# res2 = {}
2447-# account_ids = []
2448-# for payment_line_id, currency_id, account_id in cursor.fetchall():
2449-# res2[payment_line_id] = [currency_id, account_id]
2450-# account_ids.append(account_id)
2451-#
2452-# account2currency_id = {}
2453-# for account in account_obj.browse(cursor, user, account_ids,
2454-# context=context):
2455-# account2currency_id[account.id] = account.company_currency_id.id
2456-#
2457-# for payment_line_id in ids:
2458-# if res2[payment_line_id][0]:
2459-# res[payment_line_id] = res2[payment_line_id][0]
2460-# else:
2461-# res[payment_line_id] = \
2462-# account2currency_id[res2[payment_line_id][1]]
2463-#
2464-# currency_names = {}
2465-# for currency_id, name in currency_obj.name_get(cursor, user, res.values(),
2466-# context=context):
2467-# currency_names[currency_id] = name
2468-# for payment_line_id in ids:
2469-# res[payment_line_id] = (res[payment_line_id],
2470-# currency_names[res[payment_line_id]])
2471-# return res
2472-#
2473-# def _to_pay_currency(self, cursor, user, ids, name , args, context=None):
2474-# if not ids:
2475-# return {}
2476-#
2477-# cursor.execute('''SELECT pl.id,
2478-# CASE WHEN ml.amount_currency < 0
2479-# THEN - ml.amount_currency
2480-# ELSE ml.credit
2481-# END
2482-# FROM account_move_line ml
2483-# INNER JOIN payment_line pl
2484-# ON (ml.id = pl.move_line_id)
2485-# WHERE pl.id in (''' + ','.join([str(x) for x in ids]) + ')')
2486-# return dict(cursor.fetchall())
2487-
2488 def _amount(self, cursor, user, ids, name, args, context=None):
2489 if not ids:
2490 return {}
2491@@ -334,15 +266,6 @@
2492 else:
2493 return self.pool.get('res.currency').search(cr, uid, [('rate','=',1.0)])[0]
2494
2495-# def select_move_lines(*a):
2496-# print a
2497-# return []
2498-
2499-# def create(self, cr, uid, vals, context):
2500-# print "created!!!"
2501-# vals['company_currency'] = self._get_currency(cr, uid, context)
2502-# return super(payment_line, self).create(cr, uid, vals, context)
2503-
2504 def _get_ml_inv_ref(self, cr, uid, ids, *a):
2505 res={}
2506 for id in self.browse(cr, uid, ids):
2507@@ -377,11 +300,6 @@
2508 'move_line_id': fields.many2one('account.move.line','Entry line', domain=[('reconcile_id','=', False), ('account_id.type', '=','payable')],help='This Entry Line will be referred for the information of the ordering customer.'),
2509 'amount_currency': fields.float('Amount in Partner Currency', digits=(16,2),
2510 required=True, help='Payment amount in the partner currency'),
2511-# 'to_pay_currency': fields.function(_to_pay_currency, string='To Pay',
2512-# method=True, type='float',
2513-# help='Amount to pay in the partner currency'),
2514-# 'currency': fields.function(_currency, string='Currency',
2515-# method=True, type='many2one', obj='res.currency'),
2516 'currency': fields.many2one('res.currency','Partner Currency',required=True),
2517 'company_currency': fields.many2one('res.currency','Company Currency',readonly=True),
2518 'bank_id': fields.many2one('res.partner.bank', 'Destination Bank account'),
2519@@ -391,21 +309,12 @@
2520 'amount': fields.function(_amount, string='Amount in Company Currency',
2521 method=True, type='float',
2522 help='Payment amount in the company currency'),
2523-# 'to_pay': fields.function(select_by_name, string="To Pay", method=True,
2524-# type='float', help='Amount to pay in the company currency'),
2525-# 'due_date': fields.function(select_by_name, string="Due date",
2526-# method=True, type='date'),
2527 'ml_date_created': fields.function(_get_ml_created_date, string="Effective Date",
2528 method=True, type='date',help="Invoice Effective Date"),
2529-# 'reference': fields.function(select_by_name, string="Ref", method=True,
2530-# type='char'),
2531 'ml_maturity_date': fields.function(_get_ml_maturity_date, method=True, type='date', string='Maturity Date'),
2532 'ml_inv_ref': fields.function(_get_ml_inv_ref, method=True, type='many2one', relation='account.invoice', string='Invoice Ref.'),
2533 'info_owner': fields.function(info_owner, string="Owner Account", method=True, type="text",help='Address of the Main Partner'),
2534 'info_partner': fields.function(info_partner, string="Destination Account", method=True, type="text",help='Address of the Ordering Customer.'),
2535-# 'partner_payable': fields.function(partner_payable, string="Partner payable", method=True, type='float'),
2536-# 'value_date': fields.function(_value_date, string='Value Date',
2537-# method=True, type='date'),
2538 'date': fields.date('Payment Date',help="If no payment date is specified, the bank will treat this payment line directly"),
2539 'create_date': fields.datetime('Created' ,readonly=True),
2540 'state': fields.selection([('normal','Free'), ('structured','Structured')], 'Communication Type', required=True)
2541
2542=== modified file 'account_voucher/account.py'
2543--- account_voucher/account.py 2010-01-20 17:19:31 +0000
2544+++ account_voucher/account.py 2010-03-17 11:50:49 +0000
2545@@ -67,9 +67,11 @@
2546 def compute_total(self, cr, uid, ids, yr_st_date, yr_end_date, st_date, end_date, field_names, context={}):
2547 if not (st_date >= yr_st_date and end_date <= yr_end_date):
2548 return {}
2549- query = "l.date >= '%s' AND l.date <= '%s'" (st_date, end_date)
2550- return self.__compute(cr, uid, ids, field_names, context=context, query=query)
2551-
2552+ return self.__compute(
2553+ cr, uid, ids, field_names, context=context,
2554+ query="l.date >= '%s' AND l.date <= '%s'",
2555+ query_params=(st_date, end_date))
2556+
2557 def create(self, cr, uid, vals, context={}):
2558 name=self.search(cr,uid,[('name','ilike',vals['name']),('company_id','=',vals['name'])])
2559 if name:
2560
2561=== modified file 'account_voucher/voucher.py'
2562--- account_voucher/voucher.py 2010-03-08 07:19:28 +0000
2563+++ account_voucher/voucher.py 2010-03-17 11:50:49 +0000
2564@@ -407,7 +407,8 @@
2565 def action_number(self, cr, uid, ids, *args):
2566 cr.execute('SELECT id, type, number, move_id, reference ' \
2567 'FROM account_voucher ' \
2568- 'WHERE id IN ('+','.join(map(str,ids))+')')
2569+ 'WHERE id IN %s',
2570+ (tuple(ids),))
2571 for (id, invtype, number, move_id, reference) in cr.fetchall():
2572 if not number:
2573 number = self.pool.get('ir.sequence').get(cr, uid, invtype)
2574
2575=== modified file 'auction/auction.py'
2576--- auction/auction.py 2009-08-24 11:51:52 +0000
2577+++ auction/auction.py 2010-03-17 11:50:49 +0000
2578@@ -95,12 +95,19 @@
2579 RETURN: True
2580 """
2581 # objects vendus mais non factures
2582- 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',))
2583+ cr.execute('SELECT COUNT(*) AS c '
2584+ 'FROM auction_lots '
2585+ 'WHERE auction_id IN %s '
2586+ 'AND state=%s AND obj_price>0', (tuple(ids), 'draft'))
2587 nbr = cr.fetchone()[0]
2588 ach_uids = {}
2589- cr.execute('select id from auction_lots where auction_id in ('+','.join(map(str,ids))+') and state=%s and obj_price>0', ('draft',))
2590+ cr.execute('SELECT id FROM auction_lots '
2591+ 'WHERE auction_id IN %s '
2592+ 'AND state=%s AND obj_price>0', (tuple(ids), 'draft'))
2593 r=self.pool.get('auction.lots').lots_invoice(cr, uid, [x[0] for x in cr.fetchall()],{},None)
2594- cr.execute('select id from auction_lots where auction_id in ('+','.join(map(str,ids))+') and obj_price>0')
2595+ cr.execute('SELECT id FROM auction_lots '
2596+ 'WHERE auction_id IN %s '
2597+ 'AND obj_price>0', (tuple(ids),))
2598 ids2 = [x[0] for x in cr.fetchall()]
2599 # for auction in auction_ids:
2600 c=self.pool.get('auction.lots').seller_trans_create(cr, uid, ids2,{})
2601@@ -113,7 +120,9 @@
2602 # Deposits
2603 #----------------------------------------------------------
2604 def _inv_uniq(cr, ids):
2605- cr.execute('select name from auction_deposit where id in ('+','.join(map(lambda x: str(x), ids))+')')
2606+ cr.execute('SELECT name FROM auction_deposit '
2607+ 'WHERE id IN %s',
2608+ (tuple(ids),))
2609 for datas in cr.fetchall():
2610 cr.execute('select count(*) from auction_deposit where name=%s', (datas[0],))
2611 if cr.fetchone()[0]>1:
2612@@ -229,7 +238,9 @@
2613 # Lots
2614 #----------------------------------------------------------
2615 def _inv_constraint(cr, ids):
2616- cr.execute('select id, bord_vnd_id, lot_num from auction_lots where id in ('+','.join(map(lambda x: str(x), ids))+')')
2617+ cr.execute('SELECT id, bord_vnd_id, lot_num FROM auction_lots '
2618+ 'WHERE id IN %s',
2619+ (tuple(ids),))
2620 for datas in cr.fetchall():
2621 cr.execute('select count(*) from auction_lots where bord_vnd_id=%s and lot_num=%s', (datas[1],datas[2]))
2622 if cr.fetchone()[0]>1:
2623
2624=== modified file 'auction/report/auction_objects.py'
2625--- auction/report/auction_objects.py 2009-10-09 11:49:00 +0000
2626+++ auction/report/auction_objects.py 2010-03-17 11:50:49 +0000
2627@@ -29,20 +29,7 @@
2628 super(auction_objects, self).__init__(cr, uid, name, context=context)
2629 self.localcontext.update({
2630 'time': time,
2631- #'lines': self.lines
2632- #'get_data' : self.get_data
2633 })
2634-
2635-# def lines(self, auction_id):
2636-#
2637-# cr.execute('select ad.name from auction_dates ad, a1uction_lots al where ad.id=al.%d group by ad.name',(auction_id))
2638-# return self.cr.fetchone()[0]
2639-# def get_data(self, auction_id):
2640-# res = self.pool.get('auction.bid.lines').read(self.cr,self.uid,[lot_id])
2641-# return True
2642-
2643-
2644-
2645 report_sxw.report_sxw('report.auction.objects', 'auction.lots', 'addons/auction/report/auction_objects.rml', parser=auction_objects)
2646
2647 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
2648
2649=== modified file 'auction/report/auction_total_rml.py'
2650--- auction/report/auction_total_rml.py 2009-10-09 11:49:00 +0000
2651+++ auction/report/auction_total_rml.py 2010-03-17 11:50:49 +0000
2652@@ -55,7 +55,10 @@
2653 for lot_id in objects:
2654 auc_lot_ids.append(lot_id.id)
2655 self.total_obj=auc_lot_ids
2656- self.cr.execute('select auction_id from auction_lots where id in ('+','.join(map(str,auc_lot_ids))+') group by auction_id')
2657+ self.cr.execute('SELECT auction_id FROM auction_lots '
2658+ 'WHERE id IN %s '
2659+ 'GROUP BY auction_id',
2660+ (tuple(auc_lot_ids),))
2661 auc_date_ids = self.cr.fetchall()
2662 auct_dat=[]
2663 for ad_id in auc_date_ids:
2664
2665=== modified file 'auction/report/buyer_list.py'
2666--- auction/report/buyer_list.py 2009-10-09 11:49:00 +0000
2667+++ auction/report/buyer_list.py 2010-03-17 11:50:49 +0000
2668@@ -51,7 +51,8 @@
2669 for lot_id in objects:
2670 auc_lot_ids.append(lot_id.id)
2671 self.auc_lot_ids=auc_lot_ids
2672- self.cr.execute('select auction_id from auction_lots where id in ('+','.join(map(str,auc_lot_ids))+') group by auction_id')
2673+ self.cr.execute('SELECT auction_id FROM auction_lots WHERE id IN %s GROUP BY auction_id',
2674+ (tuple(auc_lot_ids),))
2675 auc_date_ids = self.cr.fetchall()
2676 auct_dat=[]
2677 for ad_id in auc_date_ids:
2678@@ -71,13 +72,16 @@
2679
2680 auc_date_ids = self.pool.get('auction.dates').search(self.cr,self.uid,([('name','like',obj['name'])]))
2681
2682-# 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],))
2683- 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],))
2684+ self.cr.execute('SELECT ach_login AS ach_uid, COUNT(1) AS no_lot, '\
2685+ 'SUM(obj_price) AS adj_price, '\
2686+ 'SUM(buyer_price)-SUM(obj_price) AS buyer_cost, '\
2687+ 'SUM(buyer_price) AS to_pay '\
2688+ 'FROM auction_lots WHERE id IN %s '\
2689+ 'AND auction_id=%s AND ach_login IS NOT NULL '\
2690+ 'GROUP BY ach_login ORDER BY ach_login',
2691+ (tuple(self.auc_lot_ids), auc_date_ids[0],))
2692 res = self.cr.dictfetchall()
2693 for r in res:
2694-# if r['ach_uid']:
2695-# tnm=self.pool.get('res.partner').read(self.cr,self.uid,[r['ach_uid']],['name'])#
2696-# r.__setitem__('ach_uid',tnm[0]['name'])
2697 self.sum_adj_price_val = self.sum_adj_price_val + r['adj_price']
2698 self.sum_buyer_obj_price_val = self.sum_buyer_obj_price_val + r['buyer_cost']
2699 self.sum_buyer_price_val = self.sum_buyer_price_val + r['to_pay']
2700
2701=== modified file 'base_module_quality/speed_test/speed_test.py'
2702--- base_module_quality/speed_test/speed_test.py 2010-02-18 15:23:03 +0000
2703+++ base_module_quality/speed_test/speed_test.py 2010-03-17 11:50:49 +0000
2704@@ -62,7 +62,9 @@
2705
2706 # remove osv_memory class becaz it does not have demo data
2707 if obj_list:
2708- 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)))
2709+ cr.execute("SELECT w.res_model FROM ir_actions_todo AS t "\
2710+ "LEFT JOIN ir_act_window AS w ON t.action_id=w.id "\
2711+ "WHERE w.res_model IN %s", (tuple(obj_list),))
2712 res = cr.fetchall()
2713 for remove_obj in res:
2714 if remove_obj and (remove_obj[0] in obj_list):
2715
2716=== modified file 'crm/crm.py'
2717--- crm/crm.py 2009-08-10 06:20:35 +0000
2718+++ crm/crm.py 2010-03-17 11:50:49 +0000
2719@@ -75,7 +75,9 @@
2720 def _check_recursion(self, cr, uid, ids):
2721 level = 100
2722 while len(ids):
2723- cr.execute('select distinct parent_id from crm_case_section where id in ('+','.join(map(str,ids))+')')
2724+ cr.execute('SELECT DISTINCT parent_id FROM crm_case_section '\
2725+ 'WHERE id IN %s',
2726+ (tuple(ids),))
2727 ids = filter(None, map(lambda x:x[0], cr.fetchall()))
2728 if not level:
2729 return False
2730
2731=== modified file 'crm/report/report_businessopp.py'
2732--- crm/report/report_businessopp.py 2010-02-17 10:53:29 +0000
2733+++ crm/report/report_businessopp.py 2010-03-17 11:50:49 +0000
2734@@ -56,7 +56,13 @@
2735 minbenef = 999999999999999999999
2736 maxbenef = 0
2737
2738- 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')
2739+ cr.execute('SELECT probability, planned_revenue, planned_cost, '\
2740+ 'user_id, res_users.name AS name '\
2741+ 'FROM crm_case '\
2742+ 'LEFT JOIN res_users ON (crm_case.user_id=res_users.id) '\
2743+ 'WHERE crm_case.id IN %s '\
2744+ 'ORDER BY user_id',
2745+ (tuple(ids),))
2746 res = cr.dictfetchall()
2747
2748 for row in res:
2749
2750=== modified file 'crm_profiling/crm_profiling.py'
2751--- crm_profiling/crm_profiling.py 2009-01-27 11:15:46 +0000
2752+++ crm_profiling/crm_profiling.py 2010-03-17 11:50:49 +0000
2753@@ -28,17 +28,17 @@
2754 query = """
2755 select distinct(answer)
2756 from profile_question_yes_rel
2757- where profile in (%s)"""% ','.join([str(i) for i in ids ])
2758+ where profile in %s"""
2759
2760- cr.execute(query)
2761+ cr.execute(query, (tuple(ids),))
2762 ans_yes = [x[0] for x in cr.fetchall()]
2763
2764 query = """
2765 select distinct(answer)
2766 from profile_question_no_rel
2767- where profile in (%s)"""% ','.join([str(i) for i in ids ])
2768+ where profile in %s"""
2769
2770- cr.execute(query)
2771+ cr.execute(query, (tuple(ids),))
2772 ans_no = [x[0] for x in cr.fetchall()]
2773
2774 return [ans_yes, ans_no]
2775@@ -50,7 +50,8 @@
2776 select distinct(parent_id)
2777 from crm_segmentation
2778 where parent_id is not null
2779- and id in (%s)""" % ','.join([str(i) for i in ids ]))
2780+ and id in %s""",
2781+ (tuple(ids),))
2782
2783 parent_ids = [x[0] for x in cr.fetchall()]
2784
2785@@ -86,30 +87,31 @@
2786
2787
2788 def _recompute_categ(self, cr, uid, pid, answers_ids):
2789- ok = []
2790 cr.execute('''
2791- select r.category_id
2792+ select r.category_id
2793 from res_partner_category_rel r left join crm_segmentation s on (r.category_id = s.categ_id)
2794 where r.partner_id = %s and (s.exclusif = false or s.exclusif is null)
2795 ''', (pid,))
2796- for x in cr.fetchall():
2797- ok.append(x[0])
2798+ categories = [x[0] for x in cr.fetchall()]
2799
2800 query = '''
2801- select id, categ_id
2802- from crm_segmentation
2803- where profiling_active = true'''
2804- if ok != []:
2805- query = query +''' and categ_id not in(%s)'''% ','.join([str(i) for i in ok ])
2806- query = query + ''' order by id '''
2807+ select id, categ_id
2808+ from crm_segmentation
2809+ where profiling_active = true'''
2810+ if not categories:
2811+ query_params = ()
2812+ else:
2813+ query += ' and categ_id not in %s'
2814+ query_params = (tuple(categories),)
2815+ query += ' order by id '
2816
2817- cr.execute(query)
2818+ cr.execute(query, query_params)
2819 segm_cat_ids = cr.fetchall()
2820
2821 for (segm_id, cat_id) in segm_cat_ids:
2822 if test_prof(cr, uid, segm_id, pid, answers_ids):
2823- ok.append(cat_id)
2824- return ok
2825+ categories.append(cat_id)
2826+ return categories
2827
2828
2829 class question(osv.osv):
2830
2831=== modified file 'document/document.py'
2832--- document/document.py 2010-01-08 11:38:58 +0000
2833+++ document/document.py 2010-03-17 11:50:49 +0000
2834@@ -302,7 +302,8 @@
2835 def _check_recursion(self, cr, uid, ids):
2836 level = 100
2837 while len(ids):
2838- cr.execute('select distinct parent_id from document_directory where id in ('+','.join(map(str,ids))+')')
2839+ cr.execute('SELECT DISTINCT parent_id FROM document_directory '\
2840+ 'WHERE id in %s', (tuple(ids),))
2841 ids = filter(None, map(lambda x:x[0], cr.fetchall()))
2842 if not level:
2843 return False
2844@@ -524,7 +525,8 @@
2845
2846 def _data_get(self, cr, uid, ids, name, arg, context):
2847 result = {}
2848- cr.execute('select id,store_fname,link from ir_attachment where id in ('+','.join(map(str,ids))+')')
2849+ cr.execute('SELECT id, store_fname, link FROM ir_attachment '\
2850+ 'WHERE id IN %s', (tuple(ids),))
2851 for id,r,l in cr.fetchall():
2852 try:
2853 value = file(os.path.join(self._get_filestore(cr), r), 'rb').read()
2854
2855=== modified file 'event/event.py'
2856--- event/event.py 2009-04-09 10:02:19 +0000
2857+++ event/event.py 2010-03-17 11:50:49 +0000
2858@@ -77,8 +77,8 @@
2859 def _get_register(self, cr, uid, ids, name, args, context=None):
2860 res={}
2861 for event in self.browse(cr, uid, ids, context):
2862- 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
2863- cr.execute(query)
2864+ 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')"""
2865+ cr.execute(query,(event.section_id.id,))
2866 res2 = cr.fetchone()
2867 if res2 and res2[0]:
2868 res[event.id] = res2[0]
2869@@ -89,8 +89,8 @@
2870 def _get_prospect(self, cr, uid, ids, name, args, context=None):
2871 res={}
2872 for event in self.browse(cr, uid, ids, context):
2873- 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
2874- cr.execute(query)
2875+ 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'"""
2876+ cr.execute(query, (event.section_id.id,))
2877 res2 = cr.fetchone()
2878 if res2 and res2[0]:
2879 res[event.id] = res2[0]
2880
2881=== modified file 'event_project/event.py'
2882--- event_project/event.py 2009-01-04 22:12:50 +0000
2883+++ event_project/event.py 2010-03-17 11:50:49 +0000
2884@@ -37,8 +37,8 @@
2885 for id in ids:
2886 res[id] = []
2887 for id in ids:
2888- query = "select project_id from event_event where id = %i" %id
2889- cr.execute(query)
2890+ query = "select project_id from event_event where id = %s"
2891+ cr.execute(query, (id,))
2892 project_ids = [ x[0] for x in cr.fetchall()]
2893 ids2 = obj.pool.get(self._obj).search(cr, user, [(self._fields_id,'in',project_ids),('state','<>','done')], limit=self._limit)
2894 for r in obj.pool.get(self._obj)._read_flat(cr, user, ids2, [self._fields_id], context=context, load='_classic_write'):
2895
2896=== modified file 'hr/hr.py'
2897--- hr/hr.py 2009-06-04 06:58:39 +0000
2898+++ hr/hr.py 2010-03-17 11:50:49 +0000
2899@@ -102,7 +102,8 @@
2900 def _check_recursion(self, cr, uid, ids):
2901 level = 100
2902 while len(ids):
2903- cr.execute('select distinct parent_id from hr_employee_category where id in ('+','.join(map(str,ids))+')')
2904+ cr.execute('SELECT DISTINCT parent_id FROM hr_employee_category '\
2905+ 'WHERE id IN %s', (tuple(ids),))
2906 ids = filter(None, map(lambda x:x[0], cr.fetchall()))
2907 if not level:
2908 return False
2909@@ -151,7 +152,8 @@
2910 def _check_recursion(self, cr, uid, ids):
2911 level = 100
2912 while len(ids):
2913- cr.execute('select distinct parent_id from hr_employee where id in ('+','.join(map(str,ids))+')')
2914+ cr.execute('SELECT DISTINCT parent_id FROM hr_employee '\
2915+ 'WHERE id IN %s', (tuple(ids),))
2916 ids = filter(None, map(lambda x:x[0], cr.fetchall()))
2917 if not level:
2918 return False
2919
2920=== modified file 'hr/hr_department.py'
2921--- hr/hr_department.py 2010-01-08 11:38:58 +0000
2922+++ hr/hr_department.py 2010-03-17 11:50:49 +0000
2923@@ -44,7 +44,8 @@
2924 def _check_recursion(self, cr, uid, ids):
2925 level = 100
2926 while len(ids):
2927- cr.execute('select distinct parent_id from hr_department where id in ('+','.join(map(str,ids))+')')
2928+ cr.execute('SELECT DISTINCT parent_id FROM hr_department '\
2929+ 'WHERE id IN %s', (tuple(ids),))
2930 ids = filter(None, map(lambda x:x[0], cr.fetchall()))
2931 if not level:
2932 return False
2933@@ -128,4 +129,4 @@
2934
2935 res_users()
2936
2937-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
2938\ No newline at end of file
2939+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
2940
2941=== modified file 'hr_attendance/hr_attendance.py'
2942--- hr_attendance/hr_attendance.py 2009-01-04 22:12:50 +0000
2943+++ hr_attendance/hr_attendance.py 2010-03-17 11:50:49 +0000
2944@@ -68,8 +68,8 @@
2945 and name <= (select name from hr_attendance where id=%s)
2946 order by name desc
2947 limit 2
2948- ''' % (id, id)
2949- cr.execute(sql)
2950+ '''
2951+ cr.execute(sql, (id, id))
2952 atts = cr.fetchall()
2953 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])):
2954 return False
2955@@ -98,7 +98,7 @@
2956 ON (hr_attendance.employee_id = foo.employee_id \
2957 AND hr_attendance.name = foo.name) \
2958 WHERE hr_attendance.employee_id \
2959- in (' + ','.join([str(x) for x in ids]) + ')')
2960+ in %s', (tuple(ids),))
2961 for res in cr.fetchall():
2962 result[res[1]] = res[0] == 'sign_in' and 'present' or 'absent'
2963 return result
2964
2965=== modified file 'hr_attendance/wizard/print_attendance_error.py'
2966--- hr_attendance/wizard/print_attendance_error.py 2010-01-21 11:52:07 +0000
2967+++ hr_attendance/wizard/print_attendance_error.py 2010-03-17 11:50:49 +0000
2968@@ -43,9 +43,12 @@
2969 def _check_data(self, cr, uid, data, *args):
2970 date_from = data['form']['init_date']
2971 date_to = data['form']['end_date']
2972- emp_ids = (','.join([str(x) for x in data['ids']]))
2973-
2974- 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'))
2975+ cr.execute("SELECT id FROM hr_attendance "\
2976+ "WHERE employee_id IN %s "\
2977+ "AND to_char(name,'YYYY-mm-dd')<=%s "\
2978+ "and to_char(name,'YYYY-mm-dd')>=%s "\
2979+ "and action in (%s, %s) order by name",
2980+ (tuple(data['ids']), date_to, date_from, 'sign_in', 'sign_out'))
2981 attendance_ids = [x[0] for x in cr.fetchall()]
2982 if not attendance_ids:
2983 raise wizard.except_wizard(_('No Data Available'), _('No records found for your selection!'))
2984
2985=== modified file 'hr_expense/hr_expense.py'
2986--- hr_expense/hr_expense.py 2009-10-13 14:50:16 +0000
2987+++ hr_expense/hr_expense.py 2010-03-17 11:50:49 +0000
2988@@ -39,10 +39,13 @@
2989 return super(hr_expense_expense, self).copy(cr, uid, id, default, context)
2990
2991 def _amount(self, cr, uid, ids, field_name, arg, context):
2992- id_set = ",".join(map(str, ids))
2993- 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 ")
2994- res = dict(cr.fetchall())
2995- return res
2996+ cr.execute("SELECT s.id, "\
2997+ "COALESCE(SUM(l.unit_amount*l.unit_quantity),0) AS amount "\
2998+ "FROM hr_expense_expense s "\
2999+ "LEFT OUTER JOIN hr_expense_line l ON (s.id=l.expense_id) "\
3000+ "WHERE s.id IN %s GROUP BY s.id ",
3001+ (tuple(ids),))
3002+ return dict(cr.fetchall())
3003
3004 def _get_currency(self, cr, uid, context):
3005 user = self.pool.get('res.users').browse(cr, uid, [uid])[0]
3006@@ -188,10 +191,11 @@
3007 def _amount(self, cr, uid, ids, field_name, arg, context):
3008 if not len(ids):
3009 return {}
3010- id_set = ",".join(map(str, ids))
3011- 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 ")
3012- res = dict(cr.fetchall())
3013- return res
3014+ cr.execute("SELECT l.id, "\
3015+ "COALESCE(SUM(l.unit_amount*l.unit_quantity),0) AS amount "\
3016+ "FROM hr_expense_line l WHERE id IN %s "\
3017+ "GROUP BY l.id", (tuple(ids),))
3018+ return dict(cr.fetchall())
3019
3020 _columns = {
3021 'name': fields.char('Short Description', size=128, required=True),
3022
3023=== modified file 'hr_holidays/hr.py'
3024--- hr_holidays/hr.py 2010-01-05 08:07:22 +0000
3025+++ hr_holidays/hr.py 2010-03-17 11:50:49 +0000
3026@@ -146,7 +146,7 @@
3027
3028 def _check_date(self, cr, uid, ids):
3029 if ids:
3030- cr.execute('select number_of_days from hr_holidays where id in ('+','.join(map(str, ids))+')')
3031+ cr.execute('select number_of_days from hr_holidays where id in %s', (tuple(ids),))
3032 res = cr.fetchall()
3033 if res and res[0][0] < 0:
3034 return False
3035
3036=== modified file 'hr_timesheet_invoice/wizard/hr_timesheet_invoice_create.py'
3037--- hr_timesheet_invoice/wizard/hr_timesheet_invoice_create.py 2009-12-10 09:40:49 +0000
3038+++ hr_timesheet_invoice/wizard/hr_timesheet_invoice_create.py 2010-03-17 11:50:49 +0000
3039@@ -43,7 +43,7 @@
3040 if obj_acc.invoice_id and obj_acc.invoice_id.state !='cancel':
3041 raise wizard.except_wizard(_('Warning'),_('The analytic entry "%s" is already invoiced!')%(obj_acc.name,))
3042
3043- cr.execute("SELECT distinct(account_id) from account_analytic_line where id IN (%s)"% (','.join(map(str,data['ids'])),))
3044+ cr.execute("SELECT distinct(account_id) from account_analytic_line where id IN %s", (tuple(data['ids']),))
3045 account_ids = cr.fetchall()
3046 return {'accounts': [x[0] for x in account_ids]}
3047
3048@@ -96,9 +96,10 @@
3049 cr.execute("SELECT product_id, to_invoice, sum(unit_amount) " \
3050 "FROM account_analytic_line as line " \
3051 "WHERE account_id = %s " \
3052- "AND id IN (" + ','.join([str(x) for x in data['ids']]) + ") " \
3053+ "AND id IN %s " \
3054 "AND to_invoice IS NOT NULL " \
3055- "GROUP BY product_id,to_invoice", (account.id,))
3056+ "GROUP BY product_id,to_invoice",
3057+ (account.id, tuple(data['ids'])))
3058
3059 for product_id,factor_id,qty in cr.fetchall():
3060 product = pool.get('product.product').browse(cr, uid, product_id, context2)
3061@@ -144,11 +145,11 @@
3062 #
3063 cr.execute("SELECT * " # TODO optimize this
3064 " FROM account_analytic_line"
3065- " WHERE account_id=%%s"
3066- " AND id IN (%s)"
3067- " AND product_id=%%s"
3068- " AND to_invoice=%%s" % ','.join(['%s']*len(data['ids'])),
3069- tuple([account.id]+ data['ids']+[ product_id, factor_id]))
3070+ " WHERE account_id=%s"
3071+ " AND id IN %s"
3072+ " AND product_id=%s"
3073+ " AND to_invoice=%s",
3074+ (account.id, tuple(data['ids']), product_id, factor_id))
3075 line_ids = cr.dictfetchall()
3076 note = []
3077 for line in line_ids:
3078@@ -169,8 +170,9 @@
3079
3080 curr_line['note'] = "\n".join(map(lambda x: x or '',note))
3081 pool.get('account.invoice.line').create(cr, uid, curr_line)
3082- strids = ','.join(map(str, data['ids']))
3083- cr.execute("update account_analytic_line set invoice_id=%%s WHERE account_id = %%s and id IN (%s)" % strids, (last_invoice,account.id,))
3084+ cr.execute("UPDATE account_analytic_line SET invoice_id=%s "\
3085+ "WHERE account_id = %s AND id IN %s",
3086+ (last_invoice,account.id, tuple(data['ids'])))
3087
3088 pool.get('account.invoice').button_reset_taxes(cr, uid, [last_invoice], context)
3089
3090
3091=== modified file 'hr_timesheet_sheet/hr_timesheet_sheet.py'
3092--- hr_timesheet_sheet/hr_timesheet_sheet.py 2010-03-11 15:43:08 +0000
3093+++ hr_timesheet_sheet/hr_timesheet_sheet.py 2010-03-17 11:50:49 +0000
3094@@ -104,7 +104,7 @@
3095 LEFT JOIN hr_timesheet_sheet_sheet_day AS day \
3096 ON (sheet.id = day.sheet_id \
3097 AND day.name = sheet.date_current) \
3098- WHERE sheet.id in (' + ','.join([str(x) for x in ids]) + ')')
3099+ WHERE sheet.id in %s', (tuple(ids),))
3100 return dict(cr.fetchall())
3101
3102 def _total(self, cr, uid, ids, name, args, context):
3103@@ -112,8 +112,8 @@
3104 FROM hr_timesheet_sheet_sheet s \
3105 LEFT JOIN hr_timesheet_sheet_sheet_day d \
3106 ON (s.id = d.sheet_id) \
3107- WHERE s.id in ('+ ','.join(map(str, ids)) + ') \
3108- GROUP BY s.id')
3109+ WHERE s.id in %s \
3110+ GROUP BY s.id', (tuple(ids),))
3111 return dict(cr.fetchall())
3112
3113 def _state_attendance(self, cr, uid, ids, name, args, context):
3114@@ -330,8 +330,8 @@
3115 ON (s.date_to >= al.date \
3116 AND s.date_from <= al.date \
3117 AND s.user_id = al.user_id) \
3118- WHERE l.id in (' + ','.join([str(x) for x in ids]) + ') \
3119- GROUP BY l.id')
3120+ WHERE l.id in %s \
3121+ GROUP BY l.id', (tuple(ids),))
3122 res = dict(cursor.fetchall())
3123 sheet_names = {}
3124 for sheet_id, name in sheet_obj.name_get(cursor, user, res.values(),
3125@@ -448,8 +448,8 @@
3126 ON (s.date_to >= to_date(to_char(a.name, 'YYYY-MM-dd'),'YYYY-MM-dd') \
3127 AND s.date_from <= to_date(to_char(a.name, 'YYYY-MM-dd'),'YYYY-MM-dd') \
3128 AND s.user_id = e.user_id) \
3129- WHERE a.id in (" + ",".join([str(x) for x in ids]) + ") \
3130- GROUP BY a.id")
3131+ WHERE a.id in %s \
3132+ GROUP BY a.id", (tuple(ids),))
3133 res = dict(cursor.fetchall())
3134 sheet_names = {}
3135 for sheet_id, name in sheet_obj.name_get(cursor, user, res.values(),
3136
3137=== modified file 'idea/idea.py'
3138--- idea/idea.py 2009-01-04 22:12:50 +0000
3139+++ idea/idea.py 2010-03-17 11:50:49 +0000
3140@@ -48,40 +48,40 @@
3141 if not len(ids):
3142 return {}
3143
3144- sql = """select i.id, avg(v.score::integer)
3145+ sql = """select i.id, avg(v.score::integer)
3146 from idea_idea i left outer join idea_vote v on i.id = v.idea_id
3147- where i.id in (%s)
3148+ where i.id in %s
3149 group by i.id
3150- """ % ','.join(['%d']*len(ids))
3151+ """
3152
3153- cr.execute(sql, ids)
3154+ cr.execute(sql, (tuple(ids),))
3155 return dict(cr.fetchall())
3156
3157 def _vote_count(self,cr,uid,ids,name,arg,context=None):
3158 if not len(ids):
3159 return {}
3160
3161- sql = """select i.id, count(1)
3162+ sql = """select i.id, count(1)
3163 from idea_idea i left outer join idea_vote v on i.id = v.idea_id
3164- where i.id in (%s)
3165+ where i.id in %s
3166 group by i.id
3167- """ % ','.join(['%d']*len(ids))
3168+ """
3169
3170- cr.execute(sql, ids)
3171+ cr.execute(sql, (tuple(ids),))
3172 return dict(cr.fetchall())
3173
3174 def _comment_count(self,cr,uid,ids,name,arg,context=None):
3175 if not len(ids):
3176 return {}
3177
3178- sql = """select i.id, count(1)
3179+ sql = """select i.id, count(1)
3180 from idea_idea i left outer join idea_comment c on i.id = c.idea_id
3181- where i.id in (%s)
3182+ where i.id in %s
3183 group by i.id
3184- """ % ','.join(['%d']*len(ids))
3185-
3186-
3187- cr.execute(sql,ids)
3188+ """
3189+
3190+
3191+ cr.execute(sql, (tuple(ids),))
3192 return dict(cr.fetchall())
3193
3194 def _vote_read(self, cr, uid, ids, name, arg, context = None):
3195
3196=== modified file 'l10n_be/wizard/wizard_vat_intra.py'
3197--- l10n_be/wizard/wizard_vat_intra.py 2009-03-24 11:01:43 +0000
3198+++ l10n_be/wizard/wizard_vat_intra.py 2010-03-17 11:50:49 +0000
3199@@ -169,11 +169,9 @@
3200 start_date = fiscal_periods[3].date_start
3201 end_date = fiscal_periods[3].date_stop
3202
3203- period = "to_date('" + str(start_date) + "','yyyy-mm-dd') and to_date('" + str(end_date) +"','yyyy-mm-dd')"
3204 record = {}
3205
3206 for p_id in p_id_list:
3207- list_partner = []
3208 partner = pool.get('res.partner').browse(cr, uid, p_id)
3209 go_ahead = False
3210 country_code = ''
3211@@ -185,27 +183,22 @@
3212 if not go_ahead:
3213 continue
3214
3215- cr.execute('select sum(debit)-sum(credit) as amount from account_move_line l left join account_account a on (l.account_id=a.id) where a.type in ('"'receivable'"') and l.partner_id=%%s and l.date between %s' % (period,), (p_id,))
3216+ cr.execute('SELECT SUM(debit)-SUM(credit) AS amount '\
3217+ 'FROM account_move_line l '\
3218+ 'LEFT JOIN account_account a ON (l.account_id=a.id) '\
3219+ 'WHERE a.type IN ('"'receivable'"') '\
3220+ 'AND l.partner_id=%s '\
3221+ 'AND l.date BETWEEN to_date(%s, \'yyyy-mm-dd\') '\
3222+ ' AND to_date(%s, \'yyyy-mm-dd\')',
3223+ (p_id, start_date, end_date))
3224 res = cr.dictfetchall()
3225- list_partner.append(res[0]['amount'])
3226- list_partner.append('T') #partner.ref ...should be check
3227- list_partner.append(partner.vat)
3228- list_partner.append(country_code)
3229- #...deprecated...
3230-# addr = pool.get('res.partner').address_get(cr, uid, [partner.id], ['invoice'])
3231-# if addr.get('invoice',False):
3232-# ads = pool.get('res.partner.address').browse(cr,uid,[addr['invoice']])[0]
3233-#
3234-# if ads.country_id:
3235-# code_country = ads.country_id.code
3236-# list_partner.append(code_country)
3237-# else:
3238-# error_message.append('Data Insufficient! : '+ 'The Partner "'+partner.name + '"'' has no country associated with its Invoice address!')
3239-# if len(list_partner)<4:
3240-# list_partner.append('')
3241-# error_message.append('Data Insufficient! : '+ 'The Partner "'+partner.name + '"'' has no Invoice address!')
3242-# list_partner.append(code_country or 'not avail')
3243- record[p_id] = list_partner
3244+
3245+ record[p_id] = (
3246+ res[0]['amount'],
3247+ 'T', #partner.ref ...should be check
3248+ partner.vat,
3249+ country_code
3250+ )
3251
3252 if len(error_message):
3253 data['form']['msg'] = 'Exception : \n' +'-'*50+'\n'+ '\n'.join(error_message)
3254@@ -235,4 +228,4 @@
3255 'result': {'type':'form', 'arch':msg_form, 'fields':msg_fields, 'state':[('end','Ok')]},
3256 }
3257 }
3258-parter_vat_intra('vat.intra.xml')
3259\ No newline at end of file
3260+parter_vat_intra('vat.intra.xml')
3261
3262=== modified file 'membership/membership.py'
3263--- membership/membership.py 2010-02-26 13:36:01 +0000
3264+++ membership/membership.py 2010-03-17 11:50:49 +0000
3265@@ -148,8 +148,8 @@
3266 )
3267 JOIN account_invoice ai ON (
3268 ai.id = ail.invoice_id)
3269- WHERE ml.id in (%s)
3270- ''' % ','.join([str(id) for id in ids]))
3271+ WHERE ml.id in %s
3272+ ''', (tuple(ids),))
3273
3274 res = cr.fetchall()
3275 for r in res:
3276@@ -414,7 +414,7 @@
3277 def _check_recursion(self, cr, uid, ids):
3278 level = 100
3279 while len(ids):
3280- cr.execute('select distinct associate_member from res_partner where id in ('+','.join(map(str,ids))+')')
3281+ cr.execute('select distinct associate_member from res_partner where id in %s', (tuple(ids),))
3282 ids = filter(None, map(lambda x:x[0], cr.fetchall()))
3283 if not level:
3284 return False
3285
3286=== modified file 'membership/wizard/invoice_membership.py'
3287--- membership/wizard/invoice_membership.py 2009-11-13 06:33:46 +0000
3288+++ membership/wizard/invoice_membership.py 2010-03-17 11:50:49 +0000
3289@@ -32,9 +32,8 @@
3290 cr.execute('''
3291 SELECT partner_id, id, type
3292 FROM res_partner_address
3293- WHERE partner_id IN (%s)
3294- ''' % ','.join([str(id) for id in partner_ids])
3295- )
3296+ WHERE partner_id IN %s
3297+ ''', (tuple(partner_ids),))
3298 fetchal = cr.fetchall()
3299 if not fetchal:
3300 raise wizard.except_wizard(_('Error !'), _('No Address defined for this partner'))
3301
3302=== modified file 'mrp/mrp.py'
3303--- mrp/mrp.py 2010-03-10 08:51:21 +0000
3304+++ mrp/mrp.py 2010-03-17 11:50:49 +0000
3305@@ -216,7 +216,7 @@
3306 def _check_recursion(self, cr, uid, ids):
3307 level = 500
3308 while len(ids):
3309- cr.execute('select distinct bom_id from mrp_bom where id in ('+','.join(map(str,ids))+')')
3310+ cr.execute('select distinct bom_id from mrp_bom where id in %s', (tuple(ids),))
3311 ids = filter(None, map(lambda x:x[0], cr.fetchall()))
3312 if not level:
3313 return False
3314
3315=== modified file 'mrp/report/workcenter_load.py'
3316--- mrp/report/workcenter_load.py 2009-09-28 14:26:44 +0000
3317+++ mrp/report/workcenter_load.py 2010-03-17 11:50:49 +0000
3318@@ -99,14 +99,13 @@
3319 def create(self, cr, uid, ids, datas, context={}):
3320 assert len(ids), 'You should provide some ids!'
3321 colors = choice_colors(len(ids))
3322- ids_str = ','.join(map(str, ids))
3323 cr.execute(
3324 "SELECT MAX(mrp_production.date_planned) AS stop,MIN(mrp_production.date_planned) AS start "\
3325 "FROM mrp_workcenter, mrp_production, mrp_production_workcenter_line "\
3326 "WHERE mrp_production_workcenter_line.production_id=mrp_production.id "\
3327 "AND mrp_production_workcenter_line.workcenter_id=mrp_workcenter.id "\
3328 "AND mrp_production.state NOT IN ('cancel','done') "\
3329- "AND mrp_workcenter.id IN (%s)" % ids_str)
3330+ "AND mrp_workcenter.id IN %s", (tuple(ids),))
3331 res = cr.dictfetchone()
3332 if not res['stop']:
3333 res['stop'] = time.strftime('%Y-%m-%d %H:%M:%S')
3334@@ -137,8 +136,8 @@
3335 # select workcenters
3336 cr.execute(
3337 "SELECT id, name FROM mrp_workcenter " \
3338- "WHERE id in (%s) "\
3339- "ORDER BY mrp_workcenter.id" % ids_str)
3340+ "WHERE id in %s "\
3341+ "ORDER BY mrp_workcenter.id", (tuple(ids),))
3342 workcenters = cr.dictfetchall()
3343
3344 data = []
3345
3346=== modified file 'point_of_sale/pos.py'
3347--- point_of_sale/pos.py 2010-02-03 05:47:12 +0000
3348+++ point_of_sale/pos.py 2010-03-17 11:50:49 +0000
3349@@ -60,7 +60,6 @@
3350 return {'value': {'pricelist_id': pricelist}}
3351
3352 def _amount_total(self, cr, uid, ids, field_name, arg, context):
3353- id_set = ",".join(map(str, ids))
3354 cr.execute("""
3355 SELECT
3356 p.id,
3357@@ -69,7 +68,7 @@
3358 ) AS amount
3359 FROM pos_order p
3360 LEFT OUTER JOIN pos_order_line l ON (p.id=l.order_id)
3361- WHERE p.id IN (""" + id_set +""") GROUP BY p.id """)
3362+ WHERE p.id IN %s GROUP BY p.id """, (tuple(ids),))
3363 res = dict(cr.fetchall())
3364
3365 for rec in self.browse(cr, uid, ids, context):
3366@@ -113,8 +112,8 @@
3367 return res
3368
3369 def payment_get(self, cr, uid, ids, context=None):
3370- cr.execute("select id from pos_payment where order_id in (%s)" % \
3371- ','.join([str(i) for i in ids]))
3372+ cr.execute("select id from pos_payment where order_id in %s",
3373+ (tuple(ids),))
3374 return [i[0] for i in cr.fetchall()]
3375
3376 def _sale_journal_get(self, cr, uid, context):
3377
3378=== modified file 'product/pricelist.py'
3379--- product/pricelist.py 2010-02-04 07:12:40 +0000
3380+++ product/pricelist.py 2010-03-17 11:50:49 +0000
3381@@ -22,7 +22,6 @@
3382
3383 from osv import fields, osv
3384
3385-#from tools.misc import currency
3386 from _common import rounding
3387 import time
3388 from tools import config
3389@@ -91,8 +90,6 @@
3390 res.append((type['key'],type['name']))
3391
3392 return res
3393-# cr.execute('select key,name from product_pricelist_type order by name')
3394-# return cr.fetchall()
3395 _name = "product.pricelist"
3396 _description = "Pricelist"
3397 _columns = {
3398@@ -179,9 +176,11 @@
3399 'you have defined cyclic categories ' \
3400 'of products!'))
3401 if categ_ids:
3402- categ_where = '(categ_id IN (' + ','.join(categ_ids) + '))'
3403+ categ_where = '(categ_id IN %s)'
3404+ sqlargs = (tuple(categ_ids),)
3405 else:
3406 categ_where = '(categ_id IS NULL)'
3407+ sqlargs = ()
3408
3409 cr.execute(
3410 'SELECT i.*, pl.currency_id '
3411@@ -194,7 +193,7 @@
3412 'AND (min_quantity IS NULL OR min_quantity <= %s) '
3413 'AND i.price_version_id = v.id AND v.pricelist_id = pl.id '
3414 'ORDER BY sequence LIMIT 1',
3415- (tmpl_id, prod_id, plversion['id'], qty))
3416+ (tmpl_id, prod_id) + sqlargs + ( plversion['id'], qty))
3417 res = cr.dictfetchone()
3418 if res:
3419 if res['base'] == -1:
3420@@ -218,10 +217,10 @@
3421 if sinfo:
3422 cr.execute('SELECT * ' \
3423 'FROM pricelist_partnerinfo ' \
3424- 'WHERE suppinfo_id IN (' + \
3425- ','.join(map(str, sinfo)) + ') ' \
3426+ 'WHERE suppinfo_id IN %s ' \
3427 'AND min_quantity <= %s ' \
3428- 'ORDER BY min_quantity DESC LIMIT 1', (qty,))
3429+ 'ORDER BY min_quantity DESC LIMIT 1',
3430+ (tuple(sinfo), qty))
3431 res2 = cr.dictfetchone()
3432 if res2:
3433 price = res2['price']
3434@@ -382,7 +381,4 @@
3435 return {}
3436 product_pricelist_item()
3437
3438-
3439-
3440 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
3441-
3442
3443=== modified file 'product/product.py'
3444--- product/product.py 2010-03-15 11:10:51 +0000
3445+++ product/product.py 2010-03-17 11:50:49 +0000
3446@@ -206,7 +206,7 @@
3447 def _check_recursion(self, cr, uid, ids):
3448 level = 100
3449 while len(ids):
3450- cr.execute('select distinct parent_id from product_category where id in ('+','.join(map(str,ids))+')')
3451+ cr.execute('select distinct parent_id from product_category where id in %s', (tuple(ids),))
3452 ids = filter(None, map(lambda x:x[0], cr.fetchall()))
3453 if not level:
3454 return False
3455
3456=== modified file 'product_margin/product_margin.py'
3457--- product_margin/product_margin.py 2009-01-04 22:12:50 +0000
3458+++ product_margin/product_margin.py 2010-03-17 11:50:49 +0000
3459@@ -1,7 +1,7 @@
3460 # -*- encoding: utf-8 -*-
3461 ##############################################################################
3462 #
3463-# OpenERP, Open Source Management Solution
3464+# OpenERP, Open Source Management Solution
3465 # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
3466 # $Id$
3467 #
3468@@ -25,53 +25,52 @@
3469 from tools import config
3470 import time
3471
3472+states = {
3473+ 'paid': ('paid',),
3474+ 'open_paid': ('open','paid'),
3475+ 'draft_open_paid': ('draft','open','paid')
3476+}
3477+
3478 class product_product(osv.osv):
3479- _inherit = "product.product"
3480-
3481-
3482+ _inherit = "product.product"
3483+
3484+
3485 def _product_margin(self, cr, uid, ids, field_names, arg, context):
3486- res = {}
3487+ res = {}
3488 for val in self.browse(cr, uid, ids,context=context):
3489 res[val.id] = {}
3490- date_from=context.get('date_from', time.strftime('%Y-01-01'))
3491- date_to=context.get('date_to', time.strftime('%Y-12-31'))
3492- invoice_state=context.get('invoice_state', 'open_paid')
3493+ date_from=context.get('date_from', time.strftime('%Y-01-01'))
3494+ date_to=context.get('date_to', time.strftime('%Y-12-31'))
3495+ invoice_state=context.get('invoice_state', 'open_paid')
3496 if 'date_from' in field_names:
3497- res[val.id]['date_from']=date_from
3498+ res[val.id]['date_from']=date_from
3499 if 'date_to' in field_names:
3500 res[val.id]['date_to']=date_to
3501 if 'invoice_state' in field_names:
3502- res[val.id]['invoice_state']=invoice_state
3503+ res[val.id]['invoice_state']=invoice_state
3504
3505-
3506- invoice_types=[]
3507- states=[]
3508- if invoice_state=='paid':
3509- states=['paid']
3510- elif invoice_state=='open_paid':
3511- states=['open','paid']
3512- elif invoice_state=='draft_open_paid':
3513- states=['draft','open','paid']
3514-
3515+ invoice_types=()
3516 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:
3517- invoice_types=['out_invoice','in_refund']
3518+ invoice_types=('out_invoice','in_refund')
3519 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:
3520- invoice_types=['in_invoice','out_refund']
3521- if len(invoice_types):
3522+ invoice_types=('in_invoice','out_refund')
3523+
3524+ if invoice_types:
3525 sql="""
3526- select
3527- avg(l.price_unit) as avg_unit_price,
3528- sum(l.quantity) as num_qty,
3529- sum(l.quantity * l.price_unit) as total,
3530- sum(l.quantity * product.list_price) as sale_expected,
3531- sum(l.quantity * product.standard_price) as normal_cost
3532+ select
3533+ avg(l.price_unit) as avg_unit_price,
3534+ sum(l.quantity) as num_qty,
3535+ sum(l.quantity * l.price_unit) as total,
3536+ sum(l.quantity * product.list_price) as sale_expected,
3537+ sum(l.quantity * product.standard_price) as normal_cost
3538 from account_invoice_line l
3539 left join account_invoice i on (l.invoice_id = i.id)
3540- left join product_template product on (product.id=l.product_id)
3541- 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'
3542- """%(val.id,"','".join(states),"','".join(invoice_types),date_from,date_to)
3543- cr.execute(sql)
3544- result=cr.fetchall()[0]
3545+ left join product_template product on (product.id=l.product_id)
3546+ 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
3547+ """
3548+ cr.execute(sql, (val.id, states[invoice_state],
3549+ invoice_types, date_from, date_to))
3550+ result=cr.fetchall()[0]
3551 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:
3552 res[val.id]['sale_avg_price']=result[0] and result[0] or 0.0
3553 res[val.id]['sale_num_invoiced']=result[1] and result[1] or 0.0
3554@@ -83,8 +82,8 @@
3555 res[val.id]['purchase_num_invoiced']=result[1] and result[1] or 0.0
3556 res[val.id]['total_cost']=result[2] and result[2] or 0.0
3557 res[val.id]['normal_cost']=result[4] and result[4] or 0.0
3558- res[val.id]['purchase_gap']=res[val.id]['normal_cost']-res[val.id]['total_cost']
3559-
3560+ res[val.id]['purchase_gap']=res[val.id]['normal_cost']-res[val.id]['total_cost']
3561+
3562 if 'total_margin' in field_names:
3563 res[val.id]['total_margin']=val.turnover-val.total_cost
3564 if 'expected_margin' in field_names:
3565@@ -92,15 +91,15 @@
3566 if 'total_margin_rate' in field_names:
3567 res[val.id]['total_margin_rate']=val.turnover and val.total_margin * 100 / val.turnover or 0.0
3568 if 'expected_margin_rate' in field_names:
3569- res[val.id]['expected_margin_rate']=val.sale_expected and val.expected_margin * 100 / val.sale_expected or 0.0
3570+ res[val.id]['expected_margin_rate']=val.sale_expected and val.expected_margin * 100 / val.sale_expected or 0.0
3571 return res
3572-
3573+
3574 _columns = {
3575 'date_from': fields.function(_product_margin, method=True, type='date', string='From Date', multi=True),
3576 'date_to': fields.function(_product_margin, method=True, type='date', string='To Date', multi=True),
3577 'invoice_state': fields.function(_product_margin, method=True, type='selection', selection=[
3578- ('paid','Paid'),('open_paid','Open and Paid'),('draft_open_paid','Draft, Open and Paid')
3579- ], string='Invoice State',multi=True, readonly=True),
3580+ ('paid','Paid'),('open_paid','Open and Paid'),('draft_open_paid','Draft, Open and Paid')
3581+ ], string='Invoice State',multi=True, readonly=True),
3582 'sale_avg_price' : fields.function(_product_margin, method=True, type='float', string='Avg. Unit Price', multi='sale',help="Avg. Price in Customer Invoices)"),
3583 'purchase_avg_price' : fields.function(_product_margin, method=True, type='float', string='Avg. Unit Price', multi='purchase',help="Avg. Price in Supplier Invoices "),
3584 'sale_num_invoiced' : fields.function(_product_margin, method=True, type='float', string='# Invoiced', multi='sale',help="Sum of Quantity in Customer Invoices"),
3585
3586=== modified file 'project/project.py'
3587--- project/project.py 2009-11-17 07:10:35 +0000
3588+++ project/project.py 2010-03-17 11:50:49 +0000
3589@@ -64,10 +64,11 @@
3590 FROM
3591 project_task
3592 WHERE
3593- project_id in ('''+','.join(map(str,ids2))+''') AND
3594+ project_id in %s AND
3595 state<>'cancelled'
3596 GROUP BY
3597- project_id''')
3598+ project_id''',
3599+ (tuple(ids2),))
3600 progress = dict(map(lambda x: (x[0], (x[1],x[2],x[3])), cr.fetchall()))
3601 for project in self.browse(cr, uid, ids, context=context):
3602 s = [0.0,0.0,0.0]
3603@@ -166,7 +167,7 @@
3604 default['name'] = proj.name+_(' (copy)')
3605 res = super(project, self).copy(cr, uid, id, default, context)
3606 ids = self.search(cr, uid, [('parent_id','child_of', [res])])
3607- cr.execute('update project_task set active=True where project_id in ('+','.join(map(str,ids))+')')
3608+ cr.execute('update project_task set active=True where project_id in %s', (tuple(ids,)))
3609 return res
3610
3611 def duplicate_template(self, cr, uid, ids,context={}):
3612@@ -228,8 +229,7 @@
3613
3614 # Compute: effective_hours, total_hours, progress
3615 def _hours_get(self, cr, uid, ids, field_names, args, context):
3616- task_set = ','.join(map(str, ids))
3617- cr.execute(("SELECT task_id, COALESCE(SUM(hours),0) FROM project_task_work WHERE task_id in (%s) GROUP BY task_id") % (task_set,))
3618+ cr.execute("SELECT task_id, COALESCE(SUM(hours),0) FROM project_task_work WHERE task_id in %s GROUP BY task_id", (tuple(ids),))
3619 hours = dict(cr.fetchall())
3620 res = {}
3621 for task in self.browse(cr, uid, ids, context=context):
3622
3623=== modified file 'purchase/purchase.py'
3624--- purchase/purchase.py 2010-03-10 09:01:40 +0000
3625+++ purchase/purchase.py 2010-03-17 11:50:49 +0000
3626@@ -112,8 +112,9 @@
3627 LEFT JOIN
3628 stock_picking p on (p.id=m.picking_id)
3629 WHERE
3630- p.purchase_id in ('''+','.join(map(str,ids))+''')
3631- GROUP BY m.state, p.purchase_id''')
3632+ p.purchase_id in %s
3633+ GROUP BY m.state, p.purchase_id''',
3634+ (tuple(ids),))
3635 for oid,nbr,state in cr.fetchall():
3636 if state=='cancel':
3637 continue
3638
3639=== modified file 'report_account/report_receivable.py'
3640--- report_account/report_receivable.py 2009-04-15 04:56:13 +0000
3641+++ report_account/report_receivable.py 2010-03-17 11:50:49 +0000
3642@@ -105,9 +105,9 @@
3643 date1,date2 = period['name'].split(' to ')
3644 query = "SELECT SUM(credit-debit) FROM account_move_line AS line, account_account as ac \
3645 WHERE (line.account_id=ac.id) AND ac.type='receivable' \
3646- AND (COALESCE(line.date,date) BETWEEN '%s' AND '%s') \
3647- AND (reconcile_id IS NULL) AND ac.active"%(str(date2),str(date1))
3648- cr.execute(query)
3649+ AND (COALESCE(line.date,date) BETWEEN %s AND %s) \
3650+ AND (reconcile_id IS NULL) AND ac.active"
3651+ cr.execute(query, (date2, date1))
3652 amount = cr.fetchone()
3653 amount = amount[0] or 0.00
3654 res[period['id']] = amount
3655
3656=== modified file 'report_analytic_planning/report_analytic_planning.py'
3657--- report_analytic_planning/report_analytic_planning.py 2009-01-04 22:12:50 +0000
3658+++ report_analytic_planning/report_analytic_planning.py 2010-03-17 11:50:49 +0000
3659@@ -119,8 +119,10 @@
3660 result = {}
3661 for line in self.browse(cr, uid, ids, context):
3662 where = ''
3663+ sqlarg = ()
3664 if line.user_id:
3665- where='user_id='+str(line.user_id.id)+' and '
3666+ where='user_id=%s and '
3667+ sqlarg = (line.user_id.id)
3668 cr.execute('''select
3669 sum(planned_hours)
3670 from
3671@@ -129,11 +131,11 @@
3672 '''+where+'''
3673 project_id in (select id from project_project where category_id=%s) and
3674 date_close>=%s and
3675- date_close<=%s''', (
3676- line.account_id.id,
3677- line.planning_id.date_from,
3678- line.planning_id.date_to)
3679- )
3680+ date_close<=%s''',
3681+ sqlarg + (
3682+ line.account_id.id,
3683+ line.planning_id.date_from,
3684+ line.planning_id.date_to))
3685 result[line.id] = cr.fetchone()[0]
3686 return result
3687 _columns = {
3688
3689=== modified file 'report_crm/report_crm.py'
3690--- report_crm/report_crm.py 2009-03-20 11:28:18 +0000
3691+++ report_crm/report_crm.py 2010-03-17 11:50:49 +0000
3692@@ -1,7 +1,7 @@
3693 # -*- encoding: utf-8 -*-
3694 ##############################################################################
3695 #
3696-# OpenERP, Open Source Management Solution
3697+# OpenERP, Open Source Management Solution
3698 # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
3699 # $Id$
3700 #
3701@@ -111,29 +111,29 @@
3702 _name = "report.crm.case.section"
3703 _description = "Cases by Section"
3704 _auto = False
3705-
3706+
3707 def _get_data(self, cr, uid, ids, field_name, arg, context={}):
3708 res = {}
3709 state_perc = 0.0
3710 avg_ans = 0.0
3711-
3712+
3713 for case in self.browse(cr, uid, ids, context):
3714 if field_name != 'avg_answers':
3715 state = field_name[5:]
3716- cr.execute("select count(*) from crm_case where section_id =%s and state='%s'"%(case.section_id.id,state))
3717+ cr.execute("select count(*) from crm_case where section_id =%s and state=%s", (case.section_id.id,state))
3718 state_cases = cr.fetchone()[0]
3719 perc_state = (state_cases / float(case.nbr_cases) ) * 100
3720-
3721+
3722 res[case.id] = perc_state
3723 else:
3724- cr.execute('select count(*) from crm_case_log l where l.section_id=%s'%(case.section_id.id))
3725+ cr.execute('select count(*) from crm_case_log l where l.section_id=%s', (case.section_id.id,))
3726 logs = cr.fetchone()[0]
3727-
3728+
3729 avg_ans = logs / case.nbr_cases
3730- res[case.id] = avg_ans
3731-
3732+ res[case.id] = avg_ans
3733+
3734 return res
3735-
3736+
3737 _columns = {
3738 'name': fields.date('Month', readonly=True),
3739 # 'user_id':fields.many2one('res.users', 'User', readonly=True),
3740@@ -181,7 +181,7 @@
3741 'create_date' : fields.datetime('Create Date', readonly=True)
3742 }
3743 _order = 'date_closed, create_date'
3744-
3745+
3746 def init(self, cr):
3747 cr.execute("""create or replace view report_crm_case_service_dashboard as (
3748 select
3749@@ -195,12 +195,12 @@
3750 where
3751 ((to_date(to_char(cse.date_closed, 'YYYY-MM-dd'),'YYYY-MM-dd') <= CURRENT_DATE)
3752 AND
3753- (to_date(to_char(cse.date_closed, 'YYYY-MM-dd'),'YYYY-MM-dd') > (CURRENT_DATE-15))
3754+ (to_date(to_char(cse.date_closed, 'YYYY-MM-dd'),'YYYY-MM-dd') > (CURRENT_DATE-15))
3755 AND
3756 cse.state='done')
3757-
3758+
3759 OR
3760-
3761+
3762 ((to_date(to_char(cse.create_date, 'YYYY-MM-dd'),'YYYY-MM-dd') <= CURRENT_DATE)
3763 AND
3764 (to_date(to_char(cse.create_date, 'YYYY-MM-dd'),'YYYY-MM-dd') > (CURRENT_DATE-15))
3765@@ -211,4 +211,3 @@
3766
3767
3768 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
3769-
3770
3771=== modified file 'report_timesheet/report_timesheet.py'
3772--- report_timesheet/report_timesheet.py 2009-06-09 23:35:34 +0000
3773+++ report_timesheet/report_timesheet.py 2010-03-17 11:50:49 +0000
3774@@ -194,11 +194,11 @@
3775 account_analytic_line line, hr_department dept,hr_department_user_rel dept_user
3776 where
3777 (dept.id = dept_user.department_id AND dept_user.user_id=line.user_id AND line.user_id is not null)
3778- AND (dept.manager_id = """ + str(uid) + """ )
3779+ AND (dept.manager_id = %s)
3780 AND (line.date <= CURRENT_DATE AND line.date > (CURRENT_DATE-3))
3781 LIMIT 10
3782 )
3783- """ )
3784+ """, (uid,))
3785
3786 report_random_timsheet()
3787
3788
3789=== modified file 'sale/sale.py'
3790--- sale/sale.py 2010-03-02 11:50:52 +0000
3791+++ sale/sale.py 2010-03-17 11:50:49 +0000
3792@@ -101,8 +101,8 @@
3793 LEFT JOIN
3794 stock_picking p on (p.id=m.picking_id)
3795 WHERE
3796- p.sale_id in ('''+','.join(map(str, ids))+''')
3797- GROUP BY m.state, p.sale_id''')
3798+ p.sale_id in %s
3799+ GROUP BY m.state, p.sale_id''', (tuple(ids),))
3800 for oid, nbr, state in cr.fetchall():
3801 if state == 'cancel':
3802 continue
3803@@ -297,7 +297,7 @@
3804 def action_cancel_draft(self, cr, uid, ids, *args):
3805 if not len(ids):
3806 return False
3807- cr.execute('select id from sale_order_line where order_id in ('+','.join(map(str, ids))+')', ('draft',))
3808+ cr.execute('select id from sale_order_line where order_id in %s', (tuple(ids),))
3809 line_ids = map(lambda x: x[0], cr.fetchall())
3810 self.write(cr, uid, ids, {'state': 'draft', 'invoice_ids': [], 'shipped': 0})
3811 self.pool.get('sale.order.line').write(cr, uid, line_ids, {'invoiced': False, 'state': 'draft', 'invoice_lines': [(6, 0, [])]})
3812
3813=== modified file 'scrum/report/_burndown.py'
3814--- scrum/report/_burndown.py 2009-01-04 22:12:50 +0000
3815+++ scrum/report/_burndown.py 2010-03-17 11:50:49 +0000
3816@@ -26,15 +26,15 @@
3817
3818 def compute_burndown(cr, uid, tasks_id, date_start, date_stop):
3819 latest = False
3820- if len(tasks_id):
3821- cr.execute('select id,create_date,state,planned_hours from project_task where id in ('+','.join(map(str,tasks_id))+') order by create_date')
3822+ if tasks_id:
3823+ cr.execute('select id,create_date,state,planned_hours from project_task where id in %s order by create_date', (tuple(tasks_id),))
3824 tasks = cr.fetchall()
3825
3826- 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')
3827+ 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 (\'open\',\'progress\') order by date', (tuple(tasks_id),))
3828
3829 tasks2 = cr.fetchall()
3830
3831- 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')
3832+ cr.execute('select date_close,planned_hours from project_task where id in %s and state in (\'cancelled\',\'done\') order by date_close', (tuple(tasks_id),))
3833 tasks2 += cr.fetchall()
3834 tasks2.sort()
3835 else:
3836@@ -63,7 +63,4 @@
3837 result.append( (int(time.mktime(time.strptime(date_stop,'%Y-%m-%d'))), 0) )
3838 return result
3839
3840-
3841-
3842 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
3843-
3844
3845=== modified file 'scrum/report/task_burndown.py'
3846--- scrum/report/task_burndown.py 2009-01-04 22:12:50 +0000
3847+++ scrum/report/task_burndown.py 2010-03-17 11:50:49 +0000
3848@@ -43,9 +43,9 @@
3849
3850 def burndown_chart(cr, uid, tasks_id, date_start, date_stop):
3851 latest = False
3852- cr.execute('select id,date_start,state,planned_hours from project_task where id in ('+','.join(map(str,tasks_id))+') order by date_start')
3853+ cr.execute('select id,date_start,state,planned_hours from project_task where id in %s order by date_start', (tuple(tasks_id),))
3854 tasks = cr.fetchall()
3855- 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'))
3856+ 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'))
3857 tasks2 = cr.fetchall()
3858 current_date = date_start
3859 total = 0
3860@@ -72,14 +72,14 @@
3861 io = StringIO.StringIO()
3862
3863 if 'date_start' not in datas:
3864- cr.execute('select min(date_start) from project_task where id in ('+','.join(map(str,ids))+')')
3865+ cr.execute('select min(date_start) from project_task where id in %s', (tuple(ids),))
3866 dt = cr.fetchone()[0]
3867 if dt:
3868 datas['date_start'] = dt[:10]
3869 else:
3870 datas['date_start'] = time.strftime('%Y-%m-%d')
3871 if 'date_stop' not in datas:
3872- cr.execute('select max(date_start),max(date_close) from project_task where id in ('+','.join(map(str,ids))+')')
3873+ cr.execute('select max(date_start),max(date_close) from project_task where id in %s', (tuple(ids),))
3874 res = cr.fetchone()
3875 datas['date_stop'] = (res[0] and res[0][:10]) or time.strftime('%Y-%m-%d')
3876 if res[1] and datas['date_stop']<res[1]:
3877
3878=== modified file 'stock/product.py'
3879--- stock/product.py 2010-02-22 13:58:43 +0000
3880+++ stock/product.py 2010-03-17 11:50:49 +0000
3881@@ -89,37 +89,43 @@
3882
3883 from_date=context.get('from_date',False)
3884 to_date=context.get('to_date',False)
3885- date_str=False
3886+ date_str = ''
3887+ date_args = ()
3888 if from_date and to_date:
3889- date_str="date_planned>='%s' and date_planned<='%s'"%(from_date,to_date)
3890+ date_str = "and date_planned>=%s and date_planned<=%s"
3891+ date_args = (from_date, to_date)
3892 elif from_date:
3893- date_str="date_planned>='%s'"%(from_date)
3894+ date_str = "and date_planned>=%s"
3895+ date_args = (from_date,)
3896 elif to_date:
3897- date_str="date_planned<='%s'"%(to_date)
3898+ date_str = "and date_planned<=%s"
3899+ date_args = (to_date,)
3900
3901 if 'in' in what:
3902 # all moves from a location out of the set to a location in the set
3903 cr.execute(
3904 'select sum(product_qty), product_id, product_uom '\
3905 'from stock_move '\
3906- 'where location_id not in ('+location_ids_str+') '\
3907- 'and location_dest_id in ('+location_ids_str+') '\
3908- 'and product_id in ('+prod_ids_str+') '\
3909- 'and state in ('+states_str+') '+ (date_str and 'and '+date_str+' ' or '') +''\
3910- 'group by product_id,product_uom'
3911- )
3912+ 'where location_id not in %s '\
3913+ 'and location_dest_id in %s '\
3914+ 'and product_id in %s '\
3915+ 'and state in %s '+ date_str + ' '\
3916+ 'group by product_id,product_uom',
3917+ (tuple(location_ids), tuple(location_ids), tuple(ids),
3918+ tuple(states)) + date_args)
3919 results = cr.fetchall()
3920 if 'out' in what:
3921 # all moves from a location in the set to a location out of the set
3922 cr.execute(
3923 'select sum(product_qty), product_id, product_uom '\
3924 'from stock_move '\
3925- 'where location_id in ('+location_ids_str+') '\
3926- 'and location_dest_id not in ('+location_ids_str+') '\
3927- 'and product_id in ('+prod_ids_str+') '\
3928- 'and state in ('+states_str+') '+ (date_str and 'and '+date_str+' ' or '') + ''\
3929- 'group by product_id,product_uom'
3930- )
3931+ 'where location_id in %s '\
3932+ 'and location_dest_id not in %s '\
3933+ 'and product_id in %s '\
3934+ 'and state in %s '+ date_str + ' '\
3935+ 'group by product_id,product_uom',
3936+ (tuple(location_ids), tuple(location_ids), tuple(ids),
3937+ tuple(states)) + date_args)
3938 results2 = cr.fetchall()
3939 uom_obj = self.pool.get('product.uom')
3940 uoms = map(lambda x: x[2], results) + map(lambda x: x[2], results2)
3941
3942=== modified file 'stock/stock.py'
3943--- stock/stock.py 2010-03-12 11:08:43 +0000
3944+++ stock/stock.py 2010-03-17 11:50:49 +0000
3945@@ -368,13 +368,15 @@
3946 ids = [ids]
3947 for pick in self.browse(cr, uid, ids, context):
3948 sql_str = """update stock_move set
3949- date_planned='%s'
3950+ date_planned=%s
3951 where
3952- picking_id=%d """ % (value, pick.id)
3953+ picking_id=%s """
3954+ sqlargs = (value, pick.id)
3955
3956 if pick.max_date:
3957- sql_str += " and (date_planned='" + pick.max_date + "' or date_planned>'" + value + "')"
3958- cr.execute(sql_str)
3959+ sql_str += " and (date_planned=%s or date_planned>%s)"
3960+ sqlargs += (pick.max_date, value)
3961+ cr.execute(sql_str, sqlargs)
3962 return True
3963
3964 def _set_minimum_date(self, cr, uid, ids, name, value, arg, context):
3965@@ -384,12 +386,14 @@
3966 ids = [ids]
3967 for pick in self.browse(cr, uid, ids, context):
3968 sql_str = """update stock_move set
3969- date_planned='%s'
3970+ date_planned=%s
3971 where
3972- picking_id=%s """ % (value, pick.id)
3973+ picking_id=%s """
3974+ sqlargs = (value, pick.id)
3975 if pick.min_date:
3976- sql_str += " and (date_planned='" + pick.min_date + "' or date_planned<'" + value + "')"
3977- cr.execute(sql_str)
3978+ sql_str += " and (date_planned=%s or date_planned<%s)"
3979+ sqlargs += (pick.min_date, value)
3980+ cr.execute(sql_str, sqlargs)
3981 return True
3982
3983 def get_min_max_date(self, cr, uid, ids, field_name, arg, context={}):
3984@@ -405,9 +409,9 @@
3985 from
3986 stock_move
3987 where
3988- picking_id in (""" + ','.join(map(str, ids)) + """)
3989+ picking_id in %s
3990 group by
3991- picking_id""")
3992+ picking_id""", (tuple(ids),))
3993 for pick, dt1, dt2 in cr.fetchall():
3994 res[pick]['min_date'] = dt1
3995 res[pick]['max_date'] = dt2
3996@@ -841,11 +845,11 @@
3997 from
3998 stock_report_prodlots
3999 where
4000- location_id in ('''+','.join(map(str, locations))+''') and
4001- prodlot_id in ('''+','.join(map(str, ids))+''')
4002+ location_id in %s and
4003+ prodlot_id in %s
4004 group by
4005 prodlot_id
4006- ''')
4007+ ''', (tuple(locations), tuple(ids)))
4008 res.update(dict(cr.fetchall()))
4009 return res
4010
4011@@ -857,11 +861,11 @@
4012 from
4013 stock_report_prodlots
4014 where
4015- location_id in ('''+','.join(map(str, locations)) + ''')
4016+ location_id in %s
4017 group by
4018 prodlot_id
4019- having sum(name) ''' + str(args[0][1]) + ''' ''' + str(args[0][2])
4020- )
4021+ having sum(name) ''' + str(args[0][1]) + ' %s',
4022+ (tuple(locations), args[0][2]))
4023 res = cr.fetchall()
4024 ids = [('id', 'in', map(lambda x: x[0], res))]
4025 return ids
4026@@ -1204,7 +1208,6 @@
4027 r = res.pop(0)
4028 move_id = self.copy(cr, uid, move.id, {'product_qty': r[0], 'location_id': r[1]})
4029 done.append(move_id)
4030- #cr.execute('insert into stock_move_history_ids values (%s,%s)', (move.id,move_id))
4031 if done:
4032 count += len(done)
4033 self.write(cr, uid, done, {'state': 'assigned'})
4034@@ -1547,4 +1550,3 @@
4035 )""")
4036
4037 report_stock_lines_date()
4038-
4039
4040=== modified file 'stock/wizard/inventory_merge_zero.py'
4041--- stock/wizard/inventory_merge_zero.py 2009-04-09 10:02:19 +0000
4042+++ stock/wizard/inventory_merge_zero.py 2010-03-17 11:50:49 +0000
4043@@ -53,11 +53,11 @@
4044 raise wizard.except_wizard(_('Warning'),
4045 _('Please select one and only one inventory !'))
4046
4047- loc = str(data['form']['location_id'])
4048+ loc = data['form']['location_id']
4049
4050 cr.execute('select distinct location_id,product_id from stock_inventory_line where inventory_id=%s', (data['ids'][0],))
4051 inv = cr.fetchall()
4052- cr.execute('select distinct product_id from stock_move where (location_dest_id='+loc+') or (location_id='+loc+')')
4053+ cr.execute('select distinct product_id from stock_move where (location_dest_id=%(location_id)s) or (location_id=%(location_id)s)', data['form'])
4054 stock = cr.fetchall()
4055 for s in stock:
4056 if (loc,s[0]) not in inv:
4057
4058=== modified file 'wiki/wizard/make_index.py'
4059--- wiki/wizard/make_index.py 2009-04-09 10:02:19 +0000
4060+++ wiki/wizard/make_index.py 2010-03-17 11:50:49 +0000
4061@@ -35,10 +35,9 @@
4062 ids = data['ids']
4063 pool = pooler.get_pool(cr.dbname)
4064 wiki_pool = pool.get('wiki.wiki')
4065-
4066- iid = ','.join([str(x) for x in ids])
4067- sSQL = "Select id, section from wiki_wiki where id in (%s) order by section " % (iid)
4068- cr.execute(sSQL)
4069+
4070+ sSQL = "Select id, section from wiki_wiki where id in %s order by section "
4071+ cr.execute(sSQL, (tuple(ids),))
4072 lst0 = cr.fetchall()
4073 lst = []
4074 ids = {}