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
=== added file '.bzrignore'
--- .bzrignore 1970-01-01 00:00:00 +0000
+++ .bzrignore 2010-03-17 11:50:49 +0000
@@ -0,0 +1,1 @@
1./.ropeproject
02
=== modified file 'account/account.py'
--- account/account.py 2010-03-16 09:19:35 +0000
+++ account/account.py 2010-03-17 11:50:49 +0000
@@ -20,8 +20,10 @@
20#20#
21##############################################################################21##############################################################################
22import time22import time
23
24from operator import itemgetter
25
23import netsvc26import netsvc
24
25from osv import fields, osv27from osv import fields, osv
2628
27from tools.misc import currency29from tools.misc import currency
@@ -32,6 +34,26 @@
3234
33from tools import config35from tools import config
3436
37def check_cycle(self, cr, uid, ids):
38 """ climbs the ``self._table.parent_id`` chains for 100 levels or
39 until it can't find any more parent(s)
40
41 Returns true if it runs out of parents (no cycle), false if
42 it can recurse 100 times without ending all chains
43 """
44 level = 100
45 while len(ids):
46 cr.execute('SELECT DISTINCT parent_id '\
47 'FROM '+self._table+' '\
48 'WHERE id IN %s '\
49 'AND parent_id IS NOT NULL',
50 (tuple(ids),))
51 ids = map(itemgetter(0), cr.fetchall())
52 if not level:
53 return False
54 level -= 1
55 return True
56
35class account_payment_term(osv.osv):57class account_payment_term(osv.osv):
36 _name = "account.payment.term"58 _name = "account.payment.term"
37 _description = "Payment Term"59 _description = "Payment Term"
@@ -149,6 +171,7 @@
149 _name = "account.account"171 _name = "account.account"
150 _description = "Account"172 _description = "Account"
151 _parent_store = True173 _parent_store = True
174 logger = netsvc.Logger()
152175
153 def search(self, cr, uid, args, offset=0, limit=None, order=None,176 def search(self, cr, uid, args, offset=0, limit=None, order=None,
154 context=None, count=False):177 context=None, count=False):
@@ -195,19 +218,33 @@
195 ids3 = self._get_children_and_consol(cr, uid, ids3, context)218 ids3 = self._get_children_and_consol(cr, uid, ids3, context)
196 return ids2 + ids3219 return ids2 + ids3
197220
198 def __compute(self, cr, uid, ids, field_names, arg, context={}, query=''):221 def __compute(self, cr, uid, ids, field_names, arg=None, context=None,
199 #compute the balance/debit/credit accordingly to the value of field_name for the given account ids222 query='', query_params=()):
223 """ compute the balance, debit and/or credit for the provided
224 account ids
225
226 Arguments:
227 `ids`: account ids
228 `field_names`: the fields to compute (a list of any of
229 'balance', 'debit' and 'credit')
230 `arg`: unused fields.function stuff
231 `query`: additional query filter (as a string)
232 `query_params`: parameters for the provided query string
233 (__compute will handle their escaping) as a
234 tuple
235 """
200 mapping = {236 mapping = {
201 'balance': "COALESCE(SUM(l.debit),0) - COALESCE(SUM(l.credit), 0) as balance ",237 'balance': "COALESCE(SUM(l.debit),0) " \
202 'debit': "COALESCE(SUM(l.debit), 0) as debit ",238 "- COALESCE(SUM(l.credit), 0) as balance",
203 'credit': "COALESCE(SUM(l.credit), 0) as credit "239 'debit': "COALESCE(SUM(l.debit), 0) as debit",
240 'credit': "COALESCE(SUM(l.credit), 0) as credit"
204 }241 }
205 #get all the necessary accounts242 #get all the necessary accounts
206 ids2 = self._get_children_and_consol(cr, uid, ids, context)243 children_and_consolidated = self._get_children_and_consol(
207 acc_set = ",".join(map(str, ids2))244 cr, uid, ids, context=context)
208 #compute for each account the balance/debit/credit from the move lines245 #compute for each account the balance/debit/credit from the move lines
209 accounts = {}246 accounts = {}
210 if ids2:247 if children_and_consolidated:
211 aml_query = self.pool.get('account.move.line')._query_get(cr, uid, context=context)248 aml_query = self.pool.get('account.move.line')._query_get(cr, uid, context=context)
212249
213 wheres = [""]250 wheres = [""]
@@ -215,23 +252,33 @@
215 wheres.append(query.strip())252 wheres.append(query.strip())
216 if aml_query:253 if aml_query:
217 wheres.append(aml_query.strip())254 wheres.append(aml_query.strip())
218 query = " AND ".join(wheres)255 filters = " AND ".join(wheres)
219256 self.logger.notifyChannel('addons.'+self._name, netsvc.LOG_DEBUG,
220 cr.execute(("SELECT l.account_id as id, " +\257 'Filters: %s'%filters)
221 ' , '.join(map(lambda x: mapping[x], field_names)) +258 # IN might not work ideally in case there are too many
222 "FROM " \259 # children_and_consolidated, in that case join on a
223 "account_move_line l " \260 # values() e.g.:
224 "WHERE " \261 # SELECT l.account_id as id FROM account_move_line l
225 "l.account_id IN (%s) " \262 # INNER JOIN (VALUES (id1), (id2), (id3), ...) AS tmp (id)
226 + query +263 # ON l.account_id = tmp.id
227 " GROUP BY l.account_id") % (acc_set, ))264 # or make _get_children_and_consol return a query and join on that
265 request = ("SELECT l.account_id as id, " +\
266 ' , '.join(map(mapping.__getitem__, field_names)) +
267 " FROM account_move_line l" \
268 " WHERE l.account_id IN %s " \
269 + filters +
270 " GROUP BY l.account_id")
271 params = (tuple(children_and_consolidated),) + query_params
272 cr.execute(request, params)
273 self.logger.notifyChannel('addons.'+self._name, netsvc.LOG_DEBUG,
274 'Status: %s'%cr.statusmessage)
228275
229 for res in cr.dictfetchall():276 for res in cr.dictfetchall():
230 accounts[res['id']] = res277 accounts[res['id']] = res
231278
232
233 # consolidate accounts with direct children279 # consolidate accounts with direct children
234 brs = list(self.browse(cr, uid, ids2, context=context))280 brs = list(self.browse(cr, uid, children_and_consolidated,
281 context=context))
235 sums = {}282 sums = {}
236 while brs:283 while brs:
237 current = brs[0]284 current = brs[0]
@@ -341,8 +388,10 @@
341 if (obj_self in obj_self.child_consol_ids) or (p_id and (p_id is obj_self.id)):388 if (obj_self in obj_self.child_consol_ids) or (p_id and (p_id is obj_self.id)):
342 return False389 return False
343 while(ids):390 while(ids):
344 cr.execute('select distinct child_id from account_account_consol_rel where parent_id in ('+','.join(map(str, ids))+')')391 cr.execute('SELECT DISTINCT child_id '\
345 child_ids = filter(None, map(lambda x: x[0], cr.fetchall()))392 'FROM account_account_consol_rel '\
393 'WHERE parent_id IN %s', (tuple(ids),))
394 child_ids = map(itemgetter(0), cr.fetchall())
346 c_ids = child_ids395 c_ids = child_ids
347 if (p_id and (p_id in c_ids)) or (obj_self.id in c_ids):396 if (p_id and (p_id in c_ids)) or (obj_self.id in c_ids):
348 return False397 return False
@@ -767,7 +816,10 @@
767816
768 def _amount_compute(self, cr, uid, ids, name, args, context, where =''):817 def _amount_compute(self, cr, uid, ids, name, args, context, where =''):
769 if not ids: return {}818 if not ids: return {}
770 cr.execute('select move_id,sum(debit) from account_move_line where move_id in ('+','.join(map(str,ids))+') group by move_id')819 cr.execute('SELECT move_id, SUM(debit) '\
820 'FROM account_move_line '\
821 'WHERE move_id IN %s '\
822 'GROUP BY move_id', (tuple(ids),))
771 result = dict(cr.fetchall())823 result = dict(cr.fetchall())
772 for id in ids:824 for id in ids:
773 result.setdefault(id, 0.0)825 result.setdefault(id, 0.0)
@@ -862,7 +914,10 @@
862 if new_name:914 if new_name:
863 self.write(cr, uid, [move.id], {'name':new_name})915 self.write(cr, uid, [move.id], {'name':new_name})
864916
865 cr.execute('update account_move set state=%s where id in ('+','.join(map(str,ids))+')', ('posted',))917 cr.execute('UPDATE account_move '\
918 'SET state=%s '\
919 'WHERE id IN %s',
920 ('posted', tuple(ids)))
866 else:921 else:
867 raise osv.except_osv(_('Integrity Error !'), _('You can not validate a non-balanced entry !'))922 raise osv.except_osv(_('Integrity Error !'), _('You can not validate a non-balanced entry !'))
868 return True923 return True
@@ -875,7 +930,9 @@
875 if not line.journal_id.update_posted:930 if not line.journal_id.update_posted:
876 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.'))931 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.'))
877 if len(ids):932 if len(ids):
878 cr.execute('update account_move set state=%s where id in ('+','.join(map(str,ids))+')', ('draft',))933 cr.execute('UPDATE account_move '\
934 'SET state=%s '\
935 'WHERE id IN %s', ('draft', tuple(ids)))
879 return True936 return True
880937
881 def write(self, cr, uid, ids, vals, context={}):938 def write(self, cr, uid, ids, vals, context={}):
@@ -995,7 +1052,10 @@
995 else:1052 else:
996 line_id2 = 01053 line_id2 = 0
9971054
998 cr.execute('select sum('+mode+') from account_move_line where move_id=%s and id<>%s', (move.id, line_id2))1055 cr.execute('SELECT SUM(%s) '\
1056 'FROM account_move_line '\
1057 'WHERE move_id=%s AND id<>%s',
1058 (mode, move.id, line_id2))
999 result = cr.fetchone()[0] or 0.01059 result = cr.fetchone()[0] or 0.0
1000 cr.execute('update account_move_line set '+mode2+'=%s where id=%s', (result, line_id))1060 cr.execute('update account_move_line set '+mode2+'=%s where id=%s', (result, line_id))
1001 return True1061 return True
@@ -1143,25 +1203,28 @@
11431203
1144 This code is used for some tax declarations.1204 This code is used for some tax declarations.
1145 """1205 """
1146 def _sum(self, cr, uid, ids, name, args, context, where =''):1206 def _sum(self, cr, uid, ids, name, args, context,
1147 ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)])1207 where ='', where_params=()):
1148 acc_set = ",".join(map(str, ids2))1208 parent_ids = tuple(self.search(
1209 cr, uid, [('parent_id', 'child_of', ids)]))
1149 if context.get('based_on', 'invoices') == 'payments':1210 if context.get('based_on', 'invoices') == 'payments':
1150 cr.execute('SELECT line.tax_code_id, sum(line.tax_amount) \1211 cr.execute('SELECT line.tax_code_id, sum(line.tax_amount) \
1151 FROM account_move_line AS line, \1212 FROM account_move_line AS line, \
1152 account_move AS move \1213 account_move AS move \
1153 LEFT JOIN account_invoice invoice ON \1214 LEFT JOIN account_invoice invoice ON \
1154 (invoice.move_id = move.id) \1215 (invoice.move_id = move.id) \
1155 WHERE line.tax_code_id in ('+acc_set+') '+where+' \1216 WHERE line.tax_code_id in %s '+where+' \
1156 AND move.id = line.move_id \1217 AND move.id = line.move_id \
1157 AND ((invoice.state = \'paid\') \1218 AND ((invoice.state = \'paid\') \
1158 OR (invoice.id IS NULL)) \1219 OR (invoice.id IS NULL)) \
1159 GROUP BY line.tax_code_id')1220 GROUP BY line.tax_code_id',
1221 (parent_ids,)+where_params)
1160 else:1222 else:
1161 cr.execute('SELECT line.tax_code_id, sum(line.tax_amount) \1223 cr.execute('SELECT line.tax_code_id, sum(line.tax_amount) \
1162 FROM account_move_line AS line \1224 FROM account_move_line AS line \
1163 WHERE line.tax_code_id in ('+acc_set+') '+where+' \1225 WHERE line.tax_code_id in %s '+where+' \
1164 GROUP BY line.tax_code_id')1226 GROUP BY line.tax_code_id',
1227 (parent_ids,)+where_params)
1165 res=dict(cr.fetchall())1228 res=dict(cr.fetchall())
1166 for record in self.browse(cr, uid, ids, context):1229 for record in self.browse(cr, uid, ids, context):
1167 def _rec_get(record):1230 def _rec_get(record):
@@ -1178,12 +1241,14 @@
1178 else:1241 else:
1179 fiscalyear_id = self.pool.get('account.fiscalyear').find(cr, uid, exception=False)1242 fiscalyear_id = self.pool.get('account.fiscalyear').find(cr, uid, exception=False)
1180 where = ''1243 where = ''
1244 where_params = ()
1181 if fiscalyear_id:1245 if fiscalyear_id:
1182 pids = map(lambda x: str(x.id), self.pool.get('account.fiscalyear').browse(cr, uid, fiscalyear_id).period_ids)1246 pids = map(lambda x: str(x.id), self.pool.get('account.fiscalyear').browse(cr, uid, fiscalyear_id).period_ids)
1183 if pids:1247 if pids:
1184 where = ' and period_id in (' + (','.join(pids))+')'1248 where = ' and period_id in %s'
1249 where_params = (tuple(pids),)
1185 return self._sum(cr, uid, ids, name, args, context,1250 return self._sum(cr, uid, ids, name, args, context,
1186 where=where)1251 where=where, where_params=where_params)
11871252
1188 def _sum_period(self, cr, uid, ids, name, args, context):1253 def _sum_period(self, cr, uid, ids, name, args, context):
1189 if 'period_id' in context and context['period_id']:1254 if 'period_id' in context and context['period_id']:
@@ -1194,7 +1259,8 @@
1194 return dict.fromkeys(ids, 0.0)1259 return dict.fromkeys(ids, 0.0)
1195 period_id = period_id[0]1260 period_id = period_id[0]
1196 return self._sum(cr, uid, ids, name, args, context,1261 return self._sum(cr, uid, ids, name, args, context,
1197 where=' and line.period_id='+str(period_id))1262 where=' and line.period_id=%s',
1263 where_params=(period_id,))
11981264
1199 _name = 'account.tax.code'1265 _name = 'account.tax.code'
1200 _description = 'Tax Code'1266 _description = 'Tax Code'
@@ -1240,6 +1306,7 @@
1240 'sign': lambda *args: 1.0,1306 'sign': lambda *args: 1.0,
1241 'notprintable': lambda *a: False,1307 'notprintable': lambda *a: False,
1242 }1308 }
1309<<<<<<< TREE
1243 def _check_recursion(self, cr, uid, ids):1310 def _check_recursion(self, cr, uid, ids):
1244 level = 1001311 level = 100
1245 while len(ids):1312 while len(ids):
@@ -1257,6 +1324,9 @@
1257 default.update({'line_ids': []})1324 default.update({'line_ids': []})
1258 return super(account_tax_code, self).copy(cr, uid, id, default, context)1325 return super(account_tax_code, self).copy(cr, uid, id, default, context)
1259 1326
1327=======
1328 _check_recursion = check_cycle
1329>>>>>>> MERGE-SOURCE
1260 _constraints = [1330 _constraints = [
1261 (_check_recursion, 'Error ! You can not create recursive accounts.', ['parent_id'])1331 (_check_recursion, 'Error ! You can not create recursive accounts.', ['parent_id'])
1262 ]1332 ]
@@ -1869,16 +1939,7 @@
1869 'type' : lambda *a :'view',1939 'type' : lambda *a :'view',
1870 }1940 }
18711941
1872 def _check_recursion(self, cr, uid, ids):1942 _check_recursion = check_cycle
1873 level = 100
1874 while len(ids):
1875 cr.execute('select parent_id from account_account_template where id in ('+','.join(map(str,ids))+')')
1876 ids = filter(None, map(lambda x:x[0], cr.fetchall()))
1877 if not level:
1878 return False
1879 level -= 1
1880 return True
1881
1882 _constraints = [1943 _constraints = [
1883 (_check_recursion, 'Error ! You can not create recursive account templates.', ['parent_id'])1944 (_check_recursion, 'Error ! You can not create recursive account templates.', ['parent_id'])
1884 ]1945 ]
@@ -1928,16 +1989,7 @@
1928 return [(x['id'], (x['code'] and x['code'] + ' - ' or '') + x['name']) \1989 return [(x['id'], (x['code'] and x['code'] + ' - ' or '') + x['name']) \
1929 for x in reads]1990 for x in reads]
19301991
1931 def _check_recursion(self, cr, uid, ids):1992 _check_recursion = check_cycle
1932 level = 100
1933 while len(ids):
1934 cr.execute('select distinct parent_id from account_tax_code_template where id in ('+','.join(map(str,ids))+')')
1935 ids = filter(None, map(lambda x:x[0], cr.fetchall()))
1936 if not level:
1937 return False
1938 level -= 1
1939 return True
1940
1941 _constraints = [1993 _constraints = [
1942 (_check_recursion, 'Error ! You can not create recursive Tax Codes.', ['parent_id'])1994 (_check_recursion, 'Error ! You can not create recursive Tax Codes.', ['parent_id'])
1943 ]1995 ]
19441996
=== modified file 'account/account_move_line.py'
--- account/account_move_line.py 2010-03-04 11:50:58 +0000
+++ account/account_move_line.py 2010-03-17 11:50:49 +0000
@@ -257,9 +257,10 @@
257 for line_id in ids:257 for line_id in ids:
258 res[line_id] = False258 res[line_id] = False
259 cursor.execute('SELECT l.id, i.id ' \259 cursor.execute('SELECT l.id, i.id ' \
260 'FROM account_move_line l, account_invoice i ' \260 'FROM account_move_line l, account_invoice i ' \
261 'WHERE l.move_id = i.move_id ' \261 'WHERE l.move_id = i.move_id ' \
262 'AND l.id in (' + ','.join([str(x) for x in ids]) + ')')262 'AND l.id in %s',
263 (tuple(ids),))
263 invoice_ids = []264 invoice_ids = []
264 for line_id, invoice_id in cursor.fetchall():265 for line_id, invoice_id in cursor.fetchall():
265 res[line_id] = invoice_id266 res[line_id] = invoice_id
@@ -566,10 +567,11 @@
566 else:567 else:
567 date = time.strftime('%Y-%m-%d')568 date = time.strftime('%Y-%m-%d')
568569
569 cr.execute('SELECT account_id, reconcile_id \570 cr.execute('SELECT account_id, reconcile_id '\
570 FROM account_move_line \571 'FROM account_move_line '\
571 WHERE id IN ('+id_set+') \572 'WHERE id IN %s '\
572 GROUP BY account_id,reconcile_id')573 'GROUP BY account_id,reconcile_id',
574 (tuple(ids),))
573 r = cr.fetchall()575 r = cr.fetchall()
574#TODO: move this check to a constraint in the account_move_reconcile object576#TODO: move this check to a constraint in the account_move_reconcile object
575 if (len(r) != 1) and not context.get('fy_closing', False):577 if (len(r) != 1) and not context.get('fy_closing', False):
576578
=== modified file 'account/invoice.py'
--- account/invoice.py 2010-03-09 12:49:07 +0000
+++ account/invoice.py 2010-03-17 11:50:49 +0000
@@ -21,6 +21,8 @@
21##############################################################################21##############################################################################
2222
23import time23import time
24from operator import itemgetter
25
24import netsvc26import netsvc
25from osv import fields, osv27from osv import fields, osv
26import pooler28import pooler
@@ -428,12 +430,13 @@
428 def move_line_id_payment_get(self, cr, uid, ids, *args):430 def move_line_id_payment_get(self, cr, uid, ids, *args):
429 res = []431 res = []
430 if not ids: return res432 if not ids: return res
431 cr.execute('select \433 cr.execute('SELECT l.id '\
432 l.id \434 'FROM account_move_line l '\
433 from account_move_line l \435 'LEFT JOIN account_invoice i ON (i.move_id=l.move_id) '\
434 left join account_invoice i on (i.move_id=l.move_id) \436 'WHERE i.id IN %s '\
435 where i.id in ('+','.join(map(str,ids))+') and l.account_id=i.account_id')437 'AND l.account_id=i.account_id',
436 res = map(lambda x: x[0], cr.fetchall())438 (tuple(ids),))
439 res = map(itemgetter(0), cr.fetchall())
437 return res440 return res
438441
439 def copy(self, cr, uid, id, default=None, context=None):442 def copy(self, cr, uid, id, default=None, context=None):
@@ -714,8 +717,9 @@
714717
715 def action_number(self, cr, uid, ids, *args):718 def action_number(self, cr, uid, ids, *args):
716 cr.execute('SELECT id, type, number, move_id, reference ' \719 cr.execute('SELECT id, type, number, move_id, reference ' \
717 'FROM account_invoice ' \720 'FROM account_invoice ' \
718 'WHERE id IN ('+','.join(map(str,ids))+')')721 'WHERE id IN %s',
722 (tuple(ids),))
719 obj_inv = self.browse(cr, uid, ids)[0]723 obj_inv = self.browse(cr, uid, ids)[0]
720 for (id, invtype, number, move_id, reference) in cr.fetchall():724 for (id, invtype, number, move_id, reference) in cr.fetchall():
721 if not number:725 if not number:
@@ -949,7 +953,9 @@
949 line_ids = []953 line_ids = []
950 total = 0.0954 total = 0.0
951 line = self.pool.get('account.move.line')955 line = self.pool.get('account.move.line')
952 cr.execute('select id from account_move_line where move_id in ('+str(move_id)+','+str(invoice.move_id.id)+')')956 cr.execute('SELECT id FROM account_move_line '\
957 'WHERE move_id in %s',
958 ((move_id, invoice.move_id.id),))
953 lines = line.browse(cr, uid, map(lambda x: x[0], cr.fetchall()) )959 lines = line.browse(cr, uid, map(lambda x: x[0], cr.fetchall()) )
954 for l in lines+invoice.payment_ids:960 for l in lines+invoice.payment_ids:
955 if l.account_id.id==src_account_id:961 if l.account_id.id==src_account_id:
956962
=== modified file 'account/partner.py'
--- account/partner.py 2010-01-08 11:38:58 +0000
+++ account/partner.py 2010-03-17 11:50:49 +0000
@@ -19,6 +19,7 @@
19# along with this program. If not, see <http://www.gnu.org/licenses/>.19# along with this program. If not, see <http://www.gnu.org/licenses/>.
20#20#
21##############################################################################21##############################################################################
22from operator import itemgetter
2223
23from osv import fields, osv24from osv import fields, osv
24import ir25import ir
@@ -89,22 +90,19 @@
89 _name = 'res.partner'90 _name = 'res.partner'
90 _inherit = 'res.partner'91 _inherit = 'res.partner'
91 _description = 'Partner'92 _description = 'Partner'
93
92 def _credit_debit_get(self, cr, uid, ids, field_names, arg, context):94 def _credit_debit_get(self, cr, uid, ids, field_names, arg, context):
93 query = self.pool.get('account.move.line')._query_get(cr, uid, context=context)95 query = self.pool.get('account.move.line')._query_get(cr, uid, context=context)
94 cr.execute(("""select96 cr.execute("""SELECT l.partner_id, a.type, SUM(l.debit-l.credit)
95 l.partner_id, a.type, sum(l.debit-l.credit)97 FROM account_move_line l
96 from98 LEFT JOIN account_account a ON (l.account_id=a.id)
97 account_move_line l99 WHERE a.type IN ('receivable','payable')
98 left join100 AND l.partner_id in %s
99 account_account a on (l.account_id=a.id)101 AND l.reconcile_id IS NULL
100 where102 AND """ + query + """
101 a.type in ('receivable','payable') and103 GROUP BY l.partner_id, a.type
102 l.partner_id in (%s) and104 """,
103 l.reconcile_id is null and105 (tuple(ids),))
104 """ % (','.join(map(str, ids)),))+query+"""
105 group by
106 l.partner_id, a.type
107 """)
108 tinvert = {106 tinvert = {
109 'credit': 'receivable',107 'credit': 'receivable',
110 'debit': 'payable'108 'debit': 'payable'
@@ -118,27 +116,38 @@
118 res[pid][maps[type]] = (type=='receivable') and val or -val116 res[pid][maps[type]] = (type=='receivable') and val or -val
119 return res117 return res
120118
119 def _asset_difference_search(self, cr, uid, obj, name, type, args,
120 context=None):
121 if not len(args):
122 return []
123 having_values = tuple(map(itemgetter(2), args))
124 where = ' AND '.join(
125 map(lambda x: '(SUM(debit-credit) %(operator)s %%s)' % {
126 'operator':x[1]},
127 args))
128 query = self.pool.get('account.move.line')._query_get(cr, uid,
129 context=context)
130 cr.execute(('SELECT partner_id FROM account_move_line l '\
131 'WHERE account_id IN '\
132 '(SELECT id FROM account_account '\
133 'WHERE type=%s AND active) '\
134 'AND reconcile_id IS NULL '\
135 'AND '+query+' '\
136 'AND partner_id IS NOT NULL '\
137 'GROUP BY partner_id HAVING '+where),
138 (type,) + having_values)
139 res = cr.fetchall()
140 if not len(res):
141 return [('id','=','0')]
142 return [('id','in',map(itemgetter(0), res))]
143
121 def _credit_search(self, cr, uid, obj, name, args, context):144 def _credit_search(self, cr, uid, obj, name, args, context):
122 if not len(args):145 return self._asset_difference_search(
123 return []146 cr, uid, obj, name, 'receivable', args, context=context)
124 where = ' and '.join(map(lambda x: '(sum(debit-credit)'+x[1]+str(x[2])+')',args))
125 query = self.pool.get('account.move.line')._query_get(cr, uid, context={})
126 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',) )
127 res = cr.fetchall()
128 if not len(res):
129 return [('id','=','0')]
130 return [('id','in',map(lambda x:x[0], res))]
131147
132 def _debit_search(self, cr, uid, obj, name, args, context):148 def _debit_search(self, cr, uid, obj, name, args, context):
133 if not len(args):149 return self._asset_difference_search(
134 return []150 cr, uid, obj, name, 'payable', args, context=context)
135 query = self.pool.get('account.move.line')._query_get(cr, uid, context={})
136 where = ' and '.join(map(lambda x: '(sum(debit-credit)'+x[1]+str(x[2])+')',args))
137 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',) )
138 res = cr.fetchall()
139 if not len(res):
140 return [('id','=','0')]
141 return [('id','in',map(lambda x:x[0], res))]
142151
143 _columns = {152 _columns = {
144 'credit': fields.function(_credit_debit_get,153 'credit': fields.function(_credit_debit_get,
145154
=== modified file 'account/project/project.py'
--- account/project/project.py 2010-02-15 07:17:01 +0000
+++ account/project/project.py 2010-03-17 11:50:49 +0000
@@ -1,7 +1,7 @@
1# -*- encoding: utf-8 -*-1# -*- encoding: utf-8 -*-
2##############################################################################2##############################################################################
3#3#
4# OpenERP, Open Source Management Solution 4# OpenERP, Open Source Management Solution
5# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved5# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
6# $Id$6# $Id$
7#7#
@@ -19,10 +19,10 @@
19# along with this program. If not, see <http://www.gnu.org/licenses/>.19# along with this program. If not, see <http://www.gnu.org/licenses/>.
20#20#
21##############################################################################21##############################################################################
22
23import time22import time
24import operator23import operator
2524
25import netsvc
26from osv import fields26from osv import fields
27from osv import osv27from osv import osv
2828
@@ -33,47 +33,52 @@
33class account_analytic_account(osv.osv):33class account_analytic_account(osv.osv):
34 _name = 'account.analytic.account'34 _name = 'account.analytic.account'
35 _description = 'Analytic Accounts'35 _description = 'Analytic Accounts'
36 logger = netsvc.Logger()
3637
37 def _credit_calc(self, cr, uid, ids, name, arg, context={}):38 def _credit_calc(self, cr, uid, ids, name, arg, context={}):
38 r = {}39 self.logger.notifyChannel('addons.'+self._name, netsvc.LOG_DEBUG,
39 acc_set = ",".join(map(str, ids))40 'Entering _credit_calc; ids:%s'%ids)
40 41 if not ids: return {}
41 for i in ids:
42 r.setdefault(i,0.0)
43
44 if not acc_set:
45 return r
4642
47 where_date = ''43 where_date = ''
48 if context.get('from_date',False):44 if context.get('from_date'):
49 where_date += " AND l.date >= '" + context['from_date'] + "'"45 where_date += " AND l.date >= %(from_date)s"
50 if context.get('to_date',False):46 if context.get('to_date'):
51 where_date += " AND l.date <= '" + context['to_date'] + "'"47 where_date += " AND l.date <= %(to_date)s"
52 48
53 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))49 cr.execute("SELECT a.id, COALESCE(SUM(l.amount), 0) "
50 "FROM account_analytic_account a "
51 "LEFT JOIN account_analytic_line l ON (a.id=l.account_id %s)"
52 " WHERE l.amount < 0 AND a.id IN %%(ids)s "
53 "GROUP BY a.id" % (where_date),
54 dict(context, ids=tuple(ids)))
54 r = dict(cr.fetchall())55 r = dict(cr.fetchall())
56 self.logger.notifyChannel('addons.'+self._name, netsvc.LOG_DEBUG,
57 '_credit_calc results: %s'%r)
55 for i in ids:58 for i in ids:
56 r.setdefault(i,0.0)59 r.setdefault(i,0.0)
57 return r60 return r
5861
59 def _debit_calc(self, cr, uid, ids, name, arg, context={}):62 def _debit_calc(self, cr, uid, ids, name, arg, context={}):
60 r = {}63 self.logger.notifyChannel('addons.'+self._name, netsvc.LOG_DEBUG,
61 acc_set = ",".join(map(str, ids))64 'Entering _debit_calc; ids:%s'%ids)
65 if not ids: return {}
6266
63 for i in ids:
64 r.setdefault(i,0.0)
65
66 if not acc_set:
67 return r
68
69 where_date = ''67 where_date = ''
70 if context.get('from_date',False):68 if context.get('from_date'):
71 where_date += " AND l.date >= '" + context['from_date'] + "'"69 where_date += " AND l.date >= %(from_date)s"
72 if context.get('to_date',False):70 if context.get('to_date'):
73 where_date += " AND l.date <= '" + context['to_date'] + "'"71 where_date += " AND l.date <= %(to_date)s"
74 72
75 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))73 cr.execute("SELECT a.id, COALESCE(SUM(l.amount), 0) "
76 r= dict(cr.fetchall())74 "FROM account_analytic_account a "
75 "LEFT JOIN account_analytic_line l ON (a.id=l.account_id %s)"
76 " WHERE l.amount > 0 AND a.id IN %%(ids)s "
77 "GROUP BY a.id" % (where_date),
78 dict(context, ids=tuple(ids)))
79 r = dict(cr.fetchall())
80 self.logger.notifyChannel('addons.'+self._name, netsvc.LOG_DEBUG,
81 '_debut_calc results: %s'%r)
77 for i in ids:82 for i in ids:
78 r.setdefault(i,0.0)83 r.setdefault(i,0.0)
79 return r84 return r
@@ -81,35 +86,49 @@
81 def _balance_calc(self, cr, uid, ids, name, arg, context={}):86 def _balance_calc(self, cr, uid, ids, name, arg, context={}):
82 res = {}87 res = {}
83 ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)])88 ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)])
84 acc_set = ",".join(map(str, ids2))89 self.logger.notifyChannel('addons.'+self._name, netsvc.LOG_DEBUG,
85 90 'Entering _balance_calc; ids:%s; ids2:%s'%(
91 ids, ids2))
92
86 for i in ids:93 for i in ids:
87 res.setdefault(i,0.0)94 res.setdefault(i,0.0)
88 95
89 if not acc_set:96 if not ids2:
90 return res97 return res
91 98
92 where_date = ''99 where_date = ''
93 if context.get('from_date',False):100 if context.get('from_date'):
94 where_date += " AND l.date >= '" + context['from_date'] + "'"101 where_date += " AND l.date >= %(from_date)s"
95 if context.get('to_date',False):102 if context.get('to_date'):
96 where_date += " AND l.date <= '" + context['to_date'] + "'"103 where_date += " AND l.date <= %(to_date)s"
97 104
98 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))105 cr.execute("SELECT a.id, COALESCE(SUM(l.amount),0) "
99 106 "FROM account_analytic_account a "
107 "LEFT JOIN account_analytic_line l ON (a.id=l.account_id %s)"
108 " WHERE a.id IN %%(ids)s "
109 "GROUP BY a.id" % (where_date),
110 dict(context, ids=tuple(ids)))
111
100 for account_id, sum in cr.fetchall():112 for account_id, sum in cr.fetchall():
101 res[account_id] = sum113 res[account_id] = sum
102114 self.logger.notifyChannel('addons.'+self._name, netsvc.LOG_DEBUG,
103 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)115 '_balance_calc, (id, sum): %s'%res)
104116
105 currency= dict(cr.fetchall())117 cr.execute("SELECT a.id, r.currency_id "
118 "FROM account_analytic_account a "
119 "INNER JOIN res_company r ON (a.company_id = r.id) "
120 "WHERE a.id in %s", (tuple(ids),))
121
122 currency = dict(cr.fetchall())
123 self.logger.notifyChannel('addons.'+self._name, netsvc.LOG_DEBUG,
124 '_balance_calc currency: %s'%currency)
106125
107 res_currency= self.pool.get('res.currency')126 res_currency= self.pool.get('res.currency')
108 for id in ids:127 for id in ids:
109 if id not in ids2:128 if id not in ids2:
110 continue129 continue
111 for child in self.search(cr, uid, [('parent_id', 'child_of', [id])]):130 for child in self.search(cr, uid, [('parent_id', 'child_of', [id])]):
112 if child <> id:131 if child != id:
113 res.setdefault(id, 0.0)132 res.setdefault(id, 0.0)
114 if currency[child]<>currency[id]:133 if currency[child]<>currency[id]:
115 res[id] += res_currency.compute(cr, uid, currency[child], currency[id], res.get(child, 0.0), context=context)134 res[id] += res_currency.compute(cr, uid, currency[child], currency[id], res.get(child, 0.0), context=context)
@@ -125,36 +144,40 @@
125 return dict([(i, res[i]) for i in ids ])144 return dict([(i, res[i]) for i in ids ])
126145
127 def _quantity_calc(self, cr, uid, ids, name, arg, context={}):146 def _quantity_calc(self, cr, uid, ids, name, arg, context={}):
147 self.logger.notifyChannel('addons.'+self._name, netsvc.LOG_DEBUG,
148 '_quantity_calc ids:%s'%ids)
128 #XXX must convert into one uom149 #XXX must convert into one uom
129 res = {}150 res = {}
130 ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)])151 ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)])
131 acc_set = ",".join(map(str, ids2))152
132
133 for i in ids:153 for i in ids:
134 res.setdefault(i,0.0)154 res.setdefault(i,0.0)
135 155
136 if not acc_set:156 if not ids2:
137 return res157 return res
138 158
139 where_date = ''159 where_date = ''
140 if context.get('from_date',False):160 if context.get('from_date'):
141 where_date += " AND l.date >= '" + context['from_date'] + "'"161 where_date += " AND l.date >= %(from_date)s"
142 if context.get('to_date',False):162 if context.get('to_date'):
143 where_date += " AND l.date <= '" + context['to_date'] + "'"163 where_date += " AND l.date <= %(to_date)s"
144 164
145 cr.execute('SELECT a.id, COALESCE(SUM(l.unit_amount), 0) \165 cr.execute('SELECT a.id, COALESCE(SUM(l.unit_amount), 0) \
146 FROM account_analytic_account a \166 FROM account_analytic_account a \
147 LEFT JOIN account_analytic_line l ON (a.id = l.account_id ' + where_date + ') \167 LEFT JOIN account_analytic_line l ON (a.id = l.account_id %s) \
148 WHERE a.id IN ('+acc_set+') GROUP BY a.id')168 WHERE a.id IN %%(ids)s GROUP BY a.id'%(where_date),
169 dict(context, ids=tuple(ids2)))
149170
150 for account_id, sum in cr.fetchall():171 for account_id, sum in cr.fetchall():
151 res[account_id] = sum172 res[account_id] = sum
173 self.logger.notifyChannel('addons.'+self._name, netsvc.LOG_DEBUG,
174 '_quantity_calc, (id, sum): %s'%res)
152175
153 for id in ids:176 for id in ids:
154 if id not in ids2:177 if id not in ids2:
155 continue178 continue
156 for child in self.search(cr, uid, [('parent_id', 'child_of', [id])]):179 for child in self.search(cr, uid, [('parent_id', 'child_of', [id])]):
157 if child <> id:180 if child != id:
158 res.setdefault(id, 0.0)181 res.setdefault(id, 0.0)
159 res[id] += res.get(child, 0.0)182 res[id] += res.get(child, 0.0)
160 return dict([(i, res[i]) for i in ids])183 return dict([(i, res[i]) for i in ids])
@@ -299,4 +322,3 @@
299account_journal()322account_journal()
300323
301# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:324# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
302
303325
=== modified file 'account/project/report/analytic_balance.py'
--- account/project/report/analytic_balance.py 2009-10-09 11:49:00 +0000
+++ account/project/report/analytic_balance.py 2010-03-17 11:50:49 +0000
@@ -33,15 +33,9 @@
33 'get_objects': self._get_objects,33 'get_objects': self._get_objects,
34 'lines_g': self._lines_g,34 'lines_g': self._lines_g,
35 'move_sum': self._move_sum,35 'move_sum': self._move_sum,
36# 'move_sum_debit': self._move_sum_debit,
37# 'move_sum_credit': self._move_sum_credit,
38 'sum_all': self._sum_all,36 'sum_all': self._sum_all,
39# 'sum_debit': self._sum_debit,
40# 'sum_credit': self._sum_credit,
41 'sum_balance': self._sum_balance,37 'sum_balance': self._sum_balance,
42# 'sum_quantity': self._sum_quantity,
43 'move_sum_balance': self._move_sum_balance,38 'move_sum_balance': self._move_sum_balance,
44# 'move_sum_quantity': self._move_sum_quantity,
45 })39 })
46 self.acc_ids = []40 self.acc_ids = []
47 self.read_data = []41 self.read_data = []
@@ -82,10 +76,10 @@
82 sum(aal.amount) AS balance, sum(aal.unit_amount) AS quantity \76 sum(aal.amount) AS balance, sum(aal.unit_amount) AS quantity \
83 FROM account_analytic_line AS aal, account_account AS aa \77 FROM account_analytic_line AS aal, account_account AS aa \
84 WHERE (aal.general_account_id=aa.id) \78 WHERE (aal.general_account_id=aa.id) \
85 AND (aal.account_id in (" + ','.join(map(str, ids)) + "))\79 AND (aal.account_id in %s)\
86 AND (date>=%s) AND (date<=%s) AND aa.active \80 AND (date>=%s) AND (date<=%s) AND aa.active \
87 GROUP BY aal.general_account_id, aa.name, aa.code, aal.code \81 GROUP BY aal.general_account_id, aa.name, aa.code, aal.code \
88 ORDER BY aal.code", (date1, date2))82 ORDER BY aal.code", (tuple(ids), date1, date2))
89 res = self.cr.dictfetchall()83 res = self.cr.dictfetchall()
90 84
91 for r in res:85 for r in res:
@@ -108,62 +102,26 @@
108 self.acc_data_dict[account_id] = ids102 self.acc_data_dict[account_id] = ids
109 else:103 else:
110 ids = self.acc_data_dict[account_id]104 ids = self.acc_data_dict[account_id]
111 105
106 query_params = (tuple(ids), date1, date2)
112 if option == "credit" :107 if option == "credit" :
113 self.cr.execute("SELECT -sum(amount) FROM account_analytic_line \108 self.cr.execute("SELECT -sum(amount) FROM account_analytic_line \
114 WHERE account_id in ("+ ','.join(map(str, ids)) +") \109 WHERE account_id in %s \
115 AND date>=%s AND date<=%s AND amount<0",110 AND date>=%s AND date<=%s AND amount<0", query_params)
116 (date1, date2))
117 elif option == "debit" :111 elif option == "debit" :
118 self.cr.execute("SELECT sum(amount) FROM account_analytic_line \112 self.cr.execute("SELECT sum(amount) FROM account_analytic_line \
119 WHERE account_id in ("+ ','.join(map(str, ids)) +") \113 WHERE account_id in %s \
120 AND date>=%s AND date<=%s AND amount>0",114 AND date>=%s AND date<=%s AND amount>0", query_params)
121 (date1, date2))
122 elif option == "quantity" :115 elif option == "quantity" :
123 self.cr.execute("SELECT sum(unit_amount) FROM account_analytic_line \116 self.cr.execute("SELECT sum(unit_amount) FROM account_analytic_line \
124 WHERE account_id in ("+ ','.join(map(str, ids)) +") \117 WHERE account_id in %s \
125 AND date>=%s AND date<=%s",118 AND date>=%s AND date<=%s", query_params)
126 (date1, date2))
127 return self.cr.fetchone()[0] or 0.0119 return self.cr.fetchone()[0] or 0.0
128
129120
130# def _move_sum_debit(self, account_id, date1, date2):
131# account_analytic_obj = self.pool.get('account.analytic.account')
132# ids = account_analytic_obj.search(self.cr, self.uid,
133# [('parent_id', 'child_of', [account_id])])
134# self.cr.execute("SELECT sum(amount) \
135# FROM account_analytic_line \
136# WHERE account_id in ("+ ','.join(map(str, ids)) +") \
137# AND date>=%s AND date<=%s AND amount>0",
138# (date1, date2))
139# return self.cr.fetchone()[0] or 0.0
140#
141# def _move_sum_credit(self, account_id, date1, date2):
142# account_analytic_obj = self.pool.get('account.analytic.account')
143# ids = account_analytic_obj.search(self.cr, self.uid,
144# [('parent_id', 'child_of', [account_id])])
145# self.cr.execute("SELECT -sum(amount) \
146# FROM account_analytic_line \
147# WHERE account_id in ("+ ','.join(map(str, ids)) +") \
148# AND date>=%s AND date<=%s AND amount<0",
149# (date1, date2))
150# return self.cr.fetchone()[0] or 0.0
151#
152 def _move_sum_balance(self, account_id, date1, date2):121 def _move_sum_balance(self, account_id, date1, date2):
153 debit = self._move_sum(account_id, date1, date2, 'debit') 122 debit = self._move_sum(account_id, date1, date2, 'debit')
154 credit = self._move_sum(account_id, date1, date2, 'credit')123 credit = self._move_sum(account_id, date1, date2, 'credit')
155 return (debit-credit)124 return (debit-credit)
156
157# def _move_sum_quantity(self, account_id, date1, date2):
158# account_analytic_obj = self.pool.get('account.analytic.account')
159# ids = account_analytic_obj.search(self.cr, self.uid,
160# [('parent_id', 'child_of', [account_id])])
161# self.cr.execute("SELECT sum(unit_amount) \
162# FROM account_analytic_line \
163# WHERE account_id in ("+ ','.join(map(str, ids)) +") \
164# AND date>=%s AND date<=%s",
165# (date1, date2))
166# return self.cr.fetchone()[0] or 0.0
167125
168 def _sum_all(self, accounts, date1, date2, option):126 def _sum_all(self, accounts, date1, date2, option):
169 ids = map(lambda x: x['id'], accounts)127 ids = map(lambda x: x['id'], accounts)
@@ -178,72 +136,26 @@
178 else:136 else:
179 ids2 = self.acc_sum_list137 ids2 = self.acc_sum_list
180138
139 query_params = (tuple(ids2), date1, date2)
181 if option == "debit" :140 if option == "debit" :
182 self.cr.execute("SELECT sum(amount) FROM account_analytic_line \141 self.cr.execute("SELECT sum(amount) FROM account_analytic_line \
183 WHERE account_id IN ("+','.join(map(str, ids2))+") \142 WHERE account_id IN %s \
184 AND date>=%s AND date<=%s AND amount>0",143 AND date>=%s AND date<=%s AND amount>0", query_params)
185 (date1, date2))
186 elif option == "credit" :144 elif option == "credit" :
187 self.cr.execute("SELECT -sum(amount) FROM account_analytic_line \145 self.cr.execute("SELECT -sum(amount) FROM account_analytic_line \
188 WHERE account_id IN ("+','.join(map(str, ids2))+") \146 WHERE account_id IN %s \
189 AND date>=%s AND date<=%s AND amount<0",147 AND date>=%s AND date<=%s AND amount<0", query_params)
190 (date1, date2))
191 elif option == "quantity" :148 elif option == "quantity" :
192 self.cr.execute("SELECT sum(unit_amount) FROM account_analytic_line \149 self.cr.execute("SELECT sum(unit_amount) FROM account_analytic_line \
193 WHERE account_id IN ("+','.join(map(str, ids2))+") \150 WHERE account_id IN %s \
194 AND date>=%s AND date<=%s",151 AND date>=%s AND date<=%s", query_params)
195 (date1, date2))
196 return self.cr.fetchone()[0] or 0.0152 return self.cr.fetchone()[0] or 0.0
197153
198
199# def _sum_debit(self, accounts, date1, date2):
200# ids = map(lambda x: x['id'], accounts)
201# if not len(ids):
202# return 0.0
203# account_analytic_obj = self.pool.get('account.analytic.account')
204# ids2 = account_analytic_obj.search(self.cr, self.uid,
205# [('parent_id', 'child_of', ids)])
206# self.cr.execute("SELECT sum(amount) \
207# FROM account_analytic_line \
208# WHERE account_id IN ("+','.join(map(str, ids2))+") \
209# AND date>=%s AND date<=%s AND amount>0",
210# (date1, date2))
211# return self.cr.fetchone()[0] or 0.0
212#
213# def _sum_credit(self, accounts, date1, date2):
214# ids = map(lambda x: x['id'], accounts)
215# if not len(ids):
216# return 0.0
217# ids = map(lambda x: x['id'], accounts)
218# account_analytic_obj = self.pool.get('account.analytic.account')
219# ids2 = account_analytic_obj.search(self.cr, self.uid,
220# [('parent_id', 'child_of', ids)])
221# self.cr.execute("SELECT -sum(amount) \
222# FROM account_analytic_line \
223# WHERE account_id IN ("+','.join(map(str, ids2))+") \
224# AND date>=%s AND date<=%s AND amount<0",
225# (date1, date2))
226# return self.cr.fetchone()[0] or 0.0
227
228 def _sum_balance(self, accounts, date1, date2):154 def _sum_balance(self, accounts, date1, date2):
229 debit = self._sum_all(accounts, date1, date2, 'debit') or 0.0155 debit = self._sum_all(accounts, date1, date2, 'debit') or 0.0
230 credit = self._sum_all(accounts, date1, date2, 'credit') or 0.0156 credit = self._sum_all(accounts, date1, date2, 'credit') or 0.0
231 return (debit-credit)157 return (debit-credit)
232158
233# def _sum_quantity(self, accounts, date1, date2):
234# ids = map(lambda x: x['id'], accounts)
235# if not len(ids):
236# return 0.0
237# account_analytic_obj = self.pool.get('account.analytic.account')
238# ids2 = account_analytic_obj.search(self.cr, self.uid,
239# [('parent_id', 'child_of', ids)])
240# self.cr.execute("SELECT sum(unit_amount) \
241# FROM account_analytic_line \
242# WHERE account_id IN ("+','.join(map(str, ids2))+") \
243# AND date>=%s AND date<=%s",
244# (date1, date2))
245# return self.cr.fetchone()[0] or 0.0
246
247report_sxw.report_sxw('report.account.analytic.account.balance',159report_sxw.report_sxw('report.account.analytic.account.balance',
248 'account.analytic.account', 'addons/account/project/report/analytic_balance.rml',160 'account.analytic.account', 'addons/account/project/report/analytic_balance.rml',
249 parser=account_analytic_balance, header=False)161 parser=account_analytic_balance, header=False)
250162
=== modified file 'account/project/report/analytic_check.py'
--- account/project/report/analytic_check.py 2010-02-24 10:46:58 +0000
+++ account/project/report/analytic_check.py 2010-03-17 11:50:49 +0000
@@ -44,7 +44,6 @@
44 def _lines_p(self, date1, date2):44 def _lines_p(self, date1, date2):
45 res = []45 res = []
46 acc_obj = self.pool.get('account.account')46 acc_obj = self.pool.get('account.account')
47 # print"3333333acc_obj3333333",acc_obj.read(self.cr, self.uid, self.ids, ['name', 'code','user_type'])
4847
49 for a in acc_obj.read(self.cr, self.uid, self.ids, ['name', 'code']):48 for a in acc_obj.read(self.cr, self.uid, self.ids, ['name', 'code']):
50 self.cr.execute("SELECT sum(debit), sum(credit) \49 self.cr.execute("SELECT sum(debit), sum(credit) \
@@ -79,41 +78,6 @@
7978
80 return res79 return res
8180
82# def _lines_p(self, date1, date2):
83# res = []
84# acc_obj = self.pool.get('account.account')
85# for a in acc_obj.read(self.cr, self.uid, self.ids, ['name', 'code','sign']):
86# self.cr.execute("SELECT sum(debit), sum(credit) \
87# FROM account_move_line \
88# WHERE date>=%s AND date<=%s AND state<>'draft' AND account_id = %s", (date1, date2, a['id']))
89# (gd, gc) = self.cr.fetchone()
90# gd = gd or 0.0
91# gc = gc or 0.0
92#
93# self.cr.execute("SELECT abs(sum(amount)) AS balance \
94# FROM account_analytic_line \
95# WHERE date>=%s AND date<=%s AND amount*%s>0 AND general_account_id = %s", (date1, date2, a['sign'], a['id']))
96# (ad,) = self.cr.fetchone()
97# ad = ad or 0.0
98# self.cr.execute("SELECT abs(sum(amount)) AS balance \
99# FROM account_analytic_line \
100# WHERE date>=%s AND date<=%s AND amount*%s<0 AND general_account_id = %s", (date1, date2, a['sign'], a['id']))
101# (ac,) = self.cr.fetchone()
102# ac = ac or 0.0
103#
104# res.append({'code': a['code'], 'name': a['name'],
105# 'gen_debit': gd,
106# 'gen_credit': gc,
107# 'ana_debit': ad,
108# 'ana_credit': ac,
109# 'delta_debit': gd - ad,
110# 'delta_credit': gc - ac,})
111# self.sum_gen_deb += gd
112# self.sum_gen_cred += gc
113# self.sum_ana_deb += ad
114# self.sum_ana_cred += ac
115# return res
116
117 def _gen_deb(self, date1, date2):81 def _gen_deb(self, date1, date2):
118 return self.sum_gen_deb82 return self.sum_gen_deb
11983
@@ -134,5 +98,4 @@
13498
135report_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)99report_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)
136100
137
138# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:101# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
139102
=== modified file 'account/project/report/cost_ledger.py'
--- account/project/report/cost_ledger.py 2009-10-09 11:49:00 +0000
+++ account/project/report/cost_ledger.py 2010-03-17 11:50:49 +0000
@@ -94,15 +94,20 @@
94 ids = map(lambda x: x.id, accounts)94 ids = map(lambda x: x.id, accounts)
95 if not len(ids):95 if not len(ids):
96 return 0.096 return 0.0
97 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))97 self.cr.execute("SELECT SUM(amount) FROM account_analytic_line "
98 "WHERE account_id IN %s "
99 "AND date>=%s AND date<=%s AND amount>0",
100 (tuple(ids), date1, date2))
98 return self.cr.fetchone()[0] or 0.0101 return self.cr.fetchone()[0] or 0.0
99102
100 def _sum_credit(self, accounts, date1, date2):103 def _sum_credit(self, accounts, date1, date2):
101 ids = map(lambda x: x.id, accounts)104 ids = map(lambda x: x.id, accounts)
102 if not len(ids):105 if not len(ids):
103 return 0.0106 return 0.0
104 ids = map(lambda x: x.id, accounts)107 self.cr.execute("SELECT -SUM(amount) FROM account_analytic_line "
105 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))108 "WHERE account_id IN %s "
109 "AND date>=%s AND date<=%s AND amount<0",
110 (tuple(ids), date1, date2))
106 return self.cr.fetchone()[0] or 0.0111 return self.cr.fetchone()[0] or 0.0
107112
108 def _sum_balance(self, accounts, date1, date2):113 def _sum_balance(self, accounts, date1, date2):
@@ -112,6 +117,5 @@
112117
113report_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)118report_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)
114119
115
116# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:120# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
117121
118122
=== modified file 'account/project/report/inverted_analytic_balance.py'
--- account/project/report/inverted_analytic_balance.py 2009-10-09 11:49:00 +0000
+++ account/project/report/inverted_analytic_balance.py 2010-03-17 11:50:49 +0000
@@ -39,10 +39,16 @@
3939
40 def _lines_g(self, accounts, date1, date2):40 def _lines_g(self, accounts, date1, date2):
41 ids = map(lambda x: x.id, accounts)41 ids = map(lambda x: x.id, accounts)
42 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 \42 self.cr.execute("SELECT aa.name AS name, aa.code AS code, "
43 "sum(aal.amount) AS balance, "
44 "sum(aal.unit_amount) AS quantity, aa.id AS id \
43 FROM account_analytic_line AS aal, account_account AS aa \45 FROM account_analytic_line AS aal, account_account AS aa \
44 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 \46 WHERE (aal.general_account_id=aa.id) "
45 GROUP BY aal.general_account_id, aa.name, aa.code, aal.code, aa.id ORDER BY aal.code", (date1, date2))47 "AND (aal.account_id IN %s) "
48 "AND (date>=%s) AND (date<=%s) AND aa.active \
49 GROUP BY aal.general_account_id, aa.name, aa.code, aal.code, aa.id "
50 "ORDER BY aal.code",
51 (tuple(ids), date1, date2))
46 res = self.cr.dictfetchall()52 res = self.cr.dictfetchall()
4753
48 for r in res:54 for r in res:
@@ -59,10 +65,17 @@
5965
60 def _lines_a(self, accounts, general_account_id, date1, date2):66 def _lines_a(self, accounts, general_account_id, date1, date2):
61 ids = map(lambda x: x.id, accounts)67 ids = map(lambda x: x.id, accounts)
62 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 \68 self.cr.execute("SELECT sum(aal.amount) AS balance, "
63 FROM account_analytic_line AS aal, account_analytic_account AS aaa \69 "sum(aal.unit_amount) AS quantity, "
64 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 \70 "aaa.code AS code, aaa.name AS name, account_id \
65 GROUP BY aal.account_id, general_account_id, aaa.code, aaa.name ORDER BY aal.account_id", (general_account_id, date1, date2))71 FROM account_analytic_line AS aal, "
72 "account_analytic_account AS aaa \
73 WHERE aal.account_id=aaa.id AND aal.account_id IN %s "
74 "AND aal.general_account_id=%s AND aal.date>=%s "
75 "AND aal.date<=%s \
76 GROUP BY aal.account_id, general_account_id, aaa.code, aaa.name "
77 "ORDER BY aal.account_id",
78 (tuple(ids), general_account_id, date1, date2))
66 res = self.cr.dictfetchall()79 res = self.cr.dictfetchall()
6780
68 aaa_obj = self.pool.get('account.analytic.account')81 aaa_obj = self.pool.get('account.analytic.account')
@@ -87,14 +100,16 @@
87 ids = map(lambda x: x.id, accounts)100 ids = map(lambda x: x.id, accounts)
88 self.cr.execute("SELECT sum(amount) \101 self.cr.execute("SELECT sum(amount) \
89 FROM account_analytic_line \102 FROM account_analytic_line \
90 WHERE account_id IN ("+','.join(map(str, ids))+") AND date>=%s AND date<=%s AND amount>0", (date1, date2))103 WHERE account_id IN %s AND date>=%s AND date<=%s AND amount>0",
104 (tuple(ids), date1, date2))
91 return self.cr.fetchone()[0] or 0.0105 return self.cr.fetchone()[0] or 0.0
92 106
93 def _sum_credit(self, accounts, date1, date2):107 def _sum_credit(self, accounts, date1, date2):
94 ids = map(lambda x: x.id, accounts)108 ids = map(lambda x: x.id, accounts)
95 self.cr.execute("SELECT -sum(amount) \109 self.cr.execute("SELECT -sum(amount) \
96 FROM account_analytic_line \110 FROM account_analytic_line \
97 WHERE account_id IN ("+','.join(map(str, ids))+") AND date>=%s AND date<=%s AND amount<0", (date1, date2))111 WHERE account_id IN %s AND date>=%s AND date<=%s AND amount<0",
112 (tuple(ids), date1, date2))
98 return self.cr.fetchone()[0] or 0.0113 return self.cr.fetchone()[0] or 0.0
99114
100 def _sum_balance(self, accounts, date1, date2):115 def _sum_balance(self, accounts, date1, date2):
@@ -106,7 +121,8 @@
106 ids = map(lambda x: x.id, accounts)121 ids = map(lambda x: x.id, accounts)
107 self.cr.execute("SELECT sum(unit_amount) \122 self.cr.execute("SELECT sum(unit_amount) \
108 FROM account_analytic_line \123 FROM account_analytic_line \
109 WHERE account_id IN ("+','.join(map(str, ids))+") AND date>=%s AND date<=%s", (date1, date2))124 WHERE account_id IN %s AND date>=%s AND date<=%s",
125 (tuple(ids), date1, date2))
110 return self.cr.fetchone()[0] or 0.0126 return self.cr.fetchone()[0] or 0.0
111127
112report_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)128report_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)
113129
=== modified file 'account/project/report/quantity_cost_ledger.py'
--- account/project/report/quantity_cost_ledger.py 2009-10-09 11:49:00 +0000
+++ account/project/report/quantity_cost_ledger.py 2010-03-17 11:50:49 +0000
@@ -53,10 +53,9 @@
53 WHERE (aal.account_id=%s) AND (aal.date>=%s) \53 WHERE (aal.account_id=%s) AND (aal.date>=%s) \
54 AND (aal.date<=%s) AND (aal.general_account_id=aa.id) \54 AND (aal.date<=%s) AND (aal.general_account_id=aa.id) \
55 AND aa.active \55 AND aa.active \
56 AND (aal.journal_id IN (" +56 AND (aal.journal_id IN %s) \
57 ','.join(map(str, journal_ids)) + ")) \
58 GROUP BY aa.code, aa.name, aa.id ORDER BY aa.code",57 GROUP BY aa.code, aa.name, aa.id ORDER BY aa.code",
59 (account_id, date1, date2))58 (account_id, date1, date2, tuple(journal_ids)))
60 res = self.cr.dictfetchall()59 res = self.cr.dictfetchall()
61 return res60 return res
6261
@@ -81,10 +80,10 @@
81 account_analytic_journal AS aaj \80 account_analytic_journal AS aaj \
82 WHERE (aal.general_account_id=%s) AND (aal.account_id=%s) \81 WHERE (aal.general_account_id=%s) AND (aal.account_id=%s) \
83 AND (aal.date>=%s) AND (aal.date<=%s) \82 AND (aal.date>=%s) AND (aal.date<=%s) \
84 AND (aal.journal_id=aaj.id) AND (aaj.id IN (" +83 AND (aal.journal_id=aaj.id) AND (aaj.id IN %s) \
85 ','.join(map(str, journal_ids)) + ")) \
86 ORDER BY aal.date, aaj.code, aal.code",84 ORDER BY aal.date, aaj.code, aal.code",
87 (general_account_id, account_id, date1, date2))85 (general_account_id, account_id,
86 date1, date2, tuple(journal_ids)))
88 res = self.cr.dictfetchall()87 res = self.cr.dictfetchall()
89 return res88 return res
9089
@@ -99,9 +98,8 @@
99 self.cr.execute("SELECT sum(unit_amount) \98 self.cr.execute("SELECT sum(unit_amount) \
100 FROM account_analytic_line \99 FROM account_analytic_line \
101 WHERE account_id = %s AND date >= %s AND date <= %s \100 WHERE account_id = %s AND date >= %s AND date <= %s \
102 AND journal_id IN (" +101 AND journal_id IN %s",
103 ','.join(map(str, journal_ids)) + ")",102 (account_id, date1, date2, tuple(journal_ids)))
104 (account_id, date1, date2))
105 return self.cr.fetchone()[0] or 0.0103 return self.cr.fetchone()[0] or 0.0
106104
107 def _sum_quantity(self, accounts, date1, date2, journals):105 def _sum_quantity(self, accounts, date1, date2, journals):
@@ -111,18 +109,15 @@
111 if not journals or not journals[0][2]:109 if not journals or not journals[0][2]:
112 self.cr.execute("SELECT sum(unit_amount) \110 self.cr.execute("SELECT sum(unit_amount) \
113 FROM account_analytic_line \111 FROM account_analytic_line \
114 WHERE account_id IN (" +112 WHERE account_id IN %s AND date>=%s AND date<=%s",
115 ','.join(map(str, ids)) + ") AND date>=%s AND date<=%s",113 (tuple(ids), date1, date2))
116 (date1, date2))
117 else:114 else:
118 journal_ids = journals[0][2]115 journal_ids = journals[0][2]
119 self.cr.execute("SELECT sum(unit_amount) \116 self.cr.execute("SELECT sum(unit_amount) \
120 FROM account_analytic_line \117 FROM account_analytic_line \
121 WHERE account_id IN (" +118 WHERE account_id IN %s AND date >= %s AND date <= %s \
122 ','.join(map(str, ids)) + ") AND date >= %s AND date <= %s \119 AND journal_id IN %s",
123 AND journal_id IN (" +120 (tuple(ids), date1, date2, tuple(journal_ids)))
124 ','.join(map(str, journal_ids)) + ")",
125 (date1, date2))
126 return self.cr.fetchone()[0] or 0.0121 return self.cr.fetchone()[0] or 0.0
127122
128report_sxw.report_sxw('report.account.analytic.account.quantity_cost_ledger',123report_sxw.report_sxw('report.account.analytic.account.quantity_cost_ledger',
129124
=== modified file 'account/report/account_balance.py'
--- account/report/account_balance.py 2009-10-09 11:49:00 +0000
+++ account/report/account_balance.py 2010-03-17 11:50:49 +0000
@@ -104,10 +104,7 @@
104 ctx['periods'] = form['periods'][0][2]104 ctx['periods'] = form['periods'][0][2]
105 ctx['date_from'] = form['date_from']105 ctx['date_from'] = form['date_from']
106 ctx['date_to'] = form['date_to']106 ctx['date_to'] = form['date_to']
107# accounts = self.pool.get('account.account').browse(self.cr, self.uid, ids, ctx)107
108# def cmp_code(x, y):
109# return cmp(x.code, y.code)
110# accounts.sort(cmp_code)
111 child_ids = self.pool.get('account.account')._get_children_and_consol(self.cr, self.uid, ids, ctx)108 child_ids = self.pool.get('account.account')._get_children_and_consol(self.cr, self.uid, ids, ctx)
112 if child_ids:109 if child_ids:
113 ids = child_ids110 ids = child_ids
@@ -131,18 +128,7 @@
131 }128 }
132 self.sum_debit += account['debit']129 self.sum_debit += account['debit']
133 self.sum_credit += account['credit']130 self.sum_credit += account['credit']
134# if account.child_id:
135# def _check_rec(account):
136# if not account.child_id:
137# return bool(account.credit or account.debit)
138# for c in account.child_id:
139# if not _check_rec(c) or _check_rec(c):
140# return True
141# return False
142# if not _check_rec(account) :
143# continue
144 if account['parent_id']:131 if account['parent_id']:
145# acc = self.pool.get('account.account').read(self.cr, self.uid, [ account['parent_id'][0] ] ,['name'], ctx)
146 for r in result_acc:132 for r in result_acc:
147 if r['id'] == account['parent_id'][0]:133 if r['id'] == account['parent_id'][0]:
148 res['level'] = r['level'] + 1134 res['level'] = r['level'] + 1
@@ -155,16 +141,6 @@
155 result_acc.append(res)141 result_acc.append(res)
156 else:142 else:
157 result_acc.append(res)143 result_acc.append(res)
158# if account.child_id:
159# acc_id = [acc.id for acc in account.child_id]
160# lst_string = ''
161# lst_string = '\'' + '\',\''.join(map(str,acc_id)) + '\''
162# self.cr.execute("select code,id from account_account where id IN (%s)"%(lst_string))
163# a_id = self.cr.fetchall()
164# a_id.sort()
165# ids2 = [x[1] for x in a_id]
166#
167# result_acc += self.lines(form, ids2, done, level+1)
168 return result_acc144 return result_acc
169 145
170 def _sum_credit(self):146 def _sum_credit(self):
171147
=== modified file 'account/report/aged_trial_balance.py'
--- account/report/aged_trial_balance.py 2009-10-09 11:49:00 +0000
+++ account/report/aged_trial_balance.py 2010-03-17 11:50:49 +0000
@@ -1,7 +1,7 @@
1# -*- encoding: utf-8 -*-1# -*- encoding: utf-8 -*-
2##############################################################################2##############################################################################
3#3#
4# OpenERP, Open Source Management Solution 4# OpenERP, Open Source Management Solution
5# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved5# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
6# $Id$6# $Id$
7#7#
@@ -21,207 +21,213 @@
21##############################################################################21##############################################################################
2222
23import time23import time
24from operator import itemgetter
24import pooler25import pooler
25import rml_parse26import rml_parse
26from report import report_sxw27from report import report_sxw
2728
28class aged_trial_report(rml_parse.rml_parse):29class aged_trial_report(rml_parse.rml_parse):
2930
30 def __init__(self, cr, uid, name, context):31 def __init__(self, cr, uid, name, context):
31 super(aged_trial_report, self).__init__(cr, uid, name, context=context)32 super(aged_trial_report, self).__init__(cr, uid, name, context=context)
32 self.line_query = ''33 self.line_query = ''
33 self.total_account = []34 self.total_account = []
3435
3536
36 self.localcontext.update({37 self.localcontext.update({
37 'time': time,38 'time': time,
38 'get_lines': self._get_lines,39 'get_lines': self._get_lines,
39 'get_total': self._get_total,40 'get_total': self._get_total,
40 'get_direction': self._get_direction,41 'get_direction': self._get_direction,
41 'get_for_period': self._get_for_period,42 'get_for_period': self._get_for_period,
42 'get_company': self._get_company,43 'get_company': self._get_company,
43 'get_currency': self._get_currency,44 'get_currency': self._get_currency,
4445
45 })46 })
4647
4748
48 def _get_lines(self, form):49 def _get_lines(self, form):
4950
50 if (form['result_selection'] == 'customer' ):51 if (form['result_selection'] == 'customer' ):
51 self.ACCOUNT_TYPE = "('receivable')"52 self.ACCOUNT_TYPE = "('receivable')"
52 elif (form['result_selection'] == 'supplier'):53 elif (form['result_selection'] == 'supplier'):
53 self.ACCOUNT_TYPE = "('payable')"54 self.ACCOUNT_TYPE = "('payable')"
54 else:55 else:
55 self.ACCOUNT_TYPE = "('payable','receivable')"56 self.ACCOUNT_TYPE = "('payable','receivable')"
5657
5758
58 res = []59 res = []
59 account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')60 account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
60 self.line_query = account_move_line_obj._query_get(self.cr, self.uid, obj='line',61 self.line_query = account_move_line_obj._query_get(self.cr, self.uid, obj='line',
61 context={'fiscalyear': form['fiscalyear']})62 context={'fiscalyear': form['fiscalyear']})
62 self.cr.execute("""SELECT DISTINCT res_partner.id AS id, 63 self.cr.execute("""SELECT DISTINCT res_partner.id AS id,
63 res_partner.name AS name 64 res_partner.name AS name
64 FROM res_partner,account_move_line AS line, account_account 65 FROM res_partner,account_move_line AS line, account_account
65 WHERE (line.account_id=account_account.id) 66 WHERE (line.account_id=account_account.id)
66 AND ((reconcile_id IS NULL) 67 AND ((reconcile_id IS NULL)
67 OR (reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > '%s' ))) 68 OR (reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > '%s' )))
68 AND (line.partner_id=res_partner.id) 69 AND (line.partner_id=res_partner.id)
69 AND (account_account.company_id = %s) 70 AND (account_account.company_id = %s)
70 ORDER BY res_partner.name""" % (form['date1'],form['company_id']))71 ORDER BY res_partner.name""" % (form['date1'],form['company_id']))
71 partners = self.cr.dictfetchall()72 partners = self.cr.dictfetchall()
72 ## mise a 0 du total73 ## mise a 0 du total
73 for i in range(7):74 for i in range(7):
74 self.total_account.append(0)75 self.total_account.append(0)
75 #76
7677 partner_ids = tuple(map(attrgetter('id'), partners))
77 # Build a string like (1,2,3) for easy use in SQL query78 # This dictionary will store the debit-credit for all partners, using partner_id as key.
78 partner_ids = '(' + ','.join( [str(x['id']) for x in partners] ) + ')'79 totals = {}
7980 self.cr.execute("""SELECT partner_id, SUM(debit-credit)
80 # This dictionary will store the debit-credit for all partners, using partner_id as key.81 FROM account_move_line AS line, account_account
81 totals = {}82 WHERE (line.account_id = account_account.id)
82 self.cr.execute("""SELECT partner_id, SUM(debit-credit) 83 AND (account_account.type IN %s)
83 FROM account_move_line AS line, account_account84 AND (partner_id in %s)
84 WHERE (line.account_id = account_account.id) 85 AND ((reconcile_id IS NULL)
85 AND (account_account.type IN %s) 86 OR (reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > %s )))
86 AND (partner_id in %s) 87 AND (account_account.company_id = %s)
87 AND ((reconcile_id IS NULL)88 AND account_account.active
88 OR (reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > '%s' ))) 89 GROUP BY partner_id""" , (
89 AND (account_account.company_id = %s) 90 self.ACCOUNT_TYPE, partner_ids,
90 AND account_account.active 91 form['date1'],form['company_id']))
91 GROUP BY partner_id""" % (self.ACCOUNT_TYPE, partner_ids,form['date1'],form['company_id']))92 t = self.cr.fetchall()
92 t = self.cr.fetchall()93 for i in t:
93 for i in t:94 totals[i[0]] = i[1]
94 totals[i[0]] = i[1]95
9596 # This dictionary will store the future or past of all partners
96 # This dictionary will store the future or past of all partners97 future_past = {}
97 future_past = {}98 if form['direction_selection'] == 'future':
98 if form['direction_selection'] == 'future':99 self.cr.execute("""SELECT partner_id, SUM(debit-credit)
99 self.cr.execute("""SELECT partner_id, SUM(debit-credit) 100 FROM account_move_line AS line, account_account
100 FROM account_move_line AS line, account_account 101 WHERE (line.account_id=account_account.id)
101 WHERE (line.account_id=account_account.id) 102 AND (account_account.type IN %s)
102 AND (account_account.type IN %s) 103 AND (COALESCE(date_maturity,date) < %s)
103 AND (COALESCE(date_maturity,date) < '%s') 104 AND (partner_id in %s)
104 AND (partner_id in %s) 105 AND ((reconcile_id IS NULL)
105 AND ((reconcile_id IS NULL)106 OR (reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > %s )))
106 OR (reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > '%s' ))) 107 AND (account_account.company_id = %s)
107 AND (account_account.company_id = %s) 108 AND account_account.active
108 AND account_account.active 109 GROUP BY partner_id""", (
109 GROUP BY partner_id"""% (self.ACCOUNT_TYPE, form['date1'], partner_ids,form['date1'], form['company_id']))110 self.ACCOUNT_TYPE, form['date1'], partner_ids,
110 t = self.cr.fetchall()111 form['date1'], form['company_id']))
111 for i in t:112 t = self.cr.fetchall()
112 future_past[i[0]] = i[1]113 for i in t:
113 elif form['direction_selection'] == 'past': # Using elif so people could extend without this breaking114 future_past[i[0]] = i[1]
114 self.cr.execute("""SELECT partner_id, SUM(debit-credit)115 elif form['direction_selection'] == 'past': # Using elif so people could extend without this breaking
115 FROM account_move_line AS line, account_account116 self.cr.execute("""SELECT partner_id, SUM(debit-credit)
116 WHERE (line.account_id=account_account.id)117 FROM account_move_line AS line, account_account
117 AND (account_account.type IN %s)118 WHERE (line.account_id=account_account.id)
118 AND (COALESCE(date_maturity,date) > '%s')119 AND (account_account.type IN %s)
119 AND (partner_id in %s)120 AND (COALESCE(date_maturity,date) > %s)
120 AND ((reconcile_id IS NULL)121 AND (partner_id in %s)
121 OR (reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > '%s' )))122 AND ((reconcile_id IS NULL)
122 AND (account_account.company_id = %s)123 OR (reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > %s )))
123 AND account_account.active124 AND (account_account.company_id = %s)
124 GROUP BY partner_id""" % (self.ACCOUNT_TYPE, form['date1'], partner_ids, form['date1'], form['company_id']))125 AND account_account.active
125 t = self.cr.fetchall()126 GROUP BY partner_id""" , (
126 for i in t:127 self.ACCOUNT_TYPE, form['date1'], partner_ids,
127 future_past[i[0]] = i[1]128 form['date1'], form['company_id']))
128129 t = self.cr.fetchall()
129 # Use one query per period and store results in history (a list variable)130 for i in t:
130 # Each history will contain : history[1] = {'<partner_id>': <partner_debit-credit>}131 future_past[i[0]] = i[1]
131 history = []132
132 for i in range(5):133 # Use one query per period and store results in history (a list variable)
133 self.cr.execute("""SELECT partner_id, SUM(debit-credit)134 # Each history will contain : history[1] = {'<partner_id>': <partner_debit-credit>}
134 FROM account_move_line AS line, account_account135 history = []
135 WHERE (line.account_id=account_account.id)136 for i in range(5):
136 AND (account_account.type IN %s)137 self.cr.execute("""SELECT partner_id, SUM(debit-credit)
137 AND (COALESCE(date_maturity,date) BETWEEN '%s' AND '%s')138 FROM account_move_line AS line, account_account
138 AND (partner_id in %s )139 WHERE (line.account_id=account_account.id)
139 AND ((reconcile_id IS NULL)140 AND (account_account.type IN %s)
140 OR (reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > '%s' )))141 AND (COALESCE(date_maturity,date) BETWEEN %s AND %s)
141 AND (account_account.company_id = %s)142 AND (partner_id in %s )
142 AND account_account.active143 AND ((reconcile_id IS NULL)
143 GROUP BY partner_id""" % (self.ACCOUNT_TYPE, form[str(i)]['start'], form[str(i)]['stop'],partner_ids ,form['date1'] ,form['company_id']))144 OR (reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > %s )))
144145 AND (account_account.company_id = %s)
145 t = self.cr.fetchall()146 AND account_account.active
146 d = {}147 GROUP BY partner_id""" , (
147 for i in t:148 self.ACCOUNT_TYPE, form[str(i)]['start'], form[str(i)]['stop'],
148 d[i[0]] = i[1]149 partner_ids ,form['date1'] ,form['company_id']))
149 history.append(d)150
150151 t = self.cr.fetchall()
151 for partner in partners:152 d = {}
152 values = {}153 for i in t:
153 ## If choise selection is in the future154 d[i[0]] = i[1]
154 if form['direction_selection'] == 'future':155 history.append(d)
155 # Query here is replaced by one query which gets the all the partners their 'before' value156
156 before = False157 for partner in partners:
157 if future_past.has_key(partner['id']):158 values = {}
158 before = [ future_past[partner['id']] ]159 ## If choise selection is in the future
159160 if form['direction_selection'] == 'future':
160 self.total_account[6] = self.total_account[6] + (before and before[0] or 0.0)161 # Query here is replaced by one query which gets the all the partners their 'before' value
161162 before = False
162 values['direction'] = before and before[0] or 0.0163 if future_past.has_key(partner['id']):
163 elif form['direction_selection'] == 'past': # Changed this so people could in the future create new direction_selections164 before = [ future_past[partner['id']] ]
164 # Query here is replaced by one query which gets the all the partners their 'after' value165
165 after = False166 self.total_account[6] = self.total_account[6] + (before and before[0] or 0.0)
166 if future_past.has_key(partner['id']): # Making sure this partner actually was found by the query167
167 after = [ future_past[partner['id']] ]168 values['direction'] = before and before[0] or 0.0
168169 elif form['direction_selection'] == 'past': # Changed this so people could in the future create new direction_selections
169 self.total_account[6] = self.total_account[6] + (after and after[0] or 0.0)170 # Query here is replaced by one query which gets the all the partners their 'after' value
170 values['direction'] = after and after[0] or ""171 after = False
171172 if future_past.has_key(partner['id']): # Making sure this partner actually was found by the query
172 for i in range(5):173 after = [ future_past[partner['id']] ]
173 during = False174
174 if history[i].has_key(partner['id']):175 self.total_account[6] = self.total_account[6] + (after and after[0] or 0.0)
175 during = [ history[i][partner['id']] ]176 values['direction'] = after and after[0] or ""
176 # Ajout du compteur177
177 self.total_account[(i)] = self.total_account[(i)] + (during and during[0] or 0)178 for i in range(5):
178 values[str(i)] = during and during[0] or ""179 during = False
179180 if history[i].has_key(partner['id']):
180 total = False181 during = [ history[i][partner['id']] ]
181 if totals.has_key( partner['id'] ):182 # Ajout du compteur
182 total = [ totals[partner['id']] ]183 self.total_account[(i)] = self.total_account[(i)] + (during and during[0] or 0)
183 values['total'] = total and total[0] or 0.0184 values[str(i)] = during and during[0] or ""
184 ## Add for total185
185 self.total_account[(i+1)] = self.total_account[(i+1)] + (total and total[0] or 0.0)186 total = False
186 values['name'] = partner['name']187 if totals.has_key( partner['id'] ):
187 #t = 0.0188 total = [ totals[partner['id']] ]
188 #for i in range(5)+['direction']:189 values['total'] = total and total[0] or 0.0
189 # t+= float(values.get(str(i), 0.0) or 0.0)190 ## Add for total
190 #values['total'] = t191 self.total_account[(i+1)] = self.total_account[(i+1)] + (total and total[0] or 0.0)
191192 values['name'] = partner['name']
192 if values['total']:193 #t = 0.0
193 res.append(values)194 #for i in range(5)+['direction']:
194195 # t+= float(values.get(str(i), 0.0) or 0.0)
195 total = 0.0196 #values['total'] = t
196 totals = {}197
197 for r in res:198 if values['total']:
198 total += float(r['total'] or 0.0)199 res.append(values)
199 for i in range(5)+['direction']:200
200 totals.setdefault(str(i), 0.0)201 total = 0.0
201 totals[str(i)] += float(r[str(i)] or 0.0)202 totals = {}
202 return res203 for r in res:
203204 total += float(r['total'] or 0.0)
204 def _get_total(self,pos):205 for i in range(5)+['direction']:
205 period = self.total_account[int(pos)]206 totals.setdefault(str(i), 0.0)
206 return period207 totals[str(i)] += float(r[str(i)] or 0.0)
207208 return res
208 def _get_direction(self,pos):209
209 period = self.total_account[int(pos)]210 def _get_total(self,pos):
210 return period211 period = self.total_account[int(pos)]
211212 return period
212 def _get_for_period(self,pos):213
213 period = self.total_account[int(pos)]214 def _get_direction(self,pos):
214 return period215 period = self.total_account[int(pos)]
215216 return period
216 def _get_company(self, form):217
217 return pooler.get_pool(self.cr.dbname).get('res.company').browse(self.cr, self.uid, form['company_id']).name218 def _get_for_period(self,pos):
218219 period = self.total_account[int(pos)]
219 def _get_currency(self, form):220 return period
220 return pooler.get_pool(self.cr.dbname).get('res.company').browse(self.cr, self.uid, form['company_id']).currency_id.name221
222 def _get_company(self, form):
223 return pooler.get_pool(self.cr.dbname).get('res.company').browse(self.cr, self.uid, form['company_id']).name
224
225 def _get_currency(self, form):
226 return pooler.get_pool(self.cr.dbname).get('res.company').browse(self.cr, self.uid, form['company_id']).currency_id.name
221227
222228
223report_sxw.report_sxw('report.account.aged_trial_balance', 'res.partner',229report_sxw.report_sxw('report.account.aged_trial_balance', 'res.partner',
224 'addons/account/report/aged_trial_balance.rml',parser=aged_trial_report,header=False)230 'addons/account/report/aged_trial_balance.rml',parser=aged_trial_report,header=False)
225231
226232
227# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:233# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
228234
=== modified file 'account/report/general_journal.py'
--- account/report/general_journal.py 2009-10-09 11:49:00 +0000
+++ account/report/general_journal.py 2010-03-17 11:50:49 +0000
@@ -19,7 +19,7 @@
19# along with this program. If not, see <http://www.gnu.org/licenses/>.19# along with this program. If not, see <http://www.gnu.org/licenses/>.
20#20#
21##############################################################################21##############################################################################
2222from operator import itemgetter
23import pooler23import pooler
24import time24import time
25from report import report_sxw25from report import report_sxw
@@ -42,10 +42,12 @@
4242
43 def set_context(self, objects, data, ids, report_type = None):43 def set_context(self, objects, data, ids, report_type = None):
44 super(journal_print, self).set_context(objects, data, ids, report_type)44 super(journal_print, self).set_context(objects, data, ids, report_type)
45 self.cr.execute('select period_id, journal_id from account_journal_period where id in (' + ','.join([str(id) for id in ids]) + ')')45 self.cr.execute('SELECT period_id, journal_id '
46 'FROM account_journal_period '
47 'WHERE id IN %s',
48 (tuple(ids),))
46 res = self.cr.fetchall()49 res = self.cr.fetchall()
47 self.period_ids = ','.join([str(x[0]) for x in res])50 self.period_ids, self.journal_ids = zip(*res)
48 self.journal_ids = ','.join([str(x[1]) for x in res])
4951
50 # returns a list of period objs52 # returns a list of period objs
51 def periods(self, journal_period_objs):53 def periods(self, journal_period_objs):
@@ -75,7 +77,14 @@
75 periods.append(data.period_id.id)77 periods.append(data.period_id.id)
76 for period in periods:78 for period in periods:
77 period_data = self.pool.get('account.period').browse(self.cr, self.uid, period)79 period_data = self.pool.get('account.period').browse(self.cr, self.uid, period)
78 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,))80 self.cr.execute(
81 'SELECT j.code, j.name, '
82 'SUM(l.debit) AS debit, SUM(l.credit) AS credit '
83 'FROM account_move_line l '
84 'LEFT JOIN account_journal j ON (l.journal_id=j.id) '
85 'WHERE period_id=%s AND journal_id IN %s '
86 'AND l.state<>\'draft\' '
87 'GROUP BY j.id, j.code, j.name', (period, tuple(journal_id)))
79 res = self.cr.dictfetchall()88 res = self.cr.dictfetchall()
80 res[0].update({'period_name':period_data.name})89 res[0].update({'period_name':period_data.name})
81 res[0].update({'pid':period})90 res[0].update({'pid':period})
@@ -83,45 +92,59 @@
83 return lines_data92 return lines_data
84 if not self.journal_ids:93 if not self.journal_ids:
85 return []94 return []
86 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,))95 self.cr.execute('SELECT j.code, j.name, '
96 'SUM(l.debit) AS debit, SUM(l.credit) AS credit '
97 'FROM account_move_line l '
98 'LEFT JOIN account_journal j ON (l.journal_id=j.id) '
99 'WHERE period_id=%s AND journal_id IN %s '
100 'AND l.state<>\'draft\' '
101 'GROUP BY j.id, j.code, j.name'
102 (period_id,tuple(self.journal_ids)))
87 res = self.cr.dictfetchall()103 res = self.cr.dictfetchall()
88 return res104 return res
89105
90 def _sum_debit_period(self, period_id,journal_id=None):106 def _sum_debit_period(self, period_id,journal_id=None):
91 if type(journal_id)==type([]):107 journals = journal_id or self.journal_ids
92 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,))108 if not journals:
93 return self.cr.fetchone()[0] or 0.0
94 if not self.journal_ids:
95 return 0.0109 return 0.0
96 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,))110 self.cr.execute('SELECT SUM(debit) FROM account_move_line '
97111 'WHERE period_id=%s AND journal_id IN %s '
112 'AND state<>\'draft\'',
113 (period_id, tuple(journals)))
98 return self.cr.fetchone()[0] or 0.0114 return self.cr.fetchone()[0] or 0.0
99115
100 def _sum_credit_period(self, period_id,journal_id=None):116 def _sum_credit_period(self, period_id,journal_id=None):
101 if type(journal_id)==type([]):117 journals = journal_id or self.journal_ids
102 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,))118 if not journals:
103 return self.cr.fetchone()[0] or 0.0
104 if not self.journal_ids:
105 return 0.0119 return 0.0
106 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,))120 self.cr.execute('SELECT SUM(credit) FROM account_move_line '
121 'WHERE period_id=%s AND journal_id IN %s '
122 'AND state<>\'draft\'',
123 (period_id,tuple(journals)))
107 return self.cr.fetchone()[0] or 0.0124 return self.cr.fetchone()[0] or 0.0
108125
109 def _sum_debit(self,period_id=None,journal_id=None):126 def _sum_debit(self,period_id=None,journal_id=None):
110 if type(period_id)==type([]):127 journals = journal_id or self.journal_ids
111 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\'')128 periods = period_id or self.period_ids
112 return self.cr.fetchone()[0] or 0.0129 if not (journals and periods):
113 if not self.journal_ids or not self.period_ids:
114 return 0.0130 return 0.0
115 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\'')131 self.cr.execute('SELECT SUM(debit) FROM account_move_line '
132 'WHERE period_id IN %s '
133 'AND journal_id IN %s '
134 'AND state<>\'draft\'',
135 (tuple(periods), tuple(journals)))
116 return self.cr.fetchone()[0] or 0.0136 return self.cr.fetchone()[0] or 0.0
117137
118 def _sum_credit(self,period_id=None,journal_id=None):138 def _sum_credit(self,period_id=None,journal_id=None):
119 if type(period_id)==type([]):139 periods = period_id or self.period_ids
120 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\'')140 journals = journal_id or self.journal_ids
121 return self.cr.fetchone()[0] or 0.0141 if not (periods and journals):
122 if not self.journal_ids or not self.period_ids:
123 return 0.0142 return 0.0
124 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\'')143 self.cr.execute('SELECT SUM(credit) FROM account_move_line '
144 'WHERE period_id IN %s '
145 'AND journal_id IN %s '
146 'AND state<>\'draft\'',
147 (tuple(periods), tuple(journals)))
125 return self.cr.fetchone()[0] or 0.0148 return self.cr.fetchone()[0] or 0.0
126report_sxw.report_sxw('report.account.general.journal', 'account.journal.period', 'addons/account/report/general_journal.rml',parser=journal_print)149report_sxw.report_sxw('report.account.general.journal', 'account.journal.period', 'addons/account/report/general_journal.rml',parser=journal_print)
127report_sxw.report_sxw('report.account.general.journal.wiz', 'account.journal.period', 'addons/account/report/wizard_general_journal.rml',parser=journal_print, header=False)150report_sxw.report_sxw('report.account.general.journal.wiz', 'account.journal.period', 'addons/account/report/wizard_general_journal.rml',parser=journal_print, header=False)
128151
=== modified file 'account/report/general_ledger.py'
--- account/report/general_ledger.py 2010-01-18 07:47:33 +0000
+++ account/report/general_ledger.py 2010-03-17 11:50:49 +0000
@@ -123,14 +123,15 @@
123 periods = form['periods'][0][2]123 periods = form['periods'][0][2]
124 if not periods:124 if not periods:
125 sql = """125 sql = """
126 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']) + """126 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
127 """127 """
128 sqlargs = (form['fiscalyear'],)
128 else:129 else:
129 periods_id = ','.join(map(str, periods))
130 sql = """130 sql = """
131 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 + """)131 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
132 """132 """
133 self.cr.execute(sql)133 sqlargs = (tuple(periods),)
134 self.cr.execute(sql, sqlargs)
134 res = self.cr.dictfetchall()135 res = self.cr.dictfetchall()
135 borne_min = res[0]['start_date']136 borne_min = res[0]['start_date']
136 borne_max = res[0]['stop_date']137 borne_max = res[0]['stop_date']
@@ -141,14 +142,21 @@
141 periods = form['periods'][0][2]142 periods = form['periods'][0][2]
142 if not periods:143 if not periods:
143 sql = """144 sql = """
144 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']) + """145 SELECT MIN(p.date_start) AS start_date,
146 MAX(p.date_stop) AS stop_date
147 FROM account_period AS p
148 WHERE p.fiscalyear_id = %s
145 """149 """
150 sqlargs = (form['fiscalyear'],)
146 else:151 else:
147 periods_id = ','.join(map(str, periods))
148 sql = """152 sql = """
149 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 + """)153 SELECT MIN(p.date_start) AS start_date,
154 MAX(p.date_stop) AS stop_date
155 FROM account_period AS p
156 WHERE p.id IN %s
150 """157 """
151 self.cr.execute(sql)158 sqlargs = (tuple(periods),)
159 self.cr.execute(sql, sqlargs)
152 res = self.cr.dictfetchall()160 res = self.cr.dictfetchall()
153 period_min = res[0]['start_date']161 period_min = res[0]['start_date']
154 period_max = res[0]['stop_date']162 period_max = res[0]['stop_date']
@@ -232,8 +240,12 @@
232 else:240 else:
233 ## We will now compute solde initiaux241 ## We will now compute solde initiaux
234 for move in res:242 for move in res:
235 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'] + "'"243 SOLDEINIT = "SELECT SUM(l.debit) AS sum_debit,"\
236 self.cr.execute(SOLDEINIT)244 " SUM(l.credit) AS sum_credit "\
245 "FROM account_move_line l "\
246 "WHERE l.account_id = %s "\
247 "AND l.date < %s AND l.date > %s"
248 self.cr.execute(SOLDEINIT, (move.id, self.borne_date['max_date'],self.borne_date['min_date']))
237 resultat = self.cr.dictfetchall()249 resultat = self.cr.dictfetchall()
238 if resultat[0] :250 if resultat[0] :
239 if resultat[0]['sum_debit'] == None:251 if resultat[0]['sum_debit'] == None:
@@ -354,7 +366,8 @@
354 return 0.0366 return 0.0
355 self.cr.execute("SELECT sum(debit) "\367 self.cr.execute("SELECT sum(debit) "\
356 "FROM account_move_line l "\368 "FROM account_move_line l "\
357 "WHERE l.account_id in ("+','.join(map(str, self.child_ids))+") AND "+self.query)369 "WHERE l.account_id in %s AND "+self.query,
370 (tuple(self.child_ids),))
358 sum_debit = self.cr.fetchone()[0] or 0.0371 sum_debit = self.cr.fetchone()[0] or 0.0
359 return sum_debit372 return sum_debit
360373
@@ -363,7 +376,8 @@
363 return 0.0376 return 0.0
364 self.cr.execute("SELECT sum(credit) "\377 self.cr.execute("SELECT sum(credit) "\
365 "FROM account_move_line l "\378 "FROM account_move_line l "\
366 "WHERE l.account_id in ("+','.join(map(str, self.child_ids))+") AND "+self.query)379 "WHERE l.account_id in %s AND "+self.query,
380 (tuple(self.child_ids),))
367 ## Add solde init to the result381 ## Add solde init to the result
368 #382 #
369 sum_credit = self.cr.fetchone()[0] or 0.0383 sum_credit = self.cr.fetchone()[0] or 0.0
@@ -374,7 +388,8 @@
374 return 0.0388 return 0.0
375 self.cr.execute("SELECT (sum(debit) - sum(credit)) as tot_solde "\389 self.cr.execute("SELECT (sum(debit) - sum(credit)) as tot_solde "\
376 "FROM account_move_line l "\390 "FROM account_move_line l "\
377 "WHERE l.account_id in ("+','.join(map(str, self.child_ids))+") AND "+self.query)391 "WHERE l.account_id in %s AND "+self.query,
392 (tuple(self.child_ids),))
378 sum_solde = self.cr.fetchone()[0] or 0.0393 sum_solde = self.cr.fetchone()[0] or 0.0
379 return sum_solde394 return sum_solde
380395
381396
=== modified file 'account/report/general_ledger_landscape.py'
--- account/report/general_ledger_landscape.py 2010-01-18 07:47:33 +0000
+++ account/report/general_ledger_landscape.py 2010-03-17 11:50:49 +0000
@@ -122,14 +122,15 @@
122 periods = form['periods'][0][2]122 periods = form['periods'][0][2]
123 if not periods:123 if not periods:
124 sql = """124 sql = """
125 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']) + """125 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
126 """126 """
127 sqlargs = (form['fiscalyear'],)
127 else:128 else:
128 periods_id = ','.join(map(str, periods))
129 sql = """129 sql = """
130 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 + """)130 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
131 """131 """
132 self.cr.execute(sql)132 sqlargs = (tuple(periods),)
133 self.cr.execute(sql, sqlargs)
133 res = self.cr.dictfetchall()134 res = self.cr.dictfetchall()
134 borne_min = res[0]['start_date']135 borne_min = res[0]['start_date']
135 borne_max = res[0]['stop_date']136 borne_max = res[0]['stop_date']
@@ -140,14 +141,15 @@
140 periods = form['periods'][0][2]141 periods = form['periods'][0][2]
141 if not periods:142 if not periods:
142 sql = """143 sql = """
143 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']) + """144 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
144 """145 """
146 sqlargs = (form['fiscalyear'],)
145 else:147 else:
146 periods_id = ','.join(map(str, periods))
147 sql = """148 sql = """
148 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 + """)149 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
149 """150 """
150 self.cr.execute(sql)151 sqlargs = (tuple(periods),)
152 self.cr.execute(sql, sqlargs)
151 res = self.cr.dictfetchall()153 res = self.cr.dictfetchall()
152 period_min = res[0]['start_date']154 period_min = res[0]['start_date']
153 period_max = res[0]['stop_date']155 period_max = res[0]['stop_date']
@@ -233,8 +235,8 @@
233 else:235 else:
234 ## We will now compute solde initiaux236 ## We will now compute solde initiaux
235 for move in res:237 for move in res:
236 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'] + "'"238 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"
237 self.cr.execute(SOLDEINIT)239 self.cr.execute(SOLDEINIT, (move.id, self.borne_date['max_date'], self.borne_date['min_date']))
238 resultat = self.cr.dictfetchall()240 resultat = self.cr.dictfetchall()
239 if resultat[0] :241 if resultat[0] :
240 if resultat[0]['sum_debit'] == None:242 if resultat[0]['sum_debit'] == None:
@@ -287,7 +289,7 @@
287 for l in res:289 for l in res:
288 line = self.pool.get('account.move.line').browse(self.cr, self.uid, l['id'])290 line = self.pool.get('account.move.line').browse(self.cr, self.uid, l['id'])
289 l['move'] = line.move_id.name291 l['move'] = line.move_id.name
290 self.cr.execute('Select id from account_invoice where move_id =%s'%(line.move_id.id))292 self.cr.execute('Select id from account_invoice where move_id =%s',(line.move_id.id,))
291 tmpres = self.cr.dictfetchall()293 tmpres = self.cr.dictfetchall()
292 if len(tmpres) > 0 :294 if len(tmpres) > 0 :
293 inv = self.pool.get('account.invoice').browse(self.cr, self.uid, tmpres[0]['id'])295 inv = self.pool.get('account.invoice').browse(self.cr, self.uid, tmpres[0]['id'])
@@ -355,7 +357,8 @@
355 return 0.0357 return 0.0
356 self.cr.execute("SELECT sum(debit) "\358 self.cr.execute("SELECT sum(debit) "\
357 "FROM account_move_line l "\359 "FROM account_move_line l "\
358 "WHERE l.account_id in ("+','.join(map(str, self.child_ids))+") AND "+self.query)360 "WHERE l.account_id in %s AND "+self.query,
361 (tuple(self.child_ids),))
359 sum_debit = self.cr.fetchone()[0] or 0.0362 sum_debit = self.cr.fetchone()[0] or 0.0
360 return sum_debit363 return sum_debit
361364
@@ -364,7 +367,8 @@
364 return 0.0367 return 0.0
365 self.cr.execute("SELECT sum(credit) "\368 self.cr.execute("SELECT sum(credit) "\
366 "FROM account_move_line l "\369 "FROM account_move_line l "\
367 "WHERE l.account_id in ("+','.join(map(str, self.child_ids))+") AND "+self.query)370 "WHERE l.account_id in %s AND "+self.query,
371 (tuple(self.child_ids),))
368 ## Add solde init to the result372 ## Add solde init to the result
369 #373 #
370 sum_credit = self.cr.fetchone()[0] or 0.0374 sum_credit = self.cr.fetchone()[0] or 0.0
@@ -375,7 +379,8 @@
375 return 0.0379 return 0.0
376 self.cr.execute("SELECT (sum(debit) - sum(credit)) as tot_solde "\380 self.cr.execute("SELECT (sum(debit) - sum(credit)) as tot_solde "\
377 "FROM account_move_line l "\381 "FROM account_move_line l "\
378 "WHERE l.account_id in ("+','.join(map(str, self.child_ids))+") AND "+self.query)382 "WHERE l.account_id in %s AND "+self.query,
383 (tuple(self.child_ids),))
379 sum_solde = self.cr.fetchone()[0] or 0.0384 sum_solde = self.cr.fetchone()[0] or 0.0
380 return sum_solde385 return sum_solde
381386
382387
=== modified file 'account/report/partner_balance.py'
--- account/report/partner_balance.py 2009-10-09 11:49:00 +0000
+++ account/report/partner_balance.py 2010-03-17 11:50:49 +0000
@@ -30,7 +30,6 @@
30 def __init__(self, cr, uid, name, context):30 def __init__(self, cr, uid, name, context):
31 super(partner_balance, self).__init__(cr, uid, name, context=context)31 super(partner_balance, self).__init__(cr, uid, name, context=context)
32 self.date_lst = []32 self.date_lst = []
33 self.date_lst_string = ''
34 self.account_ids = ''33 self.account_ids = ''
35 self.localcontext.update( {34 self.localcontext.update( {
36 'time': time,35 'time': time,
@@ -164,29 +163,23 @@
164163
165 self.transform_both_into_date_array(data)164 self.transform_both_into_date_array(data)
166165
167 ##
168 self.date_lst_string =''
169 if self.date_lst:
170 self.date_lst_string = '\'' + '\',\''.join(map(str,self.date_lst)) + '\''
171
172
173 ## Compute Code166 ## Compute Code
174 account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')167 account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
175 #168 #
176 if (data['form']['result_selection'] == 'customer' ):169 if (data['form']['result_selection'] == 'customer' ):
177 self.ACCOUNT_TYPE = "('receivable')"170 self.ACCOUNT_TYPE = ('receivable',)
178 elif (data['form']['result_selection'] == 'supplier'):171 elif (data['form']['result_selection'] == 'supplier'):
179 self.ACCOUNT_TYPE = "('payable')"172 self.ACCOUNT_TYPE = ('payable',)
180 else:173 else:
181 self.ACCOUNT_TYPE = "('payable','receivable')"174 self.ACCOUNT_TYPE = ('payable','receivable')
182 #175 #
183 self.cr.execute("SELECT a.id " \176 self.cr.execute("SELECT a.id " \
184 "FROM account_account a " \177 "FROM account_account a " \
185 "LEFT JOIN account_account_type t " \178 "LEFT JOIN account_account_type t " \
186 "ON (a.type = t.code) " \179 "ON (a.type = t.code) " \
187 "WHERE a.company_id = %s " \180 "WHERE a.company_id = %s " \
188 "AND a.type IN " + self.ACCOUNT_TYPE + " " \181 "AND a.type IN %s " \
189 "AND a.active", (data['form']['company_id'],))182 "AND a.active", (data['form']['company_id'],self.ACCOUNT_TYPE))
190 self.account_ids = ','.join([str(a) for (a,) in self.cr.fetchall()])183 self.account_ids = ','.join([str(a) for (a,) in self.cr.fetchall()])
191184
192 super(partner_balance, self).set_context(objects, data, ids, report_type)185 super(partner_balance, self).set_context(objects, data, ids, report_type)
@@ -196,7 +189,7 @@
196 account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')189 account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
197 full_account = []190 full_account = []
198 result_tmp = 0.0191 result_tmp = 0.0
199 if self.date_lst_string:192 if self.date_lst:
200 self.cr.execute(193 self.cr.execute(
201 "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, " \194 "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, " \
202 "CASE WHEN sum(debit) > sum(credit) " \195 "CASE WHEN sum(debit) > sum(credit) " \
@@ -210,16 +203,17 @@
210 "(SELECT sum(debit-credit) " \203 "(SELECT sum(debit-credit) " \
211 "FROM account_move_line l " \204 "FROM account_move_line l " \
212 "WHERE partner_id = p.id " \205 "WHERE partner_id = p.id " \
213 "AND l.date IN (" + self.date_lst_string + ") " \206 "AND l.date IN %s " \
214 "AND blocked = TRUE " \207 "AND blocked = TRUE " \
215 ") AS enlitige " \208 ") AS enlitige " \
216 "FROM account_move_line l LEFT JOIN res_partner p ON (l.partner_id=p.id) " \209 "FROM account_move_line l LEFT JOIN res_partner p ON (l.partner_id=p.id) " \
217 "JOIN account_account ac ON (l.account_id = ac.id)" \210 "JOIN account_account ac ON (l.account_id = ac.id)" \
218 "WHERE ac.type IN " + self.ACCOUNT_TYPE + " " \211 "WHERE ac.type IN %s " \
219 "AND l.date IN (" + self.date_lst_string + ") " \212 "AND l.date IN %s " \
220 "AND ac.company_id = "+ str(data['form']['company_id']) +" " \213 "AND ac.company_id = %s " \
221 "GROUP BY p.id, p.ref, p.name,l.account_id,ac.name,ac.code " \214 "GROUP BY p.id, p.ref, p.name,l.account_id,ac.name,ac.code " \
222 "ORDER BY l.account_id,p.name")215 "ORDER BY l.account_id,p.name",
216 (tuple(self.date_lst), self.ACCOUNT_TYPE, tuple(self.date_lst), data['form']['company_id']))
223 res = self.cr.dictfetchall()217 res = self.cr.dictfetchall()
224 for r in res:218 for r in res:
225 full_account.append(r)219 full_account.append(r)
@@ -352,12 +346,13 @@
352 account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')346 account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
353 result_tmp = 0.0347 result_tmp = 0.0
354 temp_res = 0.0348 temp_res = 0.0
355 if self.date_lst_string:349 if self.date_lst:
356 self.cr.execute(350 self.cr.execute(
357 "SELECT sum(debit) " \351 "SELECT sum(debit) " \
358 "FROM account_move_line AS l " \352 "FROM account_move_line AS l " \
359 "WHERE l.account_id IN (" + self.account_ids + ") " \353 "WHERE l.account_id IN (" + self.account_ids + ") " \
360 "AND l.date IN (" + self.date_lst_string + ") " )354 "AND l.date IN %s",
355 (tuple(self.date_lst),))
361 temp_res = float(self.cr.fetchone()[0] or 0.0)356 temp_res = float(self.cr.fetchone()[0] or 0.0)
362 result_tmp = result_tmp + temp_res357 result_tmp = result_tmp + temp_res
363358
@@ -370,12 +365,13 @@
370365
371 result_tmp = 0.0366 result_tmp = 0.0
372 temp_res = 0.0367 temp_res = 0.0
373 if self.date_lst_string:368 if self.date_lst:
374 self.cr.execute(369 self.cr.execute(
375 "SELECT sum(credit) " \370 "SELECT sum(credit) " \
376 "FROM account_move_line AS l " \371 "FROM account_move_line AS l " \
377 "WHERE l.account_id IN (" + self.account_ids + ") " \372 "WHERE l.account_id IN (" + self.account_ids + ") " \
378 "AND l.date IN (" + self.date_lst_string + ") " )373 "AND l.date IN %s",
374 (tuple(self.date_lst),))
379 temp_res = float(self.cr.fetchone()[0] or 0.0)375 temp_res = float(self.cr.fetchone()[0] or 0.0)
380 result_tmp = result_tmp + temp_res376 result_tmp = result_tmp + temp_res
381377
@@ -387,13 +383,14 @@
387 account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')383 account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
388 result_tmp = 0.0384 result_tmp = 0.0
389 temp_res = 0.0385 temp_res = 0.0
390 if self.date_lst_string:386 if self.date_lst:
391 self.cr.execute(387 self.cr.execute(
392 "SELECT sum(debit-credit) " \388 "SELECT sum(debit-credit) " \
393 "FROM account_move_line AS l " \389 "FROM account_move_line AS l " \
394 "WHERE l.account_id IN (" + self.account_ids + ") " \390 "WHERE l.account_id IN (" + self.account_ids + ") " \
395 "AND l.date IN (" + self.date_lst_string + ") " \391 "AND l.date IN %s " \
396 "AND l.blocked=TRUE " )392 "AND l.blocked=TRUE ",
393 (tuple(self.date_lst),))
397 temp_res = float(self.cr.fetchone()[0] or 0.0)394 temp_res = float(self.cr.fetchone()[0] or 0.0)
398 result_tmp = result_tmp + temp_res395 result_tmp = result_tmp + temp_res
399396
@@ -405,7 +402,7 @@
405 account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')402 account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
406 result_tmp = 0.0403 result_tmp = 0.0
407 a = 0.0404 a = 0.0
408 if self.date_lst_string:405 if self.date_lst:
409 self.cr.execute(406 self.cr.execute(
410 "SELECT CASE WHEN sum(debit) > sum(credit) " \407 "SELECT CASE WHEN sum(debit) > sum(credit) " \
411 "THEN sum(debit) - sum(credit) " \408 "THEN sum(debit) - sum(credit) " \
@@ -413,8 +410,9 @@
413 "END " \410 "END " \
414 "FROM account_move_line AS l " \411 "FROM account_move_line AS l " \
415 "WHERE l.account_id IN (" + self.account_ids + ") " \412 "WHERE l.account_id IN (" + self.account_ids + ") " \
416 "AND l.date IN (" + self.date_lst_string + ") " \413 "AND l.date IN %s " \
417 "GROUP BY l.partner_id")414 "GROUP BY l.partner_id",
415 (tuple(self.date_lst),))
418 a = self.cr.fetchone()[0]416 a = self.cr.fetchone()[0]
419417
420 if self.cr.fetchone() != None:418 if self.cr.fetchone() != None:
@@ -432,7 +430,7 @@
432430
433 result_tmp = 0.0431 result_tmp = 0.0
434 a = 0.0432 a = 0.0
435 if self.date_lst_string:433 if self.date_lst:
436 self.cr.execute(434 self.cr.execute(
437 "SELECT CASE WHEN sum(debit) < sum(credit) " \435 "SELECT CASE WHEN sum(debit) < sum(credit) " \
438 "THEN sum(credit) - sum(debit) " \436 "THEN sum(credit) - sum(debit) " \
@@ -440,8 +438,9 @@
440 "END " \438 "END " \
441 "FROM account_move_line AS l " \439 "FROM account_move_line AS l " \
442 "WHERE l.account_id IN (" + self.account_ids + ") " \440 "WHERE l.account_id IN (" + self.account_ids + ") " \
443 "AND l.date IN (" + self.date_lst_string + ") " \441 "AND l.date IN %s " \
444 "GROUP BY l.partner_id")442 "GROUP BY l.partner_id",
443 (tuple(self.date_lst),))
445 a = self.cr.fetchone()[0] or 0.0444 a = self.cr.fetchone()[0] or 0.0
446445
447 if self.cr.fetchone() != None:446 if self.cr.fetchone() != None:
448447
=== modified file 'account/report/tax_report.py'
--- account/report/tax_report.py 2009-10-09 11:49:00 +0000
+++ account/report/tax_report.py 2010-03-17 11:50:49 +0000
@@ -90,7 +90,7 @@
9090
91 def _get_general(self, tax_code_id,period_list ,company_id, based_on):91 def _get_general(self, tax_code_id,period_list ,company_id, based_on):
92 res=[]92 res=[]
93 period_sql_list = ','.join(map(str, period_list[0][2]))93 periods_ids = tuple(period_list[0][2])
94 if based_on == 'payments':94 if based_on == 'payments':
95 self.cr.execute('SELECT SUM(line.tax_amount) AS tax_amount, \95 self.cr.execute('SELECT SUM(line.tax_amount) AS tax_amount, \
96 SUM(line.debit) AS debit, \96 SUM(line.debit) AS debit, \
@@ -109,11 +109,11 @@
109 AND line.account_id = account.id \109 AND line.account_id = account.id \
110 AND account.company_id = %s \110 AND account.company_id = %s \
111 AND move.id = line.move_id \111 AND move.id = line.move_id \
112 AND line.period_id IN ('+ period_sql_list +') \112 AND line.period_id IN %s \
113 AND ((invoice.state = %s) \113 AND ((invoice.state = %s) \
114 OR (invoice.id IS NULL)) \114 OR (invoice.id IS NULL)) \
115 GROUP BY account.id,account.name,account.code', ('draft',tax_code_id,115 GROUP BY account.id,account.name,account.code',
116 company_id, 'paid'))116 ('draft',tax_code_id,company_id,periods_ids,'paid'))
117117
118 else :118 else :
119 self.cr.execute('SELECT SUM(line.tax_amount) AS tax_amount, \119 self.cr.execute('SELECT SUM(line.tax_amount) AS tax_amount, \
@@ -129,10 +129,10 @@
129 AND line.tax_code_id = %s \129 AND line.tax_code_id = %s \
130 AND line.account_id = account.id \130 AND line.account_id = account.id \
131 AND account.company_id = %s \131 AND account.company_id = %s \
132 AND line.period_id IN ('+ period_sql_list +') \132 AND line.period_id IN %s \
133 AND account.active \133 AND account.active \
134 GROUP BY account.id,account.name,account.code', ('draft',tax_code_id,134 GROUP BY account.id,account.name,account.code',
135 company_id))135 ('draft',tax_code_id,company_id,periods_ids))
136 res = self.cr.dictfetchall()136 res = self.cr.dictfetchall()
137 137
138 #AND line.period_id IN ('+ period_sql_list +') \138 #AND line.period_id IN ('+ period_sql_list +') \
139139
=== modified file 'account/wizard/wizard_account_balance_report.py'
--- account/wizard/wizard_account_balance_report.py 2009-09-07 07:09:31 +0000
+++ account/wizard/wizard_account_balance_report.py 2010-03-17 11:50:49 +0000
@@ -112,8 +112,8 @@
112112
113 def _check_date(self, cr, uid, data, context):113 def _check_date(self, cr, uid, data, context):
114 sql = """114 sql = """
115 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'])115 SELECT f.id, f.date_start, f.date_stop FROM account_fiscalyear f Where %s between f.date_start and f.date_stop """
116 cr.execute(sql)116 cr.execute(sql, (data['form']['date_from'],))
117 res = cr.dictfetchall()117 res = cr.dictfetchall()
118 if res:118 if res:
119 if (data['form']['date_to'] > res[0]['date_stop'] or data['form']['date_to'] < res[0]['date_start']):119 if (data['form']['date_to'] > res[0]['date_stop'] or data['form']['date_to'] < res[0]['date_start']):
120120
=== modified file 'account/wizard/wizard_general_ledger_report.py'
--- account/wizard/wizard_general_ledger_report.py 2009-09-07 07:09:31 +0000
+++ account/wizard/wizard_general_ledger_report.py 2010-03-17 11:50:49 +0000
@@ -106,8 +106,8 @@
106def _check_date(self, cr, uid, data, context):106def _check_date(self, cr, uid, data, context):
107 107
108 sql = """108 sql = """
109 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'])109 SELECT f.id, f.date_start, f.date_stop FROM account_fiscalyear f Where %s between f.date_start and f.date_stop """
110 cr.execute(sql)110 cr.execute(sql, (data['form']['date_from'],))
111 res = cr.dictfetchall()111 res = cr.dictfetchall()
112 if res:112 if res:
113 if (data['form']['date_to'] > res[0]['date_stop'] or data['form']['date_to'] < res[0]['date_start']):113 if (data['form']['date_to'] > res[0]['date_stop'] or data['form']['date_to'] < res[0]['date_start']):
114114
=== modified file 'account/wizard/wizard_open_closed_fiscalyear.py'
--- account/wizard/wizard_open_closed_fiscalyear.py 2009-01-27 11:15:46 +0000
+++ account/wizard/wizard_open_closed_fiscalyear.py 2010-03-17 11:50:49 +0000
@@ -43,16 +43,7 @@
43 period_journal = data_fyear.end_journal_period_id43 period_journal = data_fyear.end_journal_period_id
44 ids_move = pool.get('account.move').search(cr,uid,[('journal_id','=',period_journal.journal_id.id),('period_id','=',period_journal.period_id.id)])44 ids_move = pool.get('account.move').search(cr,uid,[('journal_id','=',period_journal.journal_id.id),('period_id','=',period_journal.period_id.id)])
45 if ids_move:45 if ids_move:
46 cr.execute('delete from account_move where id in ('+','.join(map(str,ids_move))+')')46 cr.execute('delete from account_move where id in %s', (tuple(ids_move),))
47 #cr.execute('UPDATE account_journal_period ' \
48 # 'SET state = %s ' \
49 # 'WHERE period_id IN (SELECT id FROM account_period WHERE fiscalyear_id = %s)',
50 # ('draft',data_fyear))
51 #cr.execute('UPDATE account_period SET state = %s ' \
52 # 'WHERE fiscalyear_id = %s', ('draft',data_fyear))
53 #cr.execute('UPDATE account_fiscalyear ' \
54 # 'SET state = %s, end_journal_period_id = null '\
55 # 'WHERE id = %s', ('draft',data_fyear))
56 return {}47 return {}
5748
58class open_closed_fiscal(wizard.interface):49class open_closed_fiscal(wizard.interface):
5950
=== modified file 'account/wizard/wizard_partner_balance_report.py'
--- account/wizard/wizard_partner_balance_report.py 2009-04-29 07:42:01 +0000
+++ account/wizard/wizard_partner_balance_report.py 2010-03-17 11:50:49 +0000
@@ -102,8 +102,8 @@
102 def _check_date(self, cr, uid, data, context):102 def _check_date(self, cr, uid, data, context):
103 103
104 sql = """104 sql = """
105 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'])105 SELECT f.id, f.date_start, f.date_stop FROM account_fiscalyear f Where %s between f.date_start and f.date_stop """
106 cr.execute(sql)106 cr.execute(sql, (data['form']['date1'],))
107 res = cr.dictfetchall()107 res = cr.dictfetchall()
108 if res:108 if res:
109 if (data['form']['date2'] > res[0]['date_stop'] or data['form']['date2'] < res[0]['date_start']):109 if (data['form']['date2'] > res[0]['date_stop'] or data['form']['date2'] < res[0]['date_start']):
110110
=== modified file 'account/wizard/wizard_third_party_ledger.py'
--- account/wizard/wizard_third_party_ledger.py 2009-05-29 11:35:52 +0000
+++ account/wizard/wizard_third_party_ledger.py 2010-03-17 11:50:49 +0000
@@ -114,8 +114,8 @@
114 def _check_date(self, cr, uid, data, context):114 def _check_date(self, cr, uid, data, context):
115115
116 sql = """116 sql = """
117 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'])117 SELECT f.id, f.date_start, f.date_stop FROM account_fiscalyear f Where %s between f.date_start and f.date_stop """
118 cr.execute(sql)118 cr.execute(sql, (data['form']['date1'],))
119 res = cr.dictfetchall()119 res = cr.dictfetchall()
120 if res:120 if res:
121 if (data['form']['date2'] > res[0]['date_stop'] or data['form']['date2'] < res[0]['date_start']):121 if (data['form']['date2'] > res[0]['date_stop'] or data['form']['date2'] < res[0]['date_start']):
122122
=== modified file 'account_analytic_plans/report/crossovered_analytic.py'
--- account_analytic_plans/report/crossovered_analytic.py 2009-10-09 11:49:00 +0000
+++ account_analytic_plans/report/crossovered_analytic.py 2010-03-17 11:50:49 +0000
@@ -72,13 +72,19 @@
7272
73 self.dict_acc_ref = {}73 self.dict_acc_ref = {}
74 if form['journal_ids'][0][2]:74 if form['journal_ids'][0][2]:
75 journal = " in (" + ','.join(map(lambda x: str(x), form['journal_ids'][0][2])) + ")"75 journal_filter = "in %s"
76 sql_args = (tuple(form['journal_ids'][0][2]),)
76 else:77 else:
77 journal = 'is not null'78 journal_filter = 'is not null'
7879 sql_args = ()
79 query_general = "select id from account_analytic_line where (journal_id " + journal +") AND date>='"+ str(form['date1']) +"'"" AND date<='" + str(form['date2']) + "'"80
8081 query_general = "SELECT id FROM account_analytic_line "\
81 self.cr.execute(query_general)82 "WHERE (journal_id %s) "\
83 "AND date>=%%s "\
84 "AND date<=%%s"%(
85 journal_filter)
86
87 self.cr.execute(query_general, sql_args + (form['date1'], form['date2']))
82 l_ids=self.cr.fetchall()88 l_ids=self.cr.fetchall()
83 line_ids = [x[0] for x in l_ids]89 line_ids = [x[0] for x in l_ids]
8490
@@ -98,10 +104,16 @@
98 self.final_list = children_list104 self.final_list = children_list
99 selected_ids = line_pool.search(self.cr,self.uid,[('account_id','in',self.final_list)])105 selected_ids = line_pool.search(self.cr,self.uid,[('account_id','in',self.final_list)])
100106
101 query="SELECT sum(aal.amount) AS amt, sum(aal.unit_amount) AS qty FROM account_analytic_line AS aal, account_analytic_account AS aaa \107 query="SELECT SUM(aal.amount) AS amt, SUM(aal.unit_amount) AS qty "\
102 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']) + "'"108 "FROM account_analytic_line AS aal, account_analytic_account AS aaa "\
109 "WHERE aal.account_id=aaa.id "\
110 "AND aal.id IN %%s "\
111 "AND (aal.journal_id %s) "\
112 "AND aal.date>=%%s "\
113 "AND aal.date<=%%s"%(journal_filter)
103114
104 self.cr.execute(query)115 self.cr.execute(
116 query, (tuple(selected_ids),) + sql_args + (form['date1'],form['date2']))
105 info=self.cr.dictfetchall()117 info=self.cr.dictfetchall()
106118
107 res['ref_qty']=info[0]['qty']119 res['ref_qty']=info[0]['qty']
@@ -116,9 +128,11 @@
116 ids = self.ids128 ids = self.ids
117129
118 if form['journal_ids'][0][2]:130 if form['journal_ids'][0][2]:
119 journal=" in (" + ','.join(map(lambda x: str(x), form['journal_ids'][0][2])) + ")"131 journal_filter = " in %s"
132 sql_args = (tuple(form['journal_ids'][0][2]),)
120 else:133 else:
121 journal= 'is not null'134 journal_filter = 'is not null'
135 sql_args = ()
122136
123 acc_pool = self.pool.get('account.analytic.account')137 acc_pool = self.pool.get('account.analytic.account')
124 line_pool=self.pool.get('account.analytic.line')138 line_pool=self.pool.get('account.analytic.line')
@@ -132,10 +146,22 @@
132 for acc_id in self.final_list:146 for acc_id in self.final_list:
133 selected_ids = line_pool.search(self.cr,self.uid,[('account_id','=',acc_id),('move_id','in',self.dict_acc_ref[form['ref']])])147 selected_ids = line_pool.search(self.cr,self.uid,[('account_id','=',acc_id),('move_id','in',self.dict_acc_ref[form['ref']])])
134 if selected_ids:148 if selected_ids:
135 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 \149 query="SELECT aaa.code as code , SUM(aal.amount) AS amt, "\
136 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"150 "SUM(aal.unit_amount) AS qty, aaa.name AS acc_name, "\
151 "aal.account_id AS id "\
152 "FROM account_analytic_line AS aal, account_analytic_account AS aaa "\
153 "WHERE aal.account_id=aaa.id "\
154 "AND aal.id IN %%s "\
155 "AND (aal.journal_id %s) "\
156 "AND aal.date>=%%s "\
157 "AND aal.date<=%%s "\
158 "GROUP BY aal.account_id, aaa.name, aaa.code "\
159 "ORDER BY aal.account_id" % (
160 journal_filter
161 )
137162
138 self.cr.execute(query)163 self.cr.execute(query, (tuple(selected_ids),) + sql_args \
164 + (form['date1'], form['date2']))
139 res = self.cr.dictfetchall()165 res = self.cr.dictfetchall()
140 if res:166 if res:
141 for element in res:167 for element in res:
142168
=== modified file 'account_payment/account_move_line.py'
--- account_payment/account_move_line.py 2010-01-08 11:38:58 +0000
+++ account_payment/account_move_line.py 2010-03-17 11:50:49 +0000
@@ -19,7 +19,7 @@
19# along with this program. If not, see <http://www.gnu.org/licenses/>.19# along with this program. If not, see <http://www.gnu.org/licenses/>.
20#20#
21##############################################################################21##############################################################################
2222from operator import itemgetter
23from osv import fields, osv23from osv import fields, osv
24from tools.translate import _24from tools.translate import _
2525
@@ -43,7 +43,7 @@
43 WHERE move_line_id = ml.id43 WHERE move_line_id = ml.id
44 AND po.state != 'cancel') as amount44 AND po.state != 'cancel') as amount
45 FROM account_move_line ml45 FROM account_move_line ml
46 WHERE id in (%s)""" % (",".join(map(str, ids))))46 WHERE id in %s""", (tuple(ids),))
47 r=dict(cr.fetchall())47 r=dict(cr.fetchall())
48 return r48 return r
4949
@@ -59,8 +59,10 @@
59 END - coalesce(sum(pl.amount_currency), 0)59 END - coalesce(sum(pl.amount_currency), 0)
60 FROM payment_line pl60 FROM payment_line pl
61 INNER JOIN payment_order po ON (pl.order_id = po.id)61 INNER JOIN payment_order po ON (pl.order_id = po.id)
62 WHERE move_line_id = l.id AND po.state != 'cancel')''' \62 WHERE move_line_id = l.id
63 + x[1] + str(x[2])+' ',args))63 AND po.state != 'cancel'
64 ) %(operator)s %%s ''' % {'operator': x[1]}, args))
65 sql_args = tuple(map(itemgetter(2), args))
6466
65 cr.execute(('''select id67 cr.execute(('''select id
66 from account_move_line l68 from account_move_line l
@@ -69,7 +71,7 @@
69 where type=%s and active)71 where type=%s and active)
70 and reconcile_id is null72 and reconcile_id is null
71 and credit > 073 and credit > 0
72 and ''' + where + ' and ' + query), ('payable',) )74 and ''' + where + ' and ' + query), ('payable',)+sql_args )
7375
74 res = cr.fetchall()76 res = cr.fetchall()
75 if not len(res):77 if not len(res):
7678
=== modified file 'account_payment/payment.py'
--- account_payment/payment.py 2009-02-26 14:31:43 +0000
+++ account_payment/payment.py 2010-03-17 11:50:49 +0000
@@ -65,8 +65,6 @@
65 join payment_mode pm on (pm.type = pt.id)65 join payment_mode pm on (pm.type = pt.id)
66 where pm.id = %s """, [payment_code])66 where pm.id = %s """, [payment_code])
67 return [x[0] for x in cr.fetchall()]67 return [x[0] for x in cr.fetchall()]
68
69
70payment_mode()68payment_mode()
7169
7270
@@ -150,19 +148,8 @@
150 _name = 'payment.line'148 _name = 'payment.line'
151 _description = 'Payment Line'149 _description = 'Payment Line'
152150
153 #~ def partner_payable(self, cr, uid, ids, name, args, context={}):
154 #~ if not ids: return {}
155 #~ partners= self.read(cr, uid, ids, ['partner_id'], context)
156 #~ partners= dict(map(lambda x: (x['id'], x['partner_id'][0]), partners))
157 #~ debit = self.pool.get('res.partner')._debit_get(cr, uid,
158 #~ partners.values(), name, args, context)
159 #~ for i in partners:
160 #~ partners[i] = debit[partners[i]]
161 #~ return partners
162
163 def translate(self, orig):151 def translate(self, orig):
164 return {152 return {
165# "to_pay": "credit",
166 "due_date": "date_maturity",153 "due_date": "date_maturity",
167 "reference": "ref"}.get(orig, orig)154 "reference": "ref"}.get(orig, orig)
168155
@@ -224,8 +211,8 @@
224 from account_move_line ml211 from account_move_line ml
225 inner join payment_line pl212 inner join payment_line pl
226 on (ml.id = pl.move_line_id)213 on (ml.id = pl.move_line_id)
227 where pl.id in (%s)"""%214 where pl.id in %%s"""% self.translate(name),
228 (self.translate(name), ','.join(map(str,ids))) )215 (tuple(ids),))
229 res = dict(cr.fetchall())216 res = dict(cr.fetchall())
230217
231 if name == 'partner_id':218 if name == 'partner_id':
@@ -244,61 +231,6 @@
244 res.setdefault(id, (False, ""))231 res.setdefault(id, (False, ""))
245 return res232 return res
246233
247# def _currency(self, cursor, user, ids, name, args, context=None):
248# if not ids:
249# return {}
250# res = {}
251#
252# currency_obj = self.pool.get('res.currency')
253# account_obj = self.pool.get('account.account')
254# cursor.execute('''SELECT pl.id, ml.currency_id, ml.account_id
255# FROM account_move_line ml
256# INNER JOIN payment_line pl
257# ON (ml.id = pl.move_line_id)
258# WHERE pl.id in (''' + ','.join([str(x) for x in ids]) + ')')
259#
260# res2 = {}
261# account_ids = []
262# for payment_line_id, currency_id, account_id in cursor.fetchall():
263# res2[payment_line_id] = [currency_id, account_id]
264# account_ids.append(account_id)
265#
266# account2currency_id = {}
267# for account in account_obj.browse(cursor, user, account_ids,
268# context=context):
269# account2currency_id[account.id] = account.company_currency_id.id
270#
271# for payment_line_id in ids:
272# if res2[payment_line_id][0]:
273# res[payment_line_id] = res2[payment_line_id][0]
274# else:
275# res[payment_line_id] = \
276# account2currency_id[res2[payment_line_id][1]]
277#
278# currency_names = {}
279# for currency_id, name in currency_obj.name_get(cursor, user, res.values(),
280# context=context):
281# currency_names[currency_id] = name
282# for payment_line_id in ids:
283# res[payment_line_id] = (res[payment_line_id],
284# currency_names[res[payment_line_id]])
285# return res
286#
287# def _to_pay_currency(self, cursor, user, ids, name , args, context=None):
288# if not ids:
289# return {}
290#
291# cursor.execute('''SELECT pl.id,
292# CASE WHEN ml.amount_currency < 0
293# THEN - ml.amount_currency
294# ELSE ml.credit
295# END
296# FROM account_move_line ml
297# INNER JOIN payment_line pl
298# ON (ml.id = pl.move_line_id)
299# WHERE pl.id in (''' + ','.join([str(x) for x in ids]) + ')')
300# return dict(cursor.fetchall())
301
302 def _amount(self, cursor, user, ids, name, args, context=None):234 def _amount(self, cursor, user, ids, name, args, context=None):
303 if not ids:235 if not ids:
304 return {}236 return {}
@@ -334,15 +266,6 @@
334 else:266 else:
335 return self.pool.get('res.currency').search(cr, uid, [('rate','=',1.0)])[0]267 return self.pool.get('res.currency').search(cr, uid, [('rate','=',1.0)])[0]
336268
337# def select_move_lines(*a):
338# print a
339# return []
340
341# def create(self, cr, uid, vals, context):
342# print "created!!!"
343# vals['company_currency'] = self._get_currency(cr, uid, context)
344# return super(payment_line, self).create(cr, uid, vals, context)
345
346 def _get_ml_inv_ref(self, cr, uid, ids, *a):269 def _get_ml_inv_ref(self, cr, uid, ids, *a):
347 res={}270 res={}
348 for id in self.browse(cr, uid, ids):271 for id in self.browse(cr, uid, ids):
@@ -377,11 +300,6 @@
377 '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.'),300 '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.'),
378 'amount_currency': fields.float('Amount in Partner Currency', digits=(16,2),301 'amount_currency': fields.float('Amount in Partner Currency', digits=(16,2),
379 required=True, help='Payment amount in the partner currency'),302 required=True, help='Payment amount in the partner currency'),
380# 'to_pay_currency': fields.function(_to_pay_currency, string='To Pay',
381# method=True, type='float',
382# help='Amount to pay in the partner currency'),
383# 'currency': fields.function(_currency, string='Currency',
384# method=True, type='many2one', obj='res.currency'),
385 'currency': fields.many2one('res.currency','Partner Currency',required=True),303 'currency': fields.many2one('res.currency','Partner Currency',required=True),
386 'company_currency': fields.many2one('res.currency','Company Currency',readonly=True),304 'company_currency': fields.many2one('res.currency','Company Currency',readonly=True),
387 'bank_id': fields.many2one('res.partner.bank', 'Destination Bank account'),305 'bank_id': fields.many2one('res.partner.bank', 'Destination Bank account'),
@@ -391,21 +309,12 @@
391 'amount': fields.function(_amount, string='Amount in Company Currency',309 'amount': fields.function(_amount, string='Amount in Company Currency',
392 method=True, type='float',310 method=True, type='float',
393 help='Payment amount in the company currency'),311 help='Payment amount in the company currency'),
394# 'to_pay': fields.function(select_by_name, string="To Pay", method=True,
395# type='float', help='Amount to pay in the company currency'),
396# 'due_date': fields.function(select_by_name, string="Due date",
397# method=True, type='date'),
398 'ml_date_created': fields.function(_get_ml_created_date, string="Effective Date",312 'ml_date_created': fields.function(_get_ml_created_date, string="Effective Date",
399 method=True, type='date',help="Invoice Effective Date"),313 method=True, type='date',help="Invoice Effective Date"),
400# 'reference': fields.function(select_by_name, string="Ref", method=True,
401# type='char'),
402 'ml_maturity_date': fields.function(_get_ml_maturity_date, method=True, type='date', string='Maturity Date'),314 'ml_maturity_date': fields.function(_get_ml_maturity_date, method=True, type='date', string='Maturity Date'),
403 'ml_inv_ref': fields.function(_get_ml_inv_ref, method=True, type='many2one', relation='account.invoice', string='Invoice Ref.'),315 'ml_inv_ref': fields.function(_get_ml_inv_ref, method=True, type='many2one', relation='account.invoice', string='Invoice Ref.'),
404 'info_owner': fields.function(info_owner, string="Owner Account", method=True, type="text",help='Address of the Main Partner'),316 'info_owner': fields.function(info_owner, string="Owner Account", method=True, type="text",help='Address of the Main Partner'),
405 'info_partner': fields.function(info_partner, string="Destination Account", method=True, type="text",help='Address of the Ordering Customer.'),317 'info_partner': fields.function(info_partner, string="Destination Account", method=True, type="text",help='Address of the Ordering Customer.'),
406# 'partner_payable': fields.function(partner_payable, string="Partner payable", method=True, type='float'),
407# 'value_date': fields.function(_value_date, string='Value Date',
408# method=True, type='date'),
409 'date': fields.date('Payment Date',help="If no payment date is specified, the bank will treat this payment line directly"),318 'date': fields.date('Payment Date',help="If no payment date is specified, the bank will treat this payment line directly"),
410 'create_date': fields.datetime('Created' ,readonly=True),319 'create_date': fields.datetime('Created' ,readonly=True),
411 'state': fields.selection([('normal','Free'), ('structured','Structured')], 'Communication Type', required=True)320 'state': fields.selection([('normal','Free'), ('structured','Structured')], 'Communication Type', required=True)
412321
=== modified file 'account_voucher/account.py'
--- account_voucher/account.py 2010-01-20 17:19:31 +0000
+++ account_voucher/account.py 2010-03-17 11:50:49 +0000
@@ -67,9 +67,11 @@
67 def compute_total(self, cr, uid, ids, yr_st_date, yr_end_date, st_date, end_date, field_names, context={}):67 def compute_total(self, cr, uid, ids, yr_st_date, yr_end_date, st_date, end_date, field_names, context={}):
68 if not (st_date >= yr_st_date and end_date <= yr_end_date):68 if not (st_date >= yr_st_date and end_date <= yr_end_date):
69 return {}69 return {}
70 query = "l.date >= '%s' AND l.date <= '%s'" (st_date, end_date)70 return self.__compute(
71 return self.__compute(cr, uid, ids, field_names, context=context, query=query)71 cr, uid, ids, field_names, context=context,
72 72 query="l.date >= '%s' AND l.date <= '%s'",
73 query_params=(st_date, end_date))
74
73 def create(self, cr, uid, vals, context={}):75 def create(self, cr, uid, vals, context={}):
74 name=self.search(cr,uid,[('name','ilike',vals['name']),('company_id','=',vals['name'])])76 name=self.search(cr,uid,[('name','ilike',vals['name']),('company_id','=',vals['name'])])
75 if name:77 if name:
7678
=== modified file 'account_voucher/voucher.py'
--- account_voucher/voucher.py 2010-03-08 07:19:28 +0000
+++ account_voucher/voucher.py 2010-03-17 11:50:49 +0000
@@ -407,7 +407,8 @@
407 def action_number(self, cr, uid, ids, *args):407 def action_number(self, cr, uid, ids, *args):
408 cr.execute('SELECT id, type, number, move_id, reference ' \408 cr.execute('SELECT id, type, number, move_id, reference ' \
409 'FROM account_voucher ' \409 'FROM account_voucher ' \
410 'WHERE id IN ('+','.join(map(str,ids))+')')410 'WHERE id IN %s',
411 (tuple(ids),))
411 for (id, invtype, number, move_id, reference) in cr.fetchall():412 for (id, invtype, number, move_id, reference) in cr.fetchall():
412 if not number:413 if not number:
413 number = self.pool.get('ir.sequence').get(cr, uid, invtype)414 number = self.pool.get('ir.sequence').get(cr, uid, invtype)
414415
=== modified file 'auction/auction.py'
--- auction/auction.py 2009-08-24 11:51:52 +0000
+++ auction/auction.py 2010-03-17 11:50:49 +0000
@@ -95,12 +95,19 @@
95 RETURN: True95 RETURN: True
96 """96 """
97 # objects vendus mais non factures97 # objects vendus mais non factures
98 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',))98 cr.execute('SELECT COUNT(*) AS c '
99 'FROM auction_lots '
100 'WHERE auction_id IN %s '
101 'AND state=%s AND obj_price>0', (tuple(ids), 'draft'))
99 nbr = cr.fetchone()[0]102 nbr = cr.fetchone()[0]
100 ach_uids = {}103 ach_uids = {}
101 cr.execute('select id from auction_lots where auction_id in ('+','.join(map(str,ids))+') and state=%s and obj_price>0', ('draft',))104 cr.execute('SELECT id FROM auction_lots '
105 'WHERE auction_id IN %s '
106 'AND state=%s AND obj_price>0', (tuple(ids), 'draft'))
102 r=self.pool.get('auction.lots').lots_invoice(cr, uid, [x[0] for x in cr.fetchall()],{},None)107 r=self.pool.get('auction.lots').lots_invoice(cr, uid, [x[0] for x in cr.fetchall()],{},None)
103 cr.execute('select id from auction_lots where auction_id in ('+','.join(map(str,ids))+') and obj_price>0')108 cr.execute('SELECT id FROM auction_lots '
109 'WHERE auction_id IN %s '
110 'AND obj_price>0', (tuple(ids),))
104 ids2 = [x[0] for x in cr.fetchall()]111 ids2 = [x[0] for x in cr.fetchall()]
105 # for auction in auction_ids:112 # for auction in auction_ids:
106 c=self.pool.get('auction.lots').seller_trans_create(cr, uid, ids2,{})113 c=self.pool.get('auction.lots').seller_trans_create(cr, uid, ids2,{})
@@ -113,7 +120,9 @@
113# Deposits120# Deposits
114#----------------------------------------------------------121#----------------------------------------------------------
115def _inv_uniq(cr, ids):122def _inv_uniq(cr, ids):
116 cr.execute('select name from auction_deposit where id in ('+','.join(map(lambda x: str(x), ids))+')')123 cr.execute('SELECT name FROM auction_deposit '
124 'WHERE id IN %s',
125 (tuple(ids),))
117 for datas in cr.fetchall():126 for datas in cr.fetchall():
118 cr.execute('select count(*) from auction_deposit where name=%s', (datas[0],))127 cr.execute('select count(*) from auction_deposit where name=%s', (datas[0],))
119 if cr.fetchone()[0]>1:128 if cr.fetchone()[0]>1:
@@ -229,7 +238,9 @@
229# Lots238# Lots
230#----------------------------------------------------------239#----------------------------------------------------------
231def _inv_constraint(cr, ids):240def _inv_constraint(cr, ids):
232 cr.execute('select id, bord_vnd_id, lot_num from auction_lots where id in ('+','.join(map(lambda x: str(x), ids))+')')241 cr.execute('SELECT id, bord_vnd_id, lot_num FROM auction_lots '
242 'WHERE id IN %s',
243 (tuple(ids),))
233 for datas in cr.fetchall():244 for datas in cr.fetchall():
234 cr.execute('select count(*) from auction_lots where bord_vnd_id=%s and lot_num=%s', (datas[1],datas[2]))245 cr.execute('select count(*) from auction_lots where bord_vnd_id=%s and lot_num=%s', (datas[1],datas[2]))
235 if cr.fetchone()[0]>1:246 if cr.fetchone()[0]>1:
236247
=== modified file 'auction/report/auction_objects.py'
--- auction/report/auction_objects.py 2009-10-09 11:49:00 +0000
+++ auction/report/auction_objects.py 2010-03-17 11:50:49 +0000
@@ -29,20 +29,7 @@
29 super(auction_objects, self).__init__(cr, uid, name, context=context)29 super(auction_objects, self).__init__(cr, uid, name, context=context)
30 self.localcontext.update({30 self.localcontext.update({
31 'time': time,31 'time': time,
32 #'lines': self.lines
33 #'get_data' : self.get_data
34 })32 })
35
36# def lines(self, auction_id):
37#
38# cr.execute('select ad.name from auction_dates ad, a1uction_lots al where ad.id=al.%d group by ad.name',(auction_id))
39# return self.cr.fetchone()[0]
40# def get_data(self, auction_id):
41# res = self.pool.get('auction.bid.lines').read(self.cr,self.uid,[lot_id])
42# return True
43
44
45
46report_sxw.report_sxw('report.auction.objects', 'auction.lots', 'addons/auction/report/auction_objects.rml', parser=auction_objects)33report_sxw.report_sxw('report.auction.objects', 'auction.lots', 'addons/auction/report/auction_objects.rml', parser=auction_objects)
4734
48# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:35# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
4936
=== modified file 'auction/report/auction_total_rml.py'
--- auction/report/auction_total_rml.py 2009-10-09 11:49:00 +0000
+++ auction/report/auction_total_rml.py 2010-03-17 11:50:49 +0000
@@ -55,7 +55,10 @@
55 for lot_id in objects:55 for lot_id in objects:
56 auc_lot_ids.append(lot_id.id)56 auc_lot_ids.append(lot_id.id)
57 self.total_obj=auc_lot_ids57 self.total_obj=auc_lot_ids
58 self.cr.execute('select auction_id from auction_lots where id in ('+','.join(map(str,auc_lot_ids))+') group by auction_id')58 self.cr.execute('SELECT auction_id FROM auction_lots '
59 'WHERE id IN %s '
60 'GROUP BY auction_id',
61 (tuple(auc_lot_ids),))
59 auc_date_ids = self.cr.fetchall()62 auc_date_ids = self.cr.fetchall()
60 auct_dat=[]63 auct_dat=[]
61 for ad_id in auc_date_ids:64 for ad_id in auc_date_ids:
6265
=== modified file 'auction/report/buyer_list.py'
--- auction/report/buyer_list.py 2009-10-09 11:49:00 +0000
+++ auction/report/buyer_list.py 2010-03-17 11:50:49 +0000
@@ -51,7 +51,8 @@
51 for lot_id in objects:51 for lot_id in objects:
52 auc_lot_ids.append(lot_id.id)52 auc_lot_ids.append(lot_id.id)
53 self.auc_lot_ids=auc_lot_ids53 self.auc_lot_ids=auc_lot_ids
54 self.cr.execute('select auction_id from auction_lots where id in ('+','.join(map(str,auc_lot_ids))+') group by auction_id')54 self.cr.execute('SELECT auction_id FROM auction_lots WHERE id IN %s GROUP BY auction_id',
55 (tuple(auc_lot_ids),))
55 auc_date_ids = self.cr.fetchall()56 auc_date_ids = self.cr.fetchall()
56 auct_dat=[]57 auct_dat=[]
57 for ad_id in auc_date_ids:58 for ad_id in auc_date_ids:
@@ -71,13 +72,16 @@
7172
72 auc_date_ids = self.pool.get('auction.dates').search(self.cr,self.uid,([('name','like',obj['name'])]))73 auc_date_ids = self.pool.get('auction.dates').search(self.cr,self.uid,([('name','like',obj['name'])]))
7374
74# 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],))75 self.cr.execute('SELECT ach_login AS ach_uid, COUNT(1) AS no_lot, '\
75 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],))76 'SUM(obj_price) AS adj_price, '\
77 'SUM(buyer_price)-SUM(obj_price) AS buyer_cost, '\
78 'SUM(buyer_price) AS to_pay '\
79 'FROM auction_lots WHERE id IN %s '\
80 'AND auction_id=%s AND ach_login IS NOT NULL '\
81 'GROUP BY ach_login ORDER BY ach_login',
82 (tuple(self.auc_lot_ids), auc_date_ids[0],))
76 res = self.cr.dictfetchall()83 res = self.cr.dictfetchall()
77 for r in res:84 for r in res:
78# if r['ach_uid']:
79# tnm=self.pool.get('res.partner').read(self.cr,self.uid,[r['ach_uid']],['name'])#
80# r.__setitem__('ach_uid',tnm[0]['name'])
81 self.sum_adj_price_val = self.sum_adj_price_val + r['adj_price']85 self.sum_adj_price_val = self.sum_adj_price_val + r['adj_price']
82 self.sum_buyer_obj_price_val = self.sum_buyer_obj_price_val + r['buyer_cost']86 self.sum_buyer_obj_price_val = self.sum_buyer_obj_price_val + r['buyer_cost']
83 self.sum_buyer_price_val = self.sum_buyer_price_val + r['to_pay']87 self.sum_buyer_price_val = self.sum_buyer_price_val + r['to_pay']
8488
=== modified file 'base_module_quality/speed_test/speed_test.py'
--- base_module_quality/speed_test/speed_test.py 2010-02-18 15:23:03 +0000
+++ base_module_quality/speed_test/speed_test.py 2010-03-17 11:50:49 +0000
@@ -62,7 +62,9 @@
6262
63 # remove osv_memory class becaz it does not have demo data63 # remove osv_memory class becaz it does not have demo data
64 if obj_list:64 if obj_list:
65 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)))65 cr.execute("SELECT w.res_model FROM ir_actions_todo AS t "\
66 "LEFT JOIN ir_act_window AS w ON t.action_id=w.id "\
67 "WHERE w.res_model IN %s", (tuple(obj_list),))
66 res = cr.fetchall()68 res = cr.fetchall()
67 for remove_obj in res:69 for remove_obj in res:
68 if remove_obj and (remove_obj[0] in obj_list):70 if remove_obj and (remove_obj[0] in obj_list):
6971
=== modified file 'crm/crm.py'
--- crm/crm.py 2009-08-10 06:20:35 +0000
+++ crm/crm.py 2010-03-17 11:50:49 +0000
@@ -75,7 +75,9 @@
75 def _check_recursion(self, cr, uid, ids):75 def _check_recursion(self, cr, uid, ids):
76 level = 10076 level = 100
77 while len(ids):77 while len(ids):
78 cr.execute('select distinct parent_id from crm_case_section where id in ('+','.join(map(str,ids))+')')78 cr.execute('SELECT DISTINCT parent_id FROM crm_case_section '\
79 'WHERE id IN %s',
80 (tuple(ids),))
79 ids = filter(None, map(lambda x:x[0], cr.fetchall()))81 ids = filter(None, map(lambda x:x[0], cr.fetchall()))
80 if not level:82 if not level:
81 return False83 return False
8284
=== modified file 'crm/report/report_businessopp.py'
--- crm/report/report_businessopp.py 2010-02-17 10:53:29 +0000
+++ crm/report/report_businessopp.py 2010-03-17 11:50:49 +0000
@@ -56,7 +56,13 @@
56 minbenef = 99999999999999999999956 minbenef = 999999999999999999999
57 maxbenef = 057 maxbenef = 0
5858
59 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')59 cr.execute('SELECT probability, planned_revenue, planned_cost, '\
60 'user_id, res_users.name AS name '\
61 'FROM crm_case '\
62 'LEFT JOIN res_users ON (crm_case.user_id=res_users.id) '\
63 'WHERE crm_case.id IN %s '\
64 'ORDER BY user_id',
65 (tuple(ids),))
60 res = cr.dictfetchall()66 res = cr.dictfetchall()
6167
62 for row in res:68 for row in res:
6369
=== modified file 'crm_profiling/crm_profiling.py'
--- crm_profiling/crm_profiling.py 2009-01-27 11:15:46 +0000
+++ crm_profiling/crm_profiling.py 2010-03-17 11:50:49 +0000
@@ -28,17 +28,17 @@
28 query = """28 query = """
29 select distinct(answer)29 select distinct(answer)
30 from profile_question_yes_rel30 from profile_question_yes_rel
31 where profile in (%s)"""% ','.join([str(i) for i in ids ])31 where profile in %s"""
3232
33 cr.execute(query)33 cr.execute(query, (tuple(ids),))
34 ans_yes = [x[0] for x in cr.fetchall()]34 ans_yes = [x[0] for x in cr.fetchall()]
3535
36 query = """36 query = """
37 select distinct(answer)37 select distinct(answer)
38 from profile_question_no_rel38 from profile_question_no_rel
39 where profile in (%s)"""% ','.join([str(i) for i in ids ])39 where profile in %s"""
4040
41 cr.execute(query)41 cr.execute(query, (tuple(ids),))
42 ans_no = [x[0] for x in cr.fetchall()]42 ans_no = [x[0] for x in cr.fetchall()]
4343
44 return [ans_yes, ans_no]44 return [ans_yes, ans_no]
@@ -50,7 +50,8 @@
50 select distinct(parent_id)50 select distinct(parent_id)
51 from crm_segmentation51 from crm_segmentation
52 where parent_id is not null52 where parent_id is not null
53 and id in (%s)""" % ','.join([str(i) for i in ids ]))53 and id in %s""",
54 (tuple(ids),))
5455
55 parent_ids = [x[0] for x in cr.fetchall()]56 parent_ids = [x[0] for x in cr.fetchall()]
5657
@@ -86,30 +87,31 @@
8687
8788
88def _recompute_categ(self, cr, uid, pid, answers_ids):89def _recompute_categ(self, cr, uid, pid, answers_ids):
89 ok = []
90 cr.execute('''90 cr.execute('''
91 select r.category_id 91 select r.category_id
92 from res_partner_category_rel r left join crm_segmentation s on (r.category_id = s.categ_id) 92 from res_partner_category_rel r left join crm_segmentation s on (r.category_id = s.categ_id)
93 where r.partner_id = %s and (s.exclusif = false or s.exclusif is null)93 where r.partner_id = %s and (s.exclusif = false or s.exclusif is null)
94 ''', (pid,))94 ''', (pid,))
95 for x in cr.fetchall():95 categories = [x[0] for x in cr.fetchall()]
96 ok.append(x[0])
9796
98 query = '''97 query = '''
99 select id, categ_id 98 select id, categ_id
100 from crm_segmentation 99 from crm_segmentation
101 where profiling_active = true''' 100 where profiling_active = true'''
102 if ok != []:101 if not categories:
103 query = query +''' and categ_id not in(%s)'''% ','.join([str(i) for i in ok ])102 query_params = ()
104 query = query + ''' order by id '''103 else:
104 query += ' and categ_id not in %s'
105 query_params = (tuple(categories),)
106 query += ' order by id '
105107
106 cr.execute(query)108 cr.execute(query, query_params)
107 segm_cat_ids = cr.fetchall()109 segm_cat_ids = cr.fetchall()
108110
109 for (segm_id, cat_id) in segm_cat_ids:111 for (segm_id, cat_id) in segm_cat_ids:
110 if test_prof(cr, uid, segm_id, pid, answers_ids):112 if test_prof(cr, uid, segm_id, pid, answers_ids):
111 ok.append(cat_id)113 categories.append(cat_id)
112 return ok114 return categories
113115
114116
115class question(osv.osv):117class question(osv.osv):
116118
=== modified file 'document/document.py'
--- document/document.py 2010-01-08 11:38:58 +0000
+++ document/document.py 2010-03-17 11:50:49 +0000
@@ -302,7 +302,8 @@
302 def _check_recursion(self, cr, uid, ids):302 def _check_recursion(self, cr, uid, ids):
303 level = 100303 level = 100
304 while len(ids):304 while len(ids):
305 cr.execute('select distinct parent_id from document_directory where id in ('+','.join(map(str,ids))+')')305 cr.execute('SELECT DISTINCT parent_id FROM document_directory '\
306 'WHERE id in %s', (tuple(ids),))
306 ids = filter(None, map(lambda x:x[0], cr.fetchall()))307 ids = filter(None, map(lambda x:x[0], cr.fetchall()))
307 if not level:308 if not level:
308 return False309 return False
@@ -524,7 +525,8 @@
524525
525 def _data_get(self, cr, uid, ids, name, arg, context):526 def _data_get(self, cr, uid, ids, name, arg, context):
526 result = {}527 result = {}
527 cr.execute('select id,store_fname,link from ir_attachment where id in ('+','.join(map(str,ids))+')')528 cr.execute('SELECT id, store_fname, link FROM ir_attachment '\
529 'WHERE id IN %s', (tuple(ids),))
528 for id,r,l in cr.fetchall():530 for id,r,l in cr.fetchall():
529 try:531 try:
530 value = file(os.path.join(self._get_filestore(cr), r), 'rb').read()532 value = file(os.path.join(self._get_filestore(cr), r), 'rb').read()
531533
=== modified file 'event/event.py'
--- event/event.py 2009-04-09 10:02:19 +0000
+++ event/event.py 2010-03-17 11:50:49 +0000
@@ -77,8 +77,8 @@
77 def _get_register(self, cr, uid, ids, name, args, context=None):77 def _get_register(self, cr, uid, ids, name, args, context=None):
78 res={}78 res={}
79 for event in self.browse(cr, uid, ids, context):79 for event in self.browse(cr, uid, ids, context):
80 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.id80 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')"""
81 cr.execute(query)81 cr.execute(query,(event.section_id.id,))
82 res2 = cr.fetchone()82 res2 = cr.fetchone()
83 if res2 and res2[0]:83 if res2 and res2[0]:
84 res[event.id] = res2[0]84 res[event.id] = res2[0]
@@ -89,8 +89,8 @@
89 def _get_prospect(self, cr, uid, ids, name, args, context=None):89 def _get_prospect(self, cr, uid, ids, name, args, context=None):
90 res={}90 res={}
91 for event in self.browse(cr, uid, ids, context):91 for event in self.browse(cr, uid, ids, context):
92 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.id92 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'"""
93 cr.execute(query)93 cr.execute(query, (event.section_id.id,))
94 res2 = cr.fetchone()94 res2 = cr.fetchone()
95 if res2 and res2[0]:95 if res2 and res2[0]:
96 res[event.id] = res2[0]96 res[event.id] = res2[0]
9797
=== modified file 'event_project/event.py'
--- event_project/event.py 2009-01-04 22:12:50 +0000
+++ event_project/event.py 2010-03-17 11:50:49 +0000
@@ -37,8 +37,8 @@
37 for id in ids:37 for id in ids:
38 res[id] = []38 res[id] = []
39 for id in ids:39 for id in ids:
40 query = "select project_id from event_event where id = %i" %id40 query = "select project_id from event_event where id = %s"
41 cr.execute(query)41 cr.execute(query, (id,))
42 project_ids = [ x[0] for x in cr.fetchall()]42 project_ids = [ x[0] for x in cr.fetchall()]
43 ids2 = obj.pool.get(self._obj).search(cr, user, [(self._fields_id,'in',project_ids),('state','<>','done')], limit=self._limit)43 ids2 = obj.pool.get(self._obj).search(cr, user, [(self._fields_id,'in',project_ids),('state','<>','done')], limit=self._limit)
44 for r in obj.pool.get(self._obj)._read_flat(cr, user, ids2, [self._fields_id], context=context, load='_classic_write'):44 for r in obj.pool.get(self._obj)._read_flat(cr, user, ids2, [self._fields_id], context=context, load='_classic_write'):
4545
=== modified file 'hr/hr.py'
--- hr/hr.py 2009-06-04 06:58:39 +0000
+++ hr/hr.py 2010-03-17 11:50:49 +0000
@@ -102,7 +102,8 @@
102 def _check_recursion(self, cr, uid, ids):102 def _check_recursion(self, cr, uid, ids):
103 level = 100103 level = 100
104 while len(ids):104 while len(ids):
105 cr.execute('select distinct parent_id from hr_employee_category where id in ('+','.join(map(str,ids))+')')105 cr.execute('SELECT DISTINCT parent_id FROM hr_employee_category '\
106 'WHERE id IN %s', (tuple(ids),))
106 ids = filter(None, map(lambda x:x[0], cr.fetchall()))107 ids = filter(None, map(lambda x:x[0], cr.fetchall()))
107 if not level:108 if not level:
108 return False109 return False
@@ -151,7 +152,8 @@
151 def _check_recursion(self, cr, uid, ids):152 def _check_recursion(self, cr, uid, ids):
152 level = 100153 level = 100
153 while len(ids):154 while len(ids):
154 cr.execute('select distinct parent_id from hr_employee where id in ('+','.join(map(str,ids))+')')155 cr.execute('SELECT DISTINCT parent_id FROM hr_employee '\
156 'WHERE id IN %s', (tuple(ids),))
155 ids = filter(None, map(lambda x:x[0], cr.fetchall()))157 ids = filter(None, map(lambda x:x[0], cr.fetchall()))
156 if not level:158 if not level:
157 return False159 return False
158160
=== modified file 'hr/hr_department.py'
--- hr/hr_department.py 2010-01-08 11:38:58 +0000
+++ hr/hr_department.py 2010-03-17 11:50:49 +0000
@@ -44,7 +44,8 @@
44 def _check_recursion(self, cr, uid, ids):44 def _check_recursion(self, cr, uid, ids):
45 level = 10045 level = 100
46 while len(ids):46 while len(ids):
47 cr.execute('select distinct parent_id from hr_department where id in ('+','.join(map(str,ids))+')')47 cr.execute('SELECT DISTINCT parent_id FROM hr_department '\
48 'WHERE id IN %s', (tuple(ids),))
48 ids = filter(None, map(lambda x:x[0], cr.fetchall()))49 ids = filter(None, map(lambda x:x[0], cr.fetchall()))
49 if not level:50 if not level:
50 return False51 return False
@@ -128,4 +129,4 @@
128129
129res_users()130res_users()
130131
131# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
132\ No newline at end of file132\ No newline at end of file
133# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
133134
=== modified file 'hr_attendance/hr_attendance.py'
--- hr_attendance/hr_attendance.py 2009-01-04 22:12:50 +0000
+++ hr_attendance/hr_attendance.py 2010-03-17 11:50:49 +0000
@@ -68,8 +68,8 @@
68 and name <= (select name from hr_attendance where id=%s)68 and name <= (select name from hr_attendance where id=%s)
69 order by name desc69 order by name desc
70 limit 270 limit 2
71 ''' % (id, id)71 '''
72 cr.execute(sql)72 cr.execute(sql, (id, id))
73 atts = cr.fetchall()73 atts = cr.fetchall()
74 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])):74 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])):
75 return False75 return False
@@ -98,7 +98,7 @@
98 ON (hr_attendance.employee_id = foo.employee_id \98 ON (hr_attendance.employee_id = foo.employee_id \
99 AND hr_attendance.name = foo.name) \99 AND hr_attendance.name = foo.name) \
100 WHERE hr_attendance.employee_id \100 WHERE hr_attendance.employee_id \
101 in (' + ','.join([str(x) for x in ids]) + ')')101 in %s', (tuple(ids),))
102 for res in cr.fetchall():102 for res in cr.fetchall():
103 result[res[1]] = res[0] == 'sign_in' and 'present' or 'absent'103 result[res[1]] = res[0] == 'sign_in' and 'present' or 'absent'
104 return result104 return result
105105
=== modified file 'hr_attendance/wizard/print_attendance_error.py'
--- hr_attendance/wizard/print_attendance_error.py 2010-01-21 11:52:07 +0000
+++ hr_attendance/wizard/print_attendance_error.py 2010-03-17 11:50:49 +0000
@@ -43,9 +43,12 @@
43def _check_data(self, cr, uid, data, *args):43def _check_data(self, cr, uid, data, *args):
44 date_from = data['form']['init_date']44 date_from = data['form']['init_date']
45 date_to = data['form']['end_date']45 date_to = data['form']['end_date']
46 emp_ids = (','.join([str(x) for x in data['ids']]))46 cr.execute("SELECT id FROM hr_attendance "\
47 47 "WHERE employee_id IN %s "\
48 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'))48 "AND to_char(name,'YYYY-mm-dd')<=%s "\
49 "and to_char(name,'YYYY-mm-dd')>=%s "\
50 "and action in (%s, %s) order by name",
51 (tuple(data['ids']), date_to, date_from, 'sign_in', 'sign_out'))
49 attendance_ids = [x[0] for x in cr.fetchall()]52 attendance_ids = [x[0] for x in cr.fetchall()]
50 if not attendance_ids:53 if not attendance_ids:
51 raise wizard.except_wizard(_('No Data Available'), _('No records found for your selection!')) 54 raise wizard.except_wizard(_('No Data Available'), _('No records found for your selection!'))
5255
=== modified file 'hr_expense/hr_expense.py'
--- hr_expense/hr_expense.py 2009-10-13 14:50:16 +0000
+++ hr_expense/hr_expense.py 2010-03-17 11:50:49 +0000
@@ -39,10 +39,13 @@
39 return super(hr_expense_expense, self).copy(cr, uid, id, default, context)39 return super(hr_expense_expense, self).copy(cr, uid, id, default, context)
4040
41 def _amount(self, cr, uid, ids, field_name, arg, context):41 def _amount(self, cr, uid, ids, field_name, arg, context):
42 id_set = ",".join(map(str, ids))42 cr.execute("SELECT s.id, "\
43 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 ")43 "COALESCE(SUM(l.unit_amount*l.unit_quantity),0) AS amount "\
44 res = dict(cr.fetchall())44 "FROM hr_expense_expense s "\
45 return res45 "LEFT OUTER JOIN hr_expense_line l ON (s.id=l.expense_id) "\
46 "WHERE s.id IN %s GROUP BY s.id ",
47 (tuple(ids),))
48 return dict(cr.fetchall())
4649
47 def _get_currency(self, cr, uid, context):50 def _get_currency(self, cr, uid, context):
48 user = self.pool.get('res.users').browse(cr, uid, [uid])[0]51 user = self.pool.get('res.users').browse(cr, uid, [uid])[0]
@@ -188,10 +191,11 @@
188 def _amount(self, cr, uid, ids, field_name, arg, context):191 def _amount(self, cr, uid, ids, field_name, arg, context):
189 if not len(ids):192 if not len(ids):
190 return {}193 return {}
191 id_set = ",".join(map(str, ids))194 cr.execute("SELECT l.id, "\
192 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 ")195 "COALESCE(SUM(l.unit_amount*l.unit_quantity),0) AS amount "\
193 res = dict(cr.fetchall())196 "FROM hr_expense_line l WHERE id IN %s "\
194 return res197 "GROUP BY l.id", (tuple(ids),))
198 return dict(cr.fetchall())
195199
196 _columns = {200 _columns = {
197 'name': fields.char('Short Description', size=128, required=True),201 'name': fields.char('Short Description', size=128, required=True),
198202
=== modified file 'hr_holidays/hr.py'
--- hr_holidays/hr.py 2010-01-05 08:07:22 +0000
+++ hr_holidays/hr.py 2010-03-17 11:50:49 +0000
@@ -146,7 +146,7 @@
146 146
147 def _check_date(self, cr, uid, ids):147 def _check_date(self, cr, uid, ids):
148 if ids:148 if ids:
149 cr.execute('select number_of_days from hr_holidays where id in ('+','.join(map(str, ids))+')')149 cr.execute('select number_of_days from hr_holidays where id in %s', (tuple(ids),))
150 res = cr.fetchall()150 res = cr.fetchall()
151 if res and res[0][0] < 0:151 if res and res[0][0] < 0:
152 return False152 return False
153153
=== modified file 'hr_timesheet_invoice/wizard/hr_timesheet_invoice_create.py'
--- hr_timesheet_invoice/wizard/hr_timesheet_invoice_create.py 2009-12-10 09:40:49 +0000
+++ hr_timesheet_invoice/wizard/hr_timesheet_invoice_create.py 2010-03-17 11:50:49 +0000
@@ -43,7 +43,7 @@
43 if obj_acc.invoice_id and obj_acc.invoice_id.state !='cancel':43 if obj_acc.invoice_id and obj_acc.invoice_id.state !='cancel':
44 raise wizard.except_wizard(_('Warning'),_('The analytic entry "%s" is already invoiced!')%(obj_acc.name,))44 raise wizard.except_wizard(_('Warning'),_('The analytic entry "%s" is already invoiced!')%(obj_acc.name,))
45 45
46 cr.execute("SELECT distinct(account_id) from account_analytic_line where id IN (%s)"% (','.join(map(str,data['ids'])),))46 cr.execute("SELECT distinct(account_id) from account_analytic_line where id IN %s", (tuple(data['ids']),))
47 account_ids = cr.fetchall()47 account_ids = cr.fetchall()
48 return {'accounts': [x[0] for x in account_ids]}48 return {'accounts': [x[0] for x in account_ids]}
4949
@@ -96,9 +96,10 @@
96 cr.execute("SELECT product_id, to_invoice, sum(unit_amount) " \96 cr.execute("SELECT product_id, to_invoice, sum(unit_amount) " \
97 "FROM account_analytic_line as line " \97 "FROM account_analytic_line as line " \
98 "WHERE account_id = %s " \98 "WHERE account_id = %s " \
99 "AND id IN (" + ','.join([str(x) for x in data['ids']]) + ") " \99 "AND id IN %s " \
100 "AND to_invoice IS NOT NULL " \100 "AND to_invoice IS NOT NULL " \
101 "GROUP BY product_id,to_invoice", (account.id,))101 "GROUP BY product_id,to_invoice",
102 (account.id, tuple(data['ids'])))
102103
103 for product_id,factor_id,qty in cr.fetchall():104 for product_id,factor_id,qty in cr.fetchall():
104 product = pool.get('product.product').browse(cr, uid, product_id, context2)105 product = pool.get('product.product').browse(cr, uid, product_id, context2)
@@ -144,11 +145,11 @@
144 #145 #
145 cr.execute("SELECT * " # TODO optimize this146 cr.execute("SELECT * " # TODO optimize this
146 " FROM account_analytic_line"147 " FROM account_analytic_line"
147 " WHERE account_id=%%s"148 " WHERE account_id=%s"
148 " AND id IN (%s)"149 " AND id IN %s"
149 " AND product_id=%%s"150 " AND product_id=%s"
150 " AND to_invoice=%%s" % ','.join(['%s']*len(data['ids'])),151 " AND to_invoice=%s",
151 tuple([account.id]+ data['ids']+[ product_id, factor_id]))152 (account.id, tuple(data['ids']), product_id, factor_id))
152 line_ids = cr.dictfetchall()153 line_ids = cr.dictfetchall()
153 note = []154 note = []
154 for line in line_ids:155 for line in line_ids:
@@ -169,8 +170,9 @@
169170
170 curr_line['note'] = "\n".join(map(lambda x: x or '',note))171 curr_line['note'] = "\n".join(map(lambda x: x or '',note))
171 pool.get('account.invoice.line').create(cr, uid, curr_line)172 pool.get('account.invoice.line').create(cr, uid, curr_line)
172 strids = ','.join(map(str, data['ids']))173 cr.execute("UPDATE account_analytic_line SET invoice_id=%s "\
173 cr.execute("update account_analytic_line set invoice_id=%%s WHERE account_id = %%s and id IN (%s)" % strids, (last_invoice,account.id,))174 "WHERE account_id = %s AND id IN %s",
175 (last_invoice,account.id, tuple(data['ids'])))
174 176
175 pool.get('account.invoice').button_reset_taxes(cr, uid, [last_invoice], context)177 pool.get('account.invoice').button_reset_taxes(cr, uid, [last_invoice], context)
176 178
177179
=== modified file 'hr_timesheet_sheet/hr_timesheet_sheet.py'
--- hr_timesheet_sheet/hr_timesheet_sheet.py 2010-03-11 15:43:08 +0000
+++ hr_timesheet_sheet/hr_timesheet_sheet.py 2010-03-17 11:50:49 +0000
@@ -104,7 +104,7 @@
104 LEFT JOIN hr_timesheet_sheet_sheet_day AS day \104 LEFT JOIN hr_timesheet_sheet_sheet_day AS day \
105 ON (sheet.id = day.sheet_id \105 ON (sheet.id = day.sheet_id \
106 AND day.name = sheet.date_current) \106 AND day.name = sheet.date_current) \
107 WHERE sheet.id in (' + ','.join([str(x) for x in ids]) + ')')107 WHERE sheet.id in %s', (tuple(ids),))
108 return dict(cr.fetchall())108 return dict(cr.fetchall())
109109
110 def _total(self, cr, uid, ids, name, args, context):110 def _total(self, cr, uid, ids, name, args, context):
@@ -112,8 +112,8 @@
112 FROM hr_timesheet_sheet_sheet s \112 FROM hr_timesheet_sheet_sheet s \
113 LEFT JOIN hr_timesheet_sheet_sheet_day d \113 LEFT JOIN hr_timesheet_sheet_sheet_day d \
114 ON (s.id = d.sheet_id) \114 ON (s.id = d.sheet_id) \
115 WHERE s.id in ('+ ','.join(map(str, ids)) + ') \115 WHERE s.id in %s \
116 GROUP BY s.id')116 GROUP BY s.id', (tuple(ids),))
117 return dict(cr.fetchall())117 return dict(cr.fetchall())
118118
119 def _state_attendance(self, cr, uid, ids, name, args, context):119 def _state_attendance(self, cr, uid, ids, name, args, context):
@@ -330,8 +330,8 @@
330 ON (s.date_to >= al.date \330 ON (s.date_to >= al.date \
331 AND s.date_from <= al.date \331 AND s.date_from <= al.date \
332 AND s.user_id = al.user_id) \332 AND s.user_id = al.user_id) \
333 WHERE l.id in (' + ','.join([str(x) for x in ids]) + ') \333 WHERE l.id in %s \
334 GROUP BY l.id')334 GROUP BY l.id', (tuple(ids),))
335 res = dict(cursor.fetchall())335 res = dict(cursor.fetchall())
336 sheet_names = {}336 sheet_names = {}
337 for sheet_id, name in sheet_obj.name_get(cursor, user, res.values(),337 for sheet_id, name in sheet_obj.name_get(cursor, user, res.values(),
@@ -448,8 +448,8 @@
448 ON (s.date_to >= to_date(to_char(a.name, 'YYYY-MM-dd'),'YYYY-MM-dd') \448 ON (s.date_to >= to_date(to_char(a.name, 'YYYY-MM-dd'),'YYYY-MM-dd') \
449 AND s.date_from <= to_date(to_char(a.name, 'YYYY-MM-dd'),'YYYY-MM-dd') \449 AND s.date_from <= to_date(to_char(a.name, 'YYYY-MM-dd'),'YYYY-MM-dd') \
450 AND s.user_id = e.user_id) \450 AND s.user_id = e.user_id) \
451 WHERE a.id in (" + ",".join([str(x) for x in ids]) + ") \451 WHERE a.id in %s \
452 GROUP BY a.id")452 GROUP BY a.id", (tuple(ids),))
453 res = dict(cursor.fetchall())453 res = dict(cursor.fetchall())
454 sheet_names = {}454 sheet_names = {}
455 for sheet_id, name in sheet_obj.name_get(cursor, user, res.values(),455 for sheet_id, name in sheet_obj.name_get(cursor, user, res.values(),
456456
=== modified file 'idea/idea.py'
--- idea/idea.py 2009-01-04 22:12:50 +0000
+++ idea/idea.py 2010-03-17 11:50:49 +0000
@@ -48,40 +48,40 @@
48 if not len(ids):48 if not len(ids):
49 return {}49 return {}
5050
51 sql = """select i.id, avg(v.score::integer) 51 sql = """select i.id, avg(v.score::integer)
52 from idea_idea i left outer join idea_vote v on i.id = v.idea_id52 from idea_idea i left outer join idea_vote v on i.id = v.idea_id
53 where i.id in (%s)53 where i.id in %s
54 group by i.id54 group by i.id
55 """ % ','.join(['%d']*len(ids))55 """
5656
57 cr.execute(sql, ids)57 cr.execute(sql, (tuple(ids),))
58 return dict(cr.fetchall())58 return dict(cr.fetchall())
5959
60 def _vote_count(self,cr,uid,ids,name,arg,context=None):60 def _vote_count(self,cr,uid,ids,name,arg,context=None):
61 if not len(ids):61 if not len(ids):
62 return {}62 return {}
6363
64 sql = """select i.id, count(1) 64 sql = """select i.id, count(1)
65 from idea_idea i left outer join idea_vote v on i.id = v.idea_id65 from idea_idea i left outer join idea_vote v on i.id = v.idea_id
66 where i.id in (%s)66 where i.id in %s
67 group by i.id67 group by i.id
68 """ % ','.join(['%d']*len(ids))68 """
6969
70 cr.execute(sql, ids)70 cr.execute(sql, (tuple(ids),))
71 return dict(cr.fetchall())71 return dict(cr.fetchall())
7272
73 def _comment_count(self,cr,uid,ids,name,arg,context=None):73 def _comment_count(self,cr,uid,ids,name,arg,context=None):
74 if not len(ids):74 if not len(ids):
75 return {}75 return {}
7676
77 sql = """select i.id, count(1) 77 sql = """select i.id, count(1)
78 from idea_idea i left outer join idea_comment c on i.id = c.idea_id78 from idea_idea i left outer join idea_comment c on i.id = c.idea_id
79 where i.id in (%s)79 where i.id in %s
80 group by i.id80 group by i.id
81 """ % ','.join(['%d']*len(ids))81 """
8282
8383
84 cr.execute(sql,ids)84 cr.execute(sql, (tuple(ids),))
85 return dict(cr.fetchall())85 return dict(cr.fetchall())
8686
87 def _vote_read(self, cr, uid, ids, name, arg, context = None):87 def _vote_read(self, cr, uid, ids, name, arg, context = None):
8888
=== modified file 'l10n_be/wizard/wizard_vat_intra.py'
--- l10n_be/wizard/wizard_vat_intra.py 2009-03-24 11:01:43 +0000
+++ l10n_be/wizard/wizard_vat_intra.py 2010-03-17 11:50:49 +0000
@@ -169,11 +169,9 @@
169 start_date = fiscal_periods[3].date_start169 start_date = fiscal_periods[3].date_start
170 end_date = fiscal_periods[3].date_stop170 end_date = fiscal_periods[3].date_stop
171171
172 period = "to_date('" + str(start_date) + "','yyyy-mm-dd') and to_date('" + str(end_date) +"','yyyy-mm-dd')"
173 record = {}172 record = {}
174173
175 for p_id in p_id_list:174 for p_id in p_id_list:
176 list_partner = []
177 partner = pool.get('res.partner').browse(cr, uid, p_id)175 partner = pool.get('res.partner').browse(cr, uid, p_id)
178 go_ahead = False176 go_ahead = False
179 country_code = ''177 country_code = ''
@@ -185,27 +183,22 @@
185 if not go_ahead:183 if not go_ahead:
186 continue184 continue
187185
188 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,))186 cr.execute('SELECT SUM(debit)-SUM(credit) AS amount '\
187 'FROM account_move_line l '\
188 'LEFT JOIN account_account a ON (l.account_id=a.id) '\
189 'WHERE a.type IN ('"'receivable'"') '\
190 'AND l.partner_id=%s '\
191 'AND l.date BETWEEN to_date(%s, \'yyyy-mm-dd\') '\
192 ' AND to_date(%s, \'yyyy-mm-dd\')',
193 (p_id, start_date, end_date))
189 res = cr.dictfetchall()194 res = cr.dictfetchall()
190 list_partner.append(res[0]['amount'])195
191 list_partner.append('T') #partner.ref ...should be check196 record[p_id] = (
192 list_partner.append(partner.vat)197 res[0]['amount'],
193 list_partner.append(country_code)198 'T', #partner.ref ...should be check
194 #...deprecated...199 partner.vat,
195# addr = pool.get('res.partner').address_get(cr, uid, [partner.id], ['invoice'])200 country_code
196# if addr.get('invoice',False):201 )
197# ads = pool.get('res.partner.address').browse(cr,uid,[addr['invoice']])[0]
198#
199# if ads.country_id:
200# code_country = ads.country_id.code
201# list_partner.append(code_country)
202# else:
203# error_message.append('Data Insufficient! : '+ 'The Partner "'+partner.name + '"'' has no country associated with its Invoice address!')
204# if len(list_partner)<4:
205# list_partner.append('')
206# error_message.append('Data Insufficient! : '+ 'The Partner "'+partner.name + '"'' has no Invoice address!')
207# list_partner.append(code_country or 'not avail')
208 record[p_id] = list_partner
209202
210 if len(error_message):203 if len(error_message):
211 data['form']['msg'] = 'Exception : \n' +'-'*50+'\n'+ '\n'.join(error_message)204 data['form']['msg'] = 'Exception : \n' +'-'*50+'\n'+ '\n'.join(error_message)
@@ -235,4 +228,4 @@
235 'result': {'type':'form', 'arch':msg_form, 'fields':msg_fields, 'state':[('end','Ok')]},228 'result': {'type':'form', 'arch':msg_form, 'fields':msg_fields, 'state':[('end','Ok')]},
236 }229 }
237 }230 }
238parter_vat_intra('vat.intra.xml')
239\ No newline at end of file231\ No newline at end of file
232parter_vat_intra('vat.intra.xml')
240233
=== modified file 'membership/membership.py'
--- membership/membership.py 2010-02-26 13:36:01 +0000
+++ membership/membership.py 2010-03-17 11:50:49 +0000
@@ -148,8 +148,8 @@
148 )148 )
149 JOIN account_invoice ai ON (149 JOIN account_invoice ai ON (
150 ai.id = ail.invoice_id)150 ai.id = ail.invoice_id)
151 WHERE ml.id in (%s)151 WHERE ml.id in %s
152 ''' % ','.join([str(id) for id in ids]))152 ''', (tuple(ids),))
153153
154 res = cr.fetchall()154 res = cr.fetchall()
155 for r in res:155 for r in res:
@@ -414,7 +414,7 @@
414 def _check_recursion(self, cr, uid, ids):414 def _check_recursion(self, cr, uid, ids):
415 level = 100415 level = 100
416 while len(ids):416 while len(ids):
417 cr.execute('select distinct associate_member from res_partner where id in ('+','.join(map(str,ids))+')')417 cr.execute('select distinct associate_member from res_partner where id in %s', (tuple(ids),))
418 ids = filter(None, map(lambda x:x[0], cr.fetchall()))418 ids = filter(None, map(lambda x:x[0], cr.fetchall()))
419 if not level:419 if not level:
420 return False420 return False
421421
=== modified file 'membership/wizard/invoice_membership.py'
--- membership/wizard/invoice_membership.py 2009-11-13 06:33:46 +0000
+++ membership/wizard/invoice_membership.py 2010-03-17 11:50:49 +0000
@@ -32,9 +32,8 @@
32 cr.execute('''32 cr.execute('''
33 SELECT partner_id, id, type33 SELECT partner_id, id, type
34 FROM res_partner_address34 FROM res_partner_address
35 WHERE partner_id IN (%s)35 WHERE partner_id IN %s
36 ''' % ','.join([str(id) for id in partner_ids])36 ''', (tuple(partner_ids),))
37 )
38 fetchal = cr.fetchall()37 fetchal = cr.fetchall()
39 if not fetchal:38 if not fetchal:
40 raise wizard.except_wizard(_('Error !'), _('No Address defined for this partner'))39 raise wizard.except_wizard(_('Error !'), _('No Address defined for this partner'))
4140
=== modified file 'mrp/mrp.py'
--- mrp/mrp.py 2010-03-10 08:51:21 +0000
+++ mrp/mrp.py 2010-03-17 11:50:49 +0000
@@ -216,7 +216,7 @@
216 def _check_recursion(self, cr, uid, ids):216 def _check_recursion(self, cr, uid, ids):
217 level = 500217 level = 500
218 while len(ids):218 while len(ids):
219 cr.execute('select distinct bom_id from mrp_bom where id in ('+','.join(map(str,ids))+')')219 cr.execute('select distinct bom_id from mrp_bom where id in %s', (tuple(ids),))
220 ids = filter(None, map(lambda x:x[0], cr.fetchall()))220 ids = filter(None, map(lambda x:x[0], cr.fetchall()))
221 if not level:221 if not level:
222 return False222 return False
223223
=== modified file 'mrp/report/workcenter_load.py'
--- mrp/report/workcenter_load.py 2009-09-28 14:26:44 +0000
+++ mrp/report/workcenter_load.py 2010-03-17 11:50:49 +0000
@@ -99,14 +99,13 @@
99 def create(self, cr, uid, ids, datas, context={}):99 def create(self, cr, uid, ids, datas, context={}):
100 assert len(ids), 'You should provide some ids!'100 assert len(ids), 'You should provide some ids!'
101 colors = choice_colors(len(ids))101 colors = choice_colors(len(ids))
102 ids_str = ','.join(map(str, ids))
103 cr.execute(102 cr.execute(
104 "SELECT MAX(mrp_production.date_planned) AS stop,MIN(mrp_production.date_planned) AS start "\103 "SELECT MAX(mrp_production.date_planned) AS stop,MIN(mrp_production.date_planned) AS start "\
105 "FROM mrp_workcenter, mrp_production, mrp_production_workcenter_line "\104 "FROM mrp_workcenter, mrp_production, mrp_production_workcenter_line "\
106 "WHERE mrp_production_workcenter_line.production_id=mrp_production.id "\105 "WHERE mrp_production_workcenter_line.production_id=mrp_production.id "\
107 "AND mrp_production_workcenter_line.workcenter_id=mrp_workcenter.id "\106 "AND mrp_production_workcenter_line.workcenter_id=mrp_workcenter.id "\
108 "AND mrp_production.state NOT IN ('cancel','done') "\107 "AND mrp_production.state NOT IN ('cancel','done') "\
109 "AND mrp_workcenter.id IN (%s)" % ids_str)108 "AND mrp_workcenter.id IN %s", (tuple(ids),))
110 res = cr.dictfetchone()109 res = cr.dictfetchone()
111 if not res['stop']:110 if not res['stop']:
112 res['stop'] = time.strftime('%Y-%m-%d %H:%M:%S')111 res['stop'] = time.strftime('%Y-%m-%d %H:%M:%S')
@@ -137,8 +136,8 @@
137 # select workcenters136 # select workcenters
138 cr.execute(137 cr.execute(
139 "SELECT id, name FROM mrp_workcenter " \138 "SELECT id, name FROM mrp_workcenter " \
140 "WHERE id in (%s) "\139 "WHERE id in %s "\
141 "ORDER BY mrp_workcenter.id" % ids_str)140 "ORDER BY mrp_workcenter.id", (tuple(ids),))
142 workcenters = cr.dictfetchall()141 workcenters = cr.dictfetchall()
143142
144 data = []143 data = []
145144
=== modified file 'point_of_sale/pos.py'
--- point_of_sale/pos.py 2010-02-03 05:47:12 +0000
+++ point_of_sale/pos.py 2010-03-17 11:50:49 +0000
@@ -60,7 +60,6 @@
60 return {'value': {'pricelist_id': pricelist}}60 return {'value': {'pricelist_id': pricelist}}
6161
62 def _amount_total(self, cr, uid, ids, field_name, arg, context):62 def _amount_total(self, cr, uid, ids, field_name, arg, context):
63 id_set = ",".join(map(str, ids))
64 cr.execute("""63 cr.execute("""
65 SELECT64 SELECT
66 p.id,65 p.id,
@@ -69,7 +68,7 @@
69 ) AS amount68 ) AS amount
70 FROM pos_order p69 FROM pos_order p
71 LEFT OUTER JOIN pos_order_line l ON (p.id=l.order_id)70 LEFT OUTER JOIN pos_order_line l ON (p.id=l.order_id)
72 WHERE p.id IN (""" + id_set +""") GROUP BY p.id """)71 WHERE p.id IN %s GROUP BY p.id """, (tuple(ids),))
73 res = dict(cr.fetchall())72 res = dict(cr.fetchall())
7473
75 for rec in self.browse(cr, uid, ids, context):74 for rec in self.browse(cr, uid, ids, context):
@@ -113,8 +112,8 @@
113 return res112 return res
114113
115 def payment_get(self, cr, uid, ids, context=None):114 def payment_get(self, cr, uid, ids, context=None):
116 cr.execute("select id from pos_payment where order_id in (%s)" % \115 cr.execute("select id from pos_payment where order_id in %s",
117 ','.join([str(i) for i in ids]))116 (tuple(ids),))
118 return [i[0] for i in cr.fetchall()]117 return [i[0] for i in cr.fetchall()]
119118
120 def _sale_journal_get(self, cr, uid, context):119 def _sale_journal_get(self, cr, uid, context):
121120
=== modified file 'product/pricelist.py'
--- product/pricelist.py 2010-02-04 07:12:40 +0000
+++ product/pricelist.py 2010-03-17 11:50:49 +0000
@@ -22,7 +22,6 @@
2222
23from osv import fields, osv23from osv import fields, osv
2424
25#from tools.misc import currency
26from _common import rounding25from _common import rounding
27import time26import time
28from tools import config27from tools import config
@@ -91,8 +90,6 @@
91 res.append((type['key'],type['name']))90 res.append((type['key'],type['name']))
9291
93 return res92 return res
94# cr.execute('select key,name from product_pricelist_type order by name')
95# return cr.fetchall()
96 _name = "product.pricelist"93 _name = "product.pricelist"
97 _description = "Pricelist"94 _description = "Pricelist"
98 _columns = {95 _columns = {
@@ -179,9 +176,11 @@
179 'you have defined cyclic categories ' \176 'you have defined cyclic categories ' \
180 'of products!'))177 'of products!'))
181 if categ_ids:178 if categ_ids:
182 categ_where = '(categ_id IN (' + ','.join(categ_ids) + '))'179 categ_where = '(categ_id IN %s)'
180 sqlargs = (tuple(categ_ids),)
183 else:181 else:
184 categ_where = '(categ_id IS NULL)'182 categ_where = '(categ_id IS NULL)'
183 sqlargs = ()
185184
186 cr.execute(185 cr.execute(
187 'SELECT i.*, pl.currency_id '186 'SELECT i.*, pl.currency_id '
@@ -194,7 +193,7 @@
194 'AND (min_quantity IS NULL OR min_quantity <= %s) '193 'AND (min_quantity IS NULL OR min_quantity <= %s) '
195 'AND i.price_version_id = v.id AND v.pricelist_id = pl.id '194 'AND i.price_version_id = v.id AND v.pricelist_id = pl.id '
196 'ORDER BY sequence LIMIT 1',195 'ORDER BY sequence LIMIT 1',
197 (tmpl_id, prod_id, plversion['id'], qty))196 (tmpl_id, prod_id) + sqlargs + ( plversion['id'], qty))
198 res = cr.dictfetchone()197 res = cr.dictfetchone()
199 if res:198 if res:
200 if res['base'] == -1:199 if res['base'] == -1:
@@ -218,10 +217,10 @@
218 if sinfo:217 if sinfo:
219 cr.execute('SELECT * ' \218 cr.execute('SELECT * ' \
220 'FROM pricelist_partnerinfo ' \219 'FROM pricelist_partnerinfo ' \
221 'WHERE suppinfo_id IN (' + \220 'WHERE suppinfo_id IN %s ' \
222 ','.join(map(str, sinfo)) + ') ' \
223 'AND min_quantity <= %s ' \221 'AND min_quantity <= %s ' \
224 'ORDER BY min_quantity DESC LIMIT 1', (qty,))222 'ORDER BY min_quantity DESC LIMIT 1',
223 (tuple(sinfo), qty))
225 res2 = cr.dictfetchone()224 res2 = cr.dictfetchone()
226 if res2:225 if res2:
227 price = res2['price']226 price = res2['price']
@@ -382,7 +381,4 @@
382 return {}381 return {}
383product_pricelist_item()382product_pricelist_item()
384383
385
386
387# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:384# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
388
389385
=== modified file 'product/product.py'
--- product/product.py 2010-03-15 11:10:51 +0000
+++ product/product.py 2010-03-17 11:50:49 +0000
@@ -206,7 +206,7 @@
206 def _check_recursion(self, cr, uid, ids):206 def _check_recursion(self, cr, uid, ids):
207 level = 100207 level = 100
208 while len(ids):208 while len(ids):
209 cr.execute('select distinct parent_id from product_category where id in ('+','.join(map(str,ids))+')')209 cr.execute('select distinct parent_id from product_category where id in %s', (tuple(ids),))
210 ids = filter(None, map(lambda x:x[0], cr.fetchall()))210 ids = filter(None, map(lambda x:x[0], cr.fetchall()))
211 if not level:211 if not level:
212 return False212 return False
213213
=== modified file 'product_margin/product_margin.py'
--- product_margin/product_margin.py 2009-01-04 22:12:50 +0000
+++ product_margin/product_margin.py 2010-03-17 11:50:49 +0000
@@ -1,7 +1,7 @@
1# -*- encoding: utf-8 -*-1# -*- encoding: utf-8 -*-
2##############################################################################2##############################################################################
3#3#
4# OpenERP, Open Source Management Solution 4# OpenERP, Open Source Management Solution
5# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved5# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
6# $Id$6# $Id$
7#7#
@@ -25,53 +25,52 @@
25from tools import config25from tools import config
26import time26import time
2727
28states = {
29 'paid': ('paid',),
30 'open_paid': ('open','paid'),
31 'draft_open_paid': ('draft','open','paid')
32}
33
28class product_product(osv.osv):34class product_product(osv.osv):
29 _inherit = "product.product" 35 _inherit = "product.product"
30 36
31 37
32 def _product_margin(self, cr, uid, ids, field_names, arg, context):38 def _product_margin(self, cr, uid, ids, field_names, arg, context):
33 res = {} 39 res = {}
34 for val in self.browse(cr, uid, ids,context=context):40 for val in self.browse(cr, uid, ids,context=context):
35 res[val.id] = {}41 res[val.id] = {}
36 date_from=context.get('date_from', time.strftime('%Y-01-01')) 42 date_from=context.get('date_from', time.strftime('%Y-01-01'))
37 date_to=context.get('date_to', time.strftime('%Y-12-31')) 43 date_to=context.get('date_to', time.strftime('%Y-12-31'))
38 invoice_state=context.get('invoice_state', 'open_paid') 44 invoice_state=context.get('invoice_state', 'open_paid')
39 if 'date_from' in field_names:45 if 'date_from' in field_names:
40 res[val.id]['date_from']=date_from46 res[val.id]['date_from']=date_from
41 if 'date_to' in field_names:47 if 'date_to' in field_names:
42 res[val.id]['date_to']=date_to48 res[val.id]['date_to']=date_to
43 if 'invoice_state' in field_names:49 if 'invoice_state' in field_names:
44 res[val.id]['invoice_state']=invoice_state50 res[val.id]['invoice_state']=invoice_state
4551
46 52 invoice_types=()
47 invoice_types=[]
48 states=[]
49 if invoice_state=='paid':
50 states=['paid']
51 elif invoice_state=='open_paid':
52 states=['open','paid']
53 elif invoice_state=='draft_open_paid':
54 states=['draft','open','paid']
55
56 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:53 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:
57 invoice_types=['out_invoice','in_refund']54 invoice_types=('out_invoice','in_refund')
58 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:55 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:
59 invoice_types=['in_invoice','out_refund']56 invoice_types=('in_invoice','out_refund')
60 if len(invoice_types):57
58 if invoice_types:
61 sql="""59 sql="""
62 select 60 select
63 avg(l.price_unit) as avg_unit_price,61 avg(l.price_unit) as avg_unit_price,
64 sum(l.quantity) as num_qty,62 sum(l.quantity) as num_qty,
65 sum(l.quantity * l.price_unit) as total,63 sum(l.quantity * l.price_unit) as total,
66 sum(l.quantity * product.list_price) as sale_expected,64 sum(l.quantity * product.list_price) as sale_expected,
67 sum(l.quantity * product.standard_price) as normal_cost 65 sum(l.quantity * product.standard_price) as normal_cost
68 from account_invoice_line l66 from account_invoice_line l
69 left join account_invoice i on (l.invoice_id = i.id)67 left join account_invoice i on (l.invoice_id = i.id)
70 left join product_template product on (product.id=l.product_id) 68 left join product_template product on (product.id=l.product_id)
71 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' 69 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
72 """%(val.id,"','".join(states),"','".join(invoice_types),date_from,date_to) 70 """
73 cr.execute(sql)71 cr.execute(sql, (val.id, states[invoice_state],
74 result=cr.fetchall()[0] 72 invoice_types, date_from, date_to))
73 result=cr.fetchall()[0]
75 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:74 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:
76 res[val.id]['sale_avg_price']=result[0] and result[0] or 0.075 res[val.id]['sale_avg_price']=result[0] and result[0] or 0.0
77 res[val.id]['sale_num_invoiced']=result[1] and result[1] or 0.076 res[val.id]['sale_num_invoiced']=result[1] and result[1] or 0.0
@@ -83,8 +82,8 @@
83 res[val.id]['purchase_num_invoiced']=result[1] and result[1] or 0.082 res[val.id]['purchase_num_invoiced']=result[1] and result[1] or 0.0
84 res[val.id]['total_cost']=result[2] and result[2] or 0.083 res[val.id]['total_cost']=result[2] and result[2] or 0.0
85 res[val.id]['normal_cost']=result[4] and result[4] or 0.084 res[val.id]['normal_cost']=result[4] and result[4] or 0.0
86 res[val.id]['purchase_gap']=res[val.id]['normal_cost']-res[val.id]['total_cost'] 85 res[val.id]['purchase_gap']=res[val.id]['normal_cost']-res[val.id]['total_cost']
87 86
88 if 'total_margin' in field_names:87 if 'total_margin' in field_names:
89 res[val.id]['total_margin']=val.turnover-val.total_cost88 res[val.id]['total_margin']=val.turnover-val.total_cost
90 if 'expected_margin' in field_names:89 if 'expected_margin' in field_names:
@@ -92,15 +91,15 @@
92 if 'total_margin_rate' in field_names:91 if 'total_margin_rate' in field_names:
93 res[val.id]['total_margin_rate']=val.turnover and val.total_margin * 100 / val.turnover or 0.092 res[val.id]['total_margin_rate']=val.turnover and val.total_margin * 100 / val.turnover or 0.0
94 if 'expected_margin_rate' in field_names:93 if 'expected_margin_rate' in field_names:
95 res[val.id]['expected_margin_rate']=val.sale_expected and val.expected_margin * 100 / val.sale_expected or 0.0 94 res[val.id]['expected_margin_rate']=val.sale_expected and val.expected_margin * 100 / val.sale_expected or 0.0
96 return res95 return res
97 96
98 _columns = {97 _columns = {
99 'date_from': fields.function(_product_margin, method=True, type='date', string='From Date', multi=True),98 'date_from': fields.function(_product_margin, method=True, type='date', string='From Date', multi=True),
100 'date_to': fields.function(_product_margin, method=True, type='date', string='To Date', multi=True),99 'date_to': fields.function(_product_margin, method=True, type='date', string='To Date', multi=True),
101 'invoice_state': fields.function(_product_margin, method=True, type='selection', selection=[100 'invoice_state': fields.function(_product_margin, method=True, type='selection', selection=[
102 ('paid','Paid'),('open_paid','Open and Paid'),('draft_open_paid','Draft, Open and Paid')101 ('paid','Paid'),('open_paid','Open and Paid'),('draft_open_paid','Draft, Open and Paid')
103 ], string='Invoice State',multi=True, readonly=True), 102 ], string='Invoice State',multi=True, readonly=True),
104 'sale_avg_price' : fields.function(_product_margin, method=True, type='float', string='Avg. Unit Price', multi='sale',help="Avg. Price in Customer Invoices)"),103 'sale_avg_price' : fields.function(_product_margin, method=True, type='float', string='Avg. Unit Price', multi='sale',help="Avg. Price in Customer Invoices)"),
105 'purchase_avg_price' : fields.function(_product_margin, method=True, type='float', string='Avg. Unit Price', multi='purchase',help="Avg. Price in Supplier Invoices "),104 'purchase_avg_price' : fields.function(_product_margin, method=True, type='float', string='Avg. Unit Price', multi='purchase',help="Avg. Price in Supplier Invoices "),
106 'sale_num_invoiced' : fields.function(_product_margin, method=True, type='float', string='# Invoiced', multi='sale',help="Sum of Quantity in Customer Invoices"),105 'sale_num_invoiced' : fields.function(_product_margin, method=True, type='float', string='# Invoiced', multi='sale',help="Sum of Quantity in Customer Invoices"),
107106
=== modified file 'project/project.py'
--- project/project.py 2009-11-17 07:10:35 +0000
+++ project/project.py 2010-03-17 11:50:49 +0000
@@ -64,10 +64,11 @@
64 FROM64 FROM
65 project_task 65 project_task
66 WHERE66 WHERE
67 project_id in ('''+','.join(map(str,ids2))+''') AND67 project_id in %s AND
68 state<>'cancelled'68 state<>'cancelled'
69 GROUP BY69 GROUP BY
70 project_id''')70 project_id''',
71 (tuple(ids2),))
71 progress = dict(map(lambda x: (x[0], (x[1],x[2],x[3])), cr.fetchall()))72 progress = dict(map(lambda x: (x[0], (x[1],x[2],x[3])), cr.fetchall()))
72 for project in self.browse(cr, uid, ids, context=context):73 for project in self.browse(cr, uid, ids, context=context):
73 s = [0.0,0.0,0.0]74 s = [0.0,0.0,0.0]
@@ -166,7 +167,7 @@
166 default['name'] = proj.name+_(' (copy)')167 default['name'] = proj.name+_(' (copy)')
167 res = super(project, self).copy(cr, uid, id, default, context)168 res = super(project, self).copy(cr, uid, id, default, context)
168 ids = self.search(cr, uid, [('parent_id','child_of', [res])])169 ids = self.search(cr, uid, [('parent_id','child_of', [res])])
169 cr.execute('update project_task set active=True where project_id in ('+','.join(map(str,ids))+')')170 cr.execute('update project_task set active=True where project_id in %s', (tuple(ids,)))
170 return res171 return res
171172
172 def duplicate_template(self, cr, uid, ids,context={}):173 def duplicate_template(self, cr, uid, ids,context={}):
@@ -228,8 +229,7 @@
228229
229# Compute: effective_hours, total_hours, progress230# Compute: effective_hours, total_hours, progress
230 def _hours_get(self, cr, uid, ids, field_names, args, context):231 def _hours_get(self, cr, uid, ids, field_names, args, context):
231 task_set = ','.join(map(str, ids))232 cr.execute("SELECT task_id, COALESCE(SUM(hours),0) FROM project_task_work WHERE task_id in %s GROUP BY task_id", (tuple(ids),))
232 cr.execute(("SELECT task_id, COALESCE(SUM(hours),0) FROM project_task_work WHERE task_id in (%s) GROUP BY task_id") % (task_set,))
233 hours = dict(cr.fetchall())233 hours = dict(cr.fetchall())
234 res = {}234 res = {}
235 for task in self.browse(cr, uid, ids, context=context):235 for task in self.browse(cr, uid, ids, context=context):
236236
=== modified file 'purchase/purchase.py'
--- purchase/purchase.py 2010-03-10 09:01:40 +0000
+++ purchase/purchase.py 2010-03-17 11:50:49 +0000
@@ -112,8 +112,9 @@
112 LEFT JOIN112 LEFT JOIN
113 stock_picking p on (p.id=m.picking_id)113 stock_picking p on (p.id=m.picking_id)
114 WHERE114 WHERE
115 p.purchase_id in ('''+','.join(map(str,ids))+''')115 p.purchase_id in %s
116 GROUP BY m.state, p.purchase_id''')116 GROUP BY m.state, p.purchase_id''',
117 (tuple(ids),))
117 for oid,nbr,state in cr.fetchall():118 for oid,nbr,state in cr.fetchall():
118 if state=='cancel':119 if state=='cancel':
119 continue120 continue
120121
=== modified file 'report_account/report_receivable.py'
--- report_account/report_receivable.py 2009-04-15 04:56:13 +0000
+++ report_account/report_receivable.py 2010-03-17 11:50:49 +0000
@@ -105,9 +105,9 @@
105 date1,date2 = period['name'].split(' to ')105 date1,date2 = period['name'].split(' to ')
106 query = "SELECT SUM(credit-debit) FROM account_move_line AS line, account_account as ac \106 query = "SELECT SUM(credit-debit) FROM account_move_line AS line, account_account as ac \
107 WHERE (line.account_id=ac.id) AND ac.type='receivable' \107 WHERE (line.account_id=ac.id) AND ac.type='receivable' \
108 AND (COALESCE(line.date,date) BETWEEN '%s' AND '%s') \108 AND (COALESCE(line.date,date) BETWEEN %s AND %s) \
109 AND (reconcile_id IS NULL) AND ac.active"%(str(date2),str(date1))109 AND (reconcile_id IS NULL) AND ac.active"
110 cr.execute(query)110 cr.execute(query, (date2, date1))
111 amount = cr.fetchone()111 amount = cr.fetchone()
112 amount = amount[0] or 0.00112 amount = amount[0] or 0.00
113 res[period['id']] = amount113 res[period['id']] = amount
114114
=== modified file 'report_analytic_planning/report_analytic_planning.py'
--- report_analytic_planning/report_analytic_planning.py 2009-01-04 22:12:50 +0000
+++ report_analytic_planning/report_analytic_planning.py 2010-03-17 11:50:49 +0000
@@ -119,8 +119,10 @@
119 result = {}119 result = {}
120 for line in self.browse(cr, uid, ids, context):120 for line in self.browse(cr, uid, ids, context):
121 where = ''121 where = ''
122 sqlarg = ()
122 if line.user_id:123 if line.user_id:
123 where='user_id='+str(line.user_id.id)+' and '124 where='user_id=%s and '
125 sqlarg = (line.user_id.id)
124 cr.execute('''select126 cr.execute('''select
125 sum(planned_hours)127 sum(planned_hours)
126 from128 from
@@ -129,11 +131,11 @@
129 '''+where+'''131 '''+where+'''
130 project_id in (select id from project_project where category_id=%s) and132 project_id in (select id from project_project where category_id=%s) and
131 date_close>=%s and133 date_close>=%s and
132 date_close<=%s''', (134 date_close<=%s''',
133 line.account_id.id,135 sqlarg + (
134 line.planning_id.date_from,136 line.account_id.id,
135 line.planning_id.date_to)137 line.planning_id.date_from,
136 )138 line.planning_id.date_to))
137 result[line.id] = cr.fetchone()[0]139 result[line.id] = cr.fetchone()[0]
138 return result140 return result
139 _columns = {141 _columns = {
140142
=== modified file 'report_crm/report_crm.py'
--- report_crm/report_crm.py 2009-03-20 11:28:18 +0000
+++ report_crm/report_crm.py 2010-03-17 11:50:49 +0000
@@ -1,7 +1,7 @@
1# -*- encoding: utf-8 -*-1# -*- encoding: utf-8 -*-
2##############################################################################2##############################################################################
3#3#
4# OpenERP, Open Source Management Solution 4# OpenERP, Open Source Management Solution
5# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved5# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
6# $Id$6# $Id$
7#7#
@@ -111,29 +111,29 @@
111 _name = "report.crm.case.section"111 _name = "report.crm.case.section"
112 _description = "Cases by Section"112 _description = "Cases by Section"
113 _auto = False113 _auto = False
114 114
115 def _get_data(self, cr, uid, ids, field_name, arg, context={}):115 def _get_data(self, cr, uid, ids, field_name, arg, context={}):
116 res = {}116 res = {}
117 state_perc = 0.0117 state_perc = 0.0
118 avg_ans = 0.0118 avg_ans = 0.0
119 119
120 for case in self.browse(cr, uid, ids, context):120 for case in self.browse(cr, uid, ids, context):
121 if field_name != 'avg_answers':121 if field_name != 'avg_answers':
122 state = field_name[5:]122 state = field_name[5:]
123 cr.execute("select count(*) from crm_case where section_id =%s and state='%s'"%(case.section_id.id,state))123 cr.execute("select count(*) from crm_case where section_id =%s and state=%s", (case.section_id.id,state))
124 state_cases = cr.fetchone()[0]124 state_cases = cr.fetchone()[0]
125 perc_state = (state_cases / float(case.nbr_cases) ) * 100125 perc_state = (state_cases / float(case.nbr_cases) ) * 100
126 126
127 res[case.id] = perc_state127 res[case.id] = perc_state
128 else:128 else:
129 cr.execute('select count(*) from crm_case_log l where l.section_id=%s'%(case.section_id.id))129 cr.execute('select count(*) from crm_case_log l where l.section_id=%s', (case.section_id.id,))
130 logs = cr.fetchone()[0]130 logs = cr.fetchone()[0]
131 131
132 avg_ans = logs / case.nbr_cases132 avg_ans = logs / case.nbr_cases
133 res[case.id] = avg_ans 133 res[case.id] = avg_ans
134 134
135 return res135 return res
136 136
137 _columns = {137 _columns = {
138 'name': fields.date('Month', readonly=True),138 'name': fields.date('Month', readonly=True),
139# 'user_id':fields.many2one('res.users', 'User', readonly=True),139# 'user_id':fields.many2one('res.users', 'User', readonly=True),
@@ -181,7 +181,7 @@
181 'create_date' : fields.datetime('Create Date', readonly=True)181 'create_date' : fields.datetime('Create Date', readonly=True)
182 }182 }
183 _order = 'date_closed, create_date'183 _order = 'date_closed, create_date'
184 184
185 def init(self, cr):185 def init(self, cr):
186 cr.execute("""create or replace view report_crm_case_service_dashboard as (186 cr.execute("""create or replace view report_crm_case_service_dashboard as (
187 select187 select
@@ -195,12 +195,12 @@
195 where195 where
196 ((to_date(to_char(cse.date_closed, 'YYYY-MM-dd'),'YYYY-MM-dd') <= CURRENT_DATE)196 ((to_date(to_char(cse.date_closed, 'YYYY-MM-dd'),'YYYY-MM-dd') <= CURRENT_DATE)
197 AND197 AND
198 (to_date(to_char(cse.date_closed, 'YYYY-MM-dd'),'YYYY-MM-dd') > (CURRENT_DATE-15)) 198 (to_date(to_char(cse.date_closed, 'YYYY-MM-dd'),'YYYY-MM-dd') > (CURRENT_DATE-15))
199 AND199 AND
200 cse.state='done')200 cse.state='done')
201 201
202 OR202 OR
203 203
204 ((to_date(to_char(cse.create_date, 'YYYY-MM-dd'),'YYYY-MM-dd') <= CURRENT_DATE)204 ((to_date(to_char(cse.create_date, 'YYYY-MM-dd'),'YYYY-MM-dd') <= CURRENT_DATE)
205 AND205 AND
206 (to_date(to_char(cse.create_date, 'YYYY-MM-dd'),'YYYY-MM-dd') > (CURRENT_DATE-15))206 (to_date(to_char(cse.create_date, 'YYYY-MM-dd'),'YYYY-MM-dd') > (CURRENT_DATE-15))
@@ -211,4 +211,3 @@
211211
212212
213# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:213# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
214
215214
=== modified file 'report_timesheet/report_timesheet.py'
--- report_timesheet/report_timesheet.py 2009-06-09 23:35:34 +0000
+++ report_timesheet/report_timesheet.py 2010-03-17 11:50:49 +0000
@@ -194,11 +194,11 @@
194 account_analytic_line line, hr_department dept,hr_department_user_rel dept_user194 account_analytic_line line, hr_department dept,hr_department_user_rel dept_user
195 where195 where
196 (dept.id = dept_user.department_id AND dept_user.user_id=line.user_id AND line.user_id is not null)196 (dept.id = dept_user.department_id AND dept_user.user_id=line.user_id AND line.user_id is not null)
197 AND (dept.manager_id = """ + str(uid) + """ ) 197 AND (dept.manager_id = %s)
198 AND (line.date <= CURRENT_DATE AND line.date > (CURRENT_DATE-3))198 AND (line.date <= CURRENT_DATE AND line.date > (CURRENT_DATE-3))
199 LIMIT 10199 LIMIT 10
200 )200 )
201 """ )201 """, (uid,))
202202
203report_random_timsheet()203report_random_timsheet()
204204
205205
=== modified file 'sale/sale.py'
--- sale/sale.py 2010-03-02 11:50:52 +0000
+++ sale/sale.py 2010-03-17 11:50:49 +0000
@@ -101,8 +101,8 @@
101 LEFT JOIN101 LEFT JOIN
102 stock_picking p on (p.id=m.picking_id)102 stock_picking p on (p.id=m.picking_id)
103 WHERE103 WHERE
104 p.sale_id in ('''+','.join(map(str, ids))+''')104 p.sale_id in %s
105 GROUP BY m.state, p.sale_id''')105 GROUP BY m.state, p.sale_id''', (tuple(ids),))
106 for oid, nbr, state in cr.fetchall():106 for oid, nbr, state in cr.fetchall():
107 if state == 'cancel':107 if state == 'cancel':
108 continue108 continue
@@ -297,7 +297,7 @@
297 def action_cancel_draft(self, cr, uid, ids, *args):297 def action_cancel_draft(self, cr, uid, ids, *args):
298 if not len(ids):298 if not len(ids):
299 return False299 return False
300 cr.execute('select id from sale_order_line where order_id in ('+','.join(map(str, ids))+')', ('draft',))300 cr.execute('select id from sale_order_line where order_id in %s', (tuple(ids),))
301 line_ids = map(lambda x: x[0], cr.fetchall())301 line_ids = map(lambda x: x[0], cr.fetchall())
302 self.write(cr, uid, ids, {'state': 'draft', 'invoice_ids': [], 'shipped': 0})302 self.write(cr, uid, ids, {'state': 'draft', 'invoice_ids': [], 'shipped': 0})
303 self.pool.get('sale.order.line').write(cr, uid, line_ids, {'invoiced': False, 'state': 'draft', 'invoice_lines': [(6, 0, [])]})303 self.pool.get('sale.order.line').write(cr, uid, line_ids, {'invoiced': False, 'state': 'draft', 'invoice_lines': [(6, 0, [])]})
304304
=== modified file 'scrum/report/_burndown.py'
--- scrum/report/_burndown.py 2009-01-04 22:12:50 +0000
+++ scrum/report/_burndown.py 2010-03-17 11:50:49 +0000
@@ -26,15 +26,15 @@
2626
27def compute_burndown(cr, uid, tasks_id, date_start, date_stop):27def compute_burndown(cr, uid, tasks_id, date_start, date_stop):
28 latest = False28 latest = False
29 if len(tasks_id):29 if tasks_id:
30 cr.execute('select id,create_date,state,planned_hours from project_task where id in ('+','.join(map(str,tasks_id))+') order by create_date')30 cr.execute('select id,create_date,state,planned_hours from project_task where id in %s order by create_date', (tuple(tasks_id),))
31 tasks = cr.fetchall()31 tasks = cr.fetchall()
3232
33 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')33 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),))
3434
35 tasks2 = cr.fetchall()35 tasks2 = cr.fetchall()
3636
37 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')37 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),))
38 tasks2 += cr.fetchall()38 tasks2 += cr.fetchall()
39 tasks2.sort()39 tasks2.sort()
40 else:40 else:
@@ -63,7 +63,4 @@
63 result.append( (int(time.mktime(time.strptime(date_stop,'%Y-%m-%d'))), 0) )63 result.append( (int(time.mktime(time.strptime(date_stop,'%Y-%m-%d'))), 0) )
64 return result64 return result
6565
66
67
68# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:66# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
69
7067
=== modified file 'scrum/report/task_burndown.py'
--- scrum/report/task_burndown.py 2009-01-04 22:12:50 +0000
+++ scrum/report/task_burndown.py 2010-03-17 11:50:49 +0000
@@ -43,9 +43,9 @@
4343
44def burndown_chart(cr, uid, tasks_id, date_start, date_stop):44def burndown_chart(cr, uid, tasks_id, date_start, date_stop):
45 latest = False45 latest = False
46 cr.execute('select id,date_start,state,planned_hours from project_task where id in ('+','.join(map(str,tasks_id))+') order by date_start')46 cr.execute('select id,date_start,state,planned_hours from project_task where id in %s order by date_start', (tuple(tasks_id),))
47 tasks = cr.fetchall()47 tasks = cr.fetchall()
48 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'))48 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'))
49 tasks2 = cr.fetchall()49 tasks2 = cr.fetchall()
50 current_date = date_start50 current_date = date_start
51 total = 051 total = 0
@@ -72,14 +72,14 @@
72 io = StringIO.StringIO()72 io = StringIO.StringIO()
7373
74 if 'date_start' not in datas:74 if 'date_start' not in datas:
75 cr.execute('select min(date_start) from project_task where id in ('+','.join(map(str,ids))+')')75 cr.execute('select min(date_start) from project_task where id in %s', (tuple(ids),))
76 dt = cr.fetchone()[0]76 dt = cr.fetchone()[0]
77 if dt:77 if dt:
78 datas['date_start'] = dt[:10]78 datas['date_start'] = dt[:10]
79 else:79 else:
80 datas['date_start'] = time.strftime('%Y-%m-%d')80 datas['date_start'] = time.strftime('%Y-%m-%d')
81 if 'date_stop' not in datas:81 if 'date_stop' not in datas:
82 cr.execute('select max(date_start),max(date_close) from project_task where id in ('+','.join(map(str,ids))+')')82 cr.execute('select max(date_start),max(date_close) from project_task where id in %s', (tuple(ids),))
83 res = cr.fetchone()83 res = cr.fetchone()
84 datas['date_stop'] = (res[0] and res[0][:10]) or time.strftime('%Y-%m-%d')84 datas['date_stop'] = (res[0] and res[0][:10]) or time.strftime('%Y-%m-%d')
85 if res[1] and datas['date_stop']<res[1]:85 if res[1] and datas['date_stop']<res[1]:
8686
=== modified file 'stock/product.py'
--- stock/product.py 2010-02-22 13:58:43 +0000
+++ stock/product.py 2010-03-17 11:50:49 +0000
@@ -89,37 +89,43 @@
8989
90 from_date=context.get('from_date',False)90 from_date=context.get('from_date',False)
91 to_date=context.get('to_date',False)91 to_date=context.get('to_date',False)
92 date_str=False92 date_str = ''
93 date_args = ()
93 if from_date and to_date:94 if from_date and to_date:
94 date_str="date_planned>='%s' and date_planned<='%s'"%(from_date,to_date)95 date_str = "and date_planned>=%s and date_planned<=%s"
96 date_args = (from_date, to_date)
95 elif from_date:97 elif from_date:
96 date_str="date_planned>='%s'"%(from_date)98 date_str = "and date_planned>=%s"
99 date_args = (from_date,)
97 elif to_date:100 elif to_date:
98 date_str="date_planned<='%s'"%(to_date)101 date_str = "and date_planned<=%s"
102 date_args = (to_date,)
99103
100 if 'in' in what:104 if 'in' in what:
101 # all moves from a location out of the set to a location in the set105 # all moves from a location out of the set to a location in the set
102 cr.execute(106 cr.execute(
103 'select sum(product_qty), product_id, product_uom '\107 'select sum(product_qty), product_id, product_uom '\
104 'from stock_move '\108 'from stock_move '\
105 'where location_id not in ('+location_ids_str+') '\109 'where location_id not in %s '\
106 'and location_dest_id in ('+location_ids_str+') '\110 'and location_dest_id in %s '\
107 'and product_id in ('+prod_ids_str+') '\111 'and product_id in %s '\
108 'and state in ('+states_str+') '+ (date_str and 'and '+date_str+' ' or '') +''\112 'and state in %s '+ date_str + ' '\
109 'group by product_id,product_uom'113 'group by product_id,product_uom',
110 )114 (tuple(location_ids), tuple(location_ids), tuple(ids),
115 tuple(states)) + date_args)
111 results = cr.fetchall()116 results = cr.fetchall()
112 if 'out' in what:117 if 'out' in what:
113 # all moves from a location in the set to a location out of the set118 # all moves from a location in the set to a location out of the set
114 cr.execute(119 cr.execute(
115 'select sum(product_qty), product_id, product_uom '\120 'select sum(product_qty), product_id, product_uom '\
116 'from stock_move '\121 'from stock_move '\
117 'where location_id in ('+location_ids_str+') '\122 'where location_id in %s '\
118 'and location_dest_id not in ('+location_ids_str+') '\123 'and location_dest_id not in %s '\
119 'and product_id in ('+prod_ids_str+') '\124 'and product_id in %s '\
120 'and state in ('+states_str+') '+ (date_str and 'and '+date_str+' ' or '') + ''\125 'and state in %s '+ date_str + ' '\
121 'group by product_id,product_uom'126 'group by product_id,product_uom',
122 )127 (tuple(location_ids), tuple(location_ids), tuple(ids),
128 tuple(states)) + date_args)
123 results2 = cr.fetchall()129 results2 = cr.fetchall()
124 uom_obj = self.pool.get('product.uom')130 uom_obj = self.pool.get('product.uom')
125 uoms = map(lambda x: x[2], results) + map(lambda x: x[2], results2)131 uoms = map(lambda x: x[2], results) + map(lambda x: x[2], results2)
126132
=== modified file 'stock/stock.py'
--- stock/stock.py 2010-03-12 11:08:43 +0000
+++ stock/stock.py 2010-03-17 11:50:49 +0000
@@ -368,13 +368,15 @@
368 ids = [ids]368 ids = [ids]
369 for pick in self.browse(cr, uid, ids, context):369 for pick in self.browse(cr, uid, ids, context):
370 sql_str = """update stock_move set370 sql_str = """update stock_move set
371 date_planned='%s'371 date_planned=%s
372 where372 where
373 picking_id=%d """ % (value, pick.id)373 picking_id=%s """
374 sqlargs = (value, pick.id)
374375
375 if pick.max_date:376 if pick.max_date:
376 sql_str += " and (date_planned='" + pick.max_date + "' or date_planned>'" + value + "')"377 sql_str += " and (date_planned=%s or date_planned>%s)"
377 cr.execute(sql_str)378 sqlargs += (pick.max_date, value)
379 cr.execute(sql_str, sqlargs)
378 return True380 return True
379381
380 def _set_minimum_date(self, cr, uid, ids, name, value, arg, context):382 def _set_minimum_date(self, cr, uid, ids, name, value, arg, context):
@@ -384,12 +386,14 @@
384 ids = [ids]386 ids = [ids]
385 for pick in self.browse(cr, uid, ids, context):387 for pick in self.browse(cr, uid, ids, context):
386 sql_str = """update stock_move set388 sql_str = """update stock_move set
387 date_planned='%s'389 date_planned=%s
388 where390 where
389 picking_id=%s """ % (value, pick.id)391 picking_id=%s """
392 sqlargs = (value, pick.id)
390 if pick.min_date:393 if pick.min_date:
391 sql_str += " and (date_planned='" + pick.min_date + "' or date_planned<'" + value + "')"394 sql_str += " and (date_planned=%s or date_planned<%s)"
392 cr.execute(sql_str)395 sqlargs += (pick.min_date, value)
396 cr.execute(sql_str, sqlargs)
393 return True397 return True
394398
395 def get_min_max_date(self, cr, uid, ids, field_name, arg, context={}):399 def get_min_max_date(self, cr, uid, ids, field_name, arg, context={}):
@@ -405,9 +409,9 @@
405 from409 from
406 stock_move410 stock_move
407 where411 where
408 picking_id in (""" + ','.join(map(str, ids)) + """)412 picking_id in %s
409 group by413 group by
410 picking_id""")414 picking_id""", (tuple(ids),))
411 for pick, dt1, dt2 in cr.fetchall():415 for pick, dt1, dt2 in cr.fetchall():
412 res[pick]['min_date'] = dt1416 res[pick]['min_date'] = dt1
413 res[pick]['max_date'] = dt2417 res[pick]['max_date'] = dt2
@@ -841,11 +845,11 @@
841 from845 from
842 stock_report_prodlots846 stock_report_prodlots
843 where847 where
844 location_id in ('''+','.join(map(str, locations))+''') and848 location_id in %s and
845 prodlot_id in ('''+','.join(map(str, ids))+''')849 prodlot_id in %s
846 group by850 group by
847 prodlot_id851 prodlot_id
848 ''')852 ''', (tuple(locations), tuple(ids)))
849 res.update(dict(cr.fetchall()))853 res.update(dict(cr.fetchall()))
850 return res854 return res
851855
@@ -857,11 +861,11 @@
857 from861 from
858 stock_report_prodlots862 stock_report_prodlots
859 where863 where
860 location_id in ('''+','.join(map(str, locations)) + ''')864 location_id in %s
861 group by865 group by
862 prodlot_id866 prodlot_id
863 having sum(name) ''' + str(args[0][1]) + ''' ''' + str(args[0][2])867 having sum(name) ''' + str(args[0][1]) + ' %s',
864 )868 (tuple(locations), args[0][2]))
865 res = cr.fetchall()869 res = cr.fetchall()
866 ids = [('id', 'in', map(lambda x: x[0], res))]870 ids = [('id', 'in', map(lambda x: x[0], res))]
867 return ids871 return ids
@@ -1204,7 +1208,6 @@
1204 r = res.pop(0)1208 r = res.pop(0)
1205 move_id = self.copy(cr, uid, move.id, {'product_qty': r[0], 'location_id': r[1]})1209 move_id = self.copy(cr, uid, move.id, {'product_qty': r[0], 'location_id': r[1]})
1206 done.append(move_id)1210 done.append(move_id)
1207 #cr.execute('insert into stock_move_history_ids values (%s,%s)', (move.id,move_id))
1208 if done:1211 if done:
1209 count += len(done)1212 count += len(done)
1210 self.write(cr, uid, done, {'state': 'assigned'})1213 self.write(cr, uid, done, {'state': 'assigned'})
@@ -1547,4 +1550,3 @@
1547 )""")1550 )""")
15481551
1549report_stock_lines_date()1552report_stock_lines_date()
1550
15511553
=== modified file 'stock/wizard/inventory_merge_zero.py'
--- stock/wizard/inventory_merge_zero.py 2009-04-09 10:02:19 +0000
+++ stock/wizard/inventory_merge_zero.py 2010-03-17 11:50:49 +0000
@@ -53,11 +53,11 @@
53 raise wizard.except_wizard(_('Warning'),53 raise wizard.except_wizard(_('Warning'),
54 _('Please select one and only one inventory !'))54 _('Please select one and only one inventory !'))
5555
56 loc = str(data['form']['location_id'])56 loc = data['form']['location_id']
5757
58 cr.execute('select distinct location_id,product_id from stock_inventory_line where inventory_id=%s', (data['ids'][0],))58 cr.execute('select distinct location_id,product_id from stock_inventory_line where inventory_id=%s', (data['ids'][0],))
59 inv = cr.fetchall()59 inv = cr.fetchall()
60 cr.execute('select distinct product_id from stock_move where (location_dest_id='+loc+') or (location_id='+loc+')')60 cr.execute('select distinct product_id from stock_move where (location_dest_id=%(location_id)s) or (location_id=%(location_id)s)', data['form'])
61 stock = cr.fetchall()61 stock = cr.fetchall()
62 for s in stock:62 for s in stock:
63 if (loc,s[0]) not in inv:63 if (loc,s[0]) not in inv:
6464
=== modified file 'wiki/wizard/make_index.py'
--- wiki/wizard/make_index.py 2009-04-09 10:02:19 +0000
+++ wiki/wizard/make_index.py 2010-03-17 11:50:49 +0000
@@ -35,10 +35,9 @@
35 ids = data['ids']35 ids = data['ids']
36 pool = pooler.get_pool(cr.dbname)36 pool = pooler.get_pool(cr.dbname)
37 wiki_pool = pool.get('wiki.wiki')37 wiki_pool = pool.get('wiki.wiki')
38 38
39 iid = ','.join([str(x) for x in ids])39 sSQL = "Select id, section from wiki_wiki where id in %s order by section "
40 sSQL = "Select id, section from wiki_wiki where id in (%s) order by section " % (iid)40 cr.execute(sSQL, (tuple(ids),))
41 cr.execute(sSQL)
42 lst0 = cr.fetchall()41 lst0 = cr.fetchall()
43 lst = []42 lst = []
44 ids = {}43 ids = {}