diff --git a/addons/account/account.py b/addons/account/account.py
index 04a0bb5da68..684a3d0f142 100644
--- a/addons/account/account.py
+++ b/addons/account/account.py
@@ -20,6 +20,7 @@
##############################################################################
import time
+from operator import itemgetter
import netsvc
from osv import fields, osv
@@ -33,6 +34,25 @@ from dateutil.relativedelta import relativedelta
from tools import config
+def check_cycle(self, cr, uid, ids):
+ """ climbs the ``self._table.parent_id`` chains for 100 levels or
+ until it can't find any more parent(s)
+
+ Returns true if it runs out of parents (no cycle), false if
+ it can recurse 100 times without ending all chains
+ """
+ level = 100
+ while len(ids):
+ cr.execute('SELECT DISTINCT parent_id '\
+ 'FROM '+self._table+' '\
+ 'WHERE id IN %s '\
+ 'AND parent_id IS NOT NULL',(tuple(ids),))
+ ids = map(itemgetter(0), cr.fetchall())
+ if not level:
+ return False
+ level -= 1
+ return True
+
class account_payment_term(osv.osv):
_name = "account.payment.term"
_description = "Payment Term"
@@ -170,6 +190,7 @@ class account_account(osv.osv):
_name = "account.account"
_description = "Account"
_parent_store = True
+ logger = netsvc.Logger()
def _get_children_and_consol(self, cr, uid, ids, context={}):
ids2=[]
@@ -228,66 +249,88 @@ class account_account(osv.osv):
if ids3:
ids3 = self._get_children_and_consol(cr, uid, ids3, context)
return ids2 + ids3
-
- def __compute(self, cr, uid, ids, field_names, arg, context={}, query=''):
- #compute the balance/debit/credit accordingly to the value of field_name for the given account ids
- mapping = {
- 'balance': "COALESCE(SUM(l.debit),0) - COALESCE(SUM(l.credit), 0) as balance ",
- 'debit': "COALESCE(SUM(l.debit), 0) as debit ",
- 'credit': "COALESCE(SUM(l.credit), 0) as credit "
- }
- #get all the necessary accounts
- ids2 = self._get_children_and_consol(cr, uid, ids, context)
- #compute for each account the balance/debit/credit from the move lines
- accounts = {}
- if ids2:
- aml_query = self.pool.get('account.move.line')._query_get(cr, uid, context=context)
-
- wheres = [""]
- if query.strip():
- wheres.append(query.strip())
- if aml_query.strip():
- wheres.append(aml_query.strip())
- query = " AND ".join(wheres)
-
- cr.execute("SELECT l.account_id as id, " +\
- ' , '.join(map(lambda x: mapping[x], field_names)) +
- "FROM " \
- "account_move_line l " \
- "WHERE " \
- "l.account_id =ANY(%s) " \
- + query +
- " GROUP BY l.account_id",(ids2,))
-
- for res in cr.dictfetchall():
- accounts[res['id']] = res
-
-
- # consolidate accounts with direct children
- ids2.reverse()
- brs = list(self.browse(cr, uid, ids2, context=context))
- sums = {}
- while brs:
- current = brs[0]
- can_compute = True
- for child in current.child_id:
- if child.id not in sums:
- can_compute = False
- try:
- brs.insert(0, brs.pop(brs.index(child)))
- except ValueError:
- brs.insert(0, child)
- if can_compute:
- brs.pop(0)
- for fn in field_names:
- sums.setdefault(current.id, {})[fn] = accounts.get(current.id, {}).get(fn, 0.0)
- if current.child_id:
- sums[current.id][fn] += sum(sums[child.id][fn] for child in current.child_id)
- res = {}
- null_result = dict((fn, 0.0) for fn in field_names)
- for id in ids:
- res[id] = sums.get(id, null_result)
- return res
+
+ def __compute(self, cr, uid, ids, field_names, arg=None, context=None,
+ query='', query_params=()):
+ """ compute the balance, debit and/or credit for the provided
+ account ids
+ Arguments:
+ `ids`: account ids
+ `field_names`: the fields to compute (a list of any of
+ 'balance', 'debit' and 'credit')
+ `arg`: unused fields.function stuff
+ `query`: additional query filter (as a string)
+ `query_params`: parameters for the provided query string
+ (__compute will handle their escaping) as a
+ tuple
+ """
+ mapping = {
+ 'balance': "COALESCE(SUM(l.debit),0) " \
+ "- COALESCE(SUM(l.credit), 0) as balance",
+ 'debit': "COALESCE(SUM(l.debit), 0) as debit",
+ 'credit': "COALESCE(SUM(l.credit), 0) as credit"
+ }
+ #get all the necessary accounts
+ children_and_consolidated = self._get_children_and_consol(cr, uid, ids, context=context)
+ #compute for each account the balance/debit/credit from the move lines
+ accounts = {}
+ if children_and_consolidated:
+ aml_query = self.pool.get('account.move.line')._query_get(cr, uid, context=context)
+
+ wheres = [""]
+ if query.strip():
+ wheres.append(query.strip())
+ if aml_query.strip():
+ wheres.append(aml_query.strip())
+ filters = " AND ".join(wheres)
+ self.logger.notifyChannel('addons.'+self._name, netsvc.LOG_DEBUG,
+ 'Filters: %s'%filters)
+ # IN might not work ideally in case there are too many
+ # children_and_consolidated, in that case join on a
+ # values() e.g.:
+ # SELECT l.account_id as id FROM account_move_line l
+ # INNER JOIN (VALUES (id1), (id2), (id3), ...) AS tmp (id)
+ # ON l.account_id = tmp.id
+ # or make _get_children_and_consol return a query and join on that
+ request = ("SELECT l.account_id as id, " +\
+ ' , '.join(map(mapping.__getitem__, field_names)) +
+ " FROM account_move_line l" \
+ " WHERE l.account_id IN %s " \
+ + filters +
+ " GROUP BY l.account_id")
+ params = (tuple(children_and_consolidated),) + query_params
+ cr.execute(request, params)
+ self.logger.notifyChannel('addons.'+self._name, netsvc.LOG_DEBUG,
+ 'Status: %s'%cr.statusmessage)
+
+ for res in cr.dictfetchall():
+ accounts[res['id']] = res
+
+ # consolidate accounts with direct children
+ children_and_consolidated.reverse()
+ brs = list(self.browse(cr, uid, children_and_consolidated, context=context))
+ sums = {}
+ while brs:
+ current = brs[0]
+ can_compute = True
+ for child in current.child_id:
+ if child.id not in sums:
+ can_compute = False
+ try:
+ brs.insert(0, brs.pop(brs.index(child)))
+ except ValueError:
+ brs.insert(0, child)
+ if can_compute:
+ brs.pop(0)
+ for fn in field_names:
+ sums.setdefault(current.id, {})[fn] = accounts.get(current.id, {}).get(fn, 0.0)
+ if current.child_id:
+ sums[current.id][fn] += sum(sums[child.id][fn] for child in current.child_id)
+ res = {}
+ null_result = dict((fn, 0.0) for fn in field_names)
+ for id in ids:
+ res[id] = sums.get(id, null_result)
+ return res
def _get_company_currency(self, cr, uid, ids, field_name, arg, context={}):
result = {}
@@ -392,8 +435,10 @@ class account_account(osv.osv):
if (obj_self in obj_self.child_consol_ids) or (p_id and (p_id is obj_self.id)):
return False
while(ids):
- cr.execute('select distinct child_id from account_account_consol_rel where parent_id =ANY(%s)',(ids,))
- child_ids = filter(None, map(lambda x: x[0], cr.fetchall()))
+ cr.execute('SELECT DISTINCT child_id '\
+ 'FROM account_account_consol_rel '\
+ 'WHERE parent_id IN %s', (tuple(ids),))
+ child_ids = map(itemgetter(0), cr.fetchall())
c_ids = child_ids
if (p_id and (p_id in c_ids)) or (obj_self.id in c_ids):
return False
@@ -883,7 +928,10 @@ class account_move(osv.osv):
def _amount_compute(self, cr, uid, ids, name, args, context, where =''):
if not ids: return {}
- cr.execute('select move_id,sum(debit) from account_move_line where move_id =ANY(%s) group by move_id',(ids,))
+ cr.execute( 'SELECT move_id, SUM(debit) '\
+ 'FROM account_move_line '\
+ 'WHERE move_id IN %s '\
+ 'GROUP BY move_id', (tuple(ids),))
result = dict(cr.fetchall())
for id in ids:
result.setdefault(id, 0.0)
@@ -982,7 +1030,10 @@ class account_move(osv.osv):
if new_name:
self.write(cr, uid, [move.id], {'name':new_name})
- cr.execute('update account_move set state=%s where id =ANY(%s) ',('posted',ids,))
+ cr.execute('UPDATE account_move '\
+ 'SET state=%s '\
+ 'WHERE id IN %s',
+ ('posted', tuple(ids),))
else:
raise osv.except_osv(_('Integrity Error !'), _('You can not validate a non-balanced entry !\nMake sure you have configured Payment Term properly !\nIt should contain atleast one Payment Term Line with type "Balance" !'))
return True
@@ -995,7 +1046,9 @@ class account_move(osv.osv):
if not line.journal_id.update_posted:
raise osv.except_osv(_('Error !'), _('You can not modify a posted entry of this journal !\nYou should set the journal to allow cancelling entries if you want to do that.'))
if len(ids):
- cr.execute('update account_move set state=%s where id =ANY(%s)',('draft',ids,))
+ cr.execute('UPDATE account_move '\
+ 'SET state=%s '\
+ 'WHERE id IN %s', ('draft', tuple(ids),))
return True
def write(self, cr, uid, ids, vals, context={}):
@@ -1114,7 +1167,10 @@ class account_move(osv.osv):
else:
line_id2 = 0
- cr.execute('select sum('+mode+') from account_move_line where move_id=%s and id<>%s', (move.id, line_id2))
+ cr.execute('SELECT SUM(%s) '\
+ 'FROM account_move_line '\
+ 'WHERE move_id=%s AND id<>%s',
+ (mode, move.id, line_id2))
result = cr.fetchone()[0] or 0.0
cr.execute('update account_move_line set '+mode2+'=%s where id=%s', (result, line_id))
return True
@@ -1268,24 +1324,26 @@ class account_tax_code(osv.osv):
This code is used for some tax declarations.
"""
- def _sum(self, cr, uid, ids, name, args, context, where =''):
- ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)])
+ def _sum(self, cr, uid, ids, name, args, context,where ='', where_params=()):
+ parent_ids = tuple(self.search(cr, uid, [('parent_id', 'child_of', ids)]))
if context.get('based_on', 'invoices') == 'payments':
cr.execute('SELECT line.tax_code_id, sum(line.tax_amount) \
FROM account_move_line AS line, \
account_move AS move \
LEFT JOIN account_invoice invoice ON \
(invoice.move_id = move.id) \
- WHERE line.tax_code_id =ANY(%s) '+where+' \
+ WHERE line.tax_code_id in %s '+where+' \
AND move.id = line.move_id \
AND ((invoice.state = \'paid\') \
OR (invoice.id IS NULL)) \
- GROUP BY line.tax_code_id',(ids2,))
+ GROUP BY line.tax_code_id',
+ (parent_ids,)+where_params)
else:
cr.execute('SELECT line.tax_code_id, sum(line.tax_amount) \
FROM account_move_line AS line \
- WHERE line.tax_code_id =ANY(%s) '+where+' \
- GROUP BY line.tax_code_id',(ids2,))
+ WHERE line.tax_code_id in %s '+where+' \
+ GROUP BY line.tax_code_id',
+ (parent_ids,)+where_params)
res=dict(cr.fetchall())
for record in self.browse(cr, uid, ids, context):
def _rec_get(record):
@@ -1302,12 +1360,14 @@ class account_tax_code(osv.osv):
else:
fiscalyear_id = self.pool.get('account.fiscalyear').find(cr, uid, exception=False)
where = ''
+ where_params = ()
if fiscalyear_id:
pids = map(lambda x: str(x.id), self.pool.get('account.fiscalyear').browse(cr, uid, fiscalyear_id).period_ids)
if pids:
- where = ' and period_id in (' + (','.join(pids))+')'
+ where = ' and period_id in %s'
+ where_params = (tuple(pids),)
return self._sum(cr, uid, ids, name, args, context,
- where=where)
+ where=where, where_params=where_params)
def _sum_period(self, cr, uid, ids, name, args, context):
if 'period_id' in context and context['period_id']:
@@ -1318,7 +1378,7 @@ class account_tax_code(osv.osv):
return dict.fromkeys(ids, 0.0)
period_id = period_id[0]
return self._sum(cr, uid, ids, name, args, context,
- where=' and line.period_id='+str(period_id))
+ where=' and line.period_id=%s', where_params=(period_id,))
_name = 'account.tax.code'
_description = 'Tax Code'
@@ -1366,24 +1426,15 @@ class account_tax_code(osv.osv):
'sign': lambda *args: 1.0,
'notprintable': lambda *a: False,
}
- def _check_recursion(self, cr, uid, ids):
- level = 100
- while len(ids):
- cr.execute('select distinct parent_id from account_tax_code where id =ANY(%s)',(ids,))
- ids = filter(None, map(lambda x:x[0], cr.fetchall()))
- if not level:
- return False
- level -= 1
- return True
-
-
+
def copy(self, cr, uid, id, default=None, context=None):
if default is None:
default = {}
default = default.copy()
default.update({'line_ids': []})
return super(account_tax_code, self).copy(cr, uid, id, default, context)
-
+
+ _check_recursion = check_cycle
_constraints = [
(_check_recursion, 'Error ! You can not create recursive accounts.', ['parent_id'])
]
@@ -1922,16 +1973,7 @@ class account_account_template(osv.osv):
'nocreate': lambda *a: False,
}
- def _check_recursion(self, cr, uid, ids):
- level = 100
- while len(ids):
- cr.execute('select parent_id from account_account_template where id =ANY(%s)',(ids,))
- ids = filter(None, map(lambda x:x[0], cr.fetchall()))
- if not level:
- return False
- level -= 1
- return True
-
+ _check_recursion = check_cycle
_constraints = [
(_check_recursion, 'Error ! You can not create recursive account templates.', ['parent_id'])
]
@@ -2042,16 +2084,7 @@ class account_tax_code_template(osv.osv):
return [(x['id'], (x['code'] and x['code'] + ' - ' or '') + x['name']) \
for x in reads]
- def _check_recursion(self, cr, uid, ids):
- level = 100
- while len(ids):
- cr.execute('select distinct parent_id from account_tax_code_template where id =ANY(%s)',(ids,))
- ids = filter(None, map(lambda x:x[0], cr.fetchall()))
- if not level:
- return False
- level -= 1
- return True
-
+ _check_recursion = check_cycle
_constraints = [
(_check_recursion, 'Error ! You can not create recursive Tax Codes.', ['parent_id'])
]
diff --git a/addons/account/account_move_line.py b/addons/account/account_move_line.py
index 7350596c4e3..3975ae12743 100644
--- a/addons/account/account_move_line.py
+++ b/addons/account/account_move_line.py
@@ -298,9 +298,10 @@ class account_move_line(osv.osv):
for line_id in ids:
res[line_id] = False
cursor.execute('SELECT l.id, i.id ' \
- 'FROM account_move_line l, account_invoice i ' \
- 'WHERE l.move_id = i.move_id ' \
- 'AND l.id =ANY(%s)',(ids,))
+ 'FROM account_move_line l, account_invoice i ' \
+ 'WHERE l.move_id = i.move_id ' \
+ 'AND l.id in %s',
+ (tuple(ids),))
invoice_ids = []
for line_id, invoice_id in cursor.fetchall():
res[line_id] = invoice_id
@@ -620,10 +621,11 @@ class account_move_line(osv.osv):
else:
date = time.strftime('%Y-%m-%d')
- cr.execute('SELECT account_id, reconcile_id \
- FROM account_move_line \
- WHERE id =ANY(%s) \
- GROUP BY account_id,reconcile_id',(ids,))
+ cr.execute('SELECT account_id, reconcile_id '\
+ 'FROM account_move_line '\
+ 'WHERE id IN %s '\
+ 'GROUP BY account_id,reconcile_id',
+ (tuple(ids),))
r = cr.fetchall()
#TODO: move this check to a constraint in the account_move_reconcile object
if (len(r) != 1) and not context.get('fy_closing', False):
diff --git a/addons/account/invoice.py b/addons/account/invoice.py
index d8205ababa7..ac30ee6ce1b 100644
--- a/addons/account/invoice.py
+++ b/addons/account/invoice.py
@@ -20,6 +20,7 @@
##############################################################################
import time
+from operator import itemgetter
import decimal_precision as dp
import netsvc
@@ -564,12 +565,13 @@ class account_invoice(osv.osv):
def move_line_id_payment_get(self, cr, uid, ids, *args):
res = []
if not ids: return res
- cr.execute('select \
- l.id \
- from account_move_line l \
- left join account_invoice i on (i.move_id=l.move_id) \
- where i.id in ('+','.join(map(str,map(int, ids)))+') and l.account_id=i.account_id')
- res = map(lambda x: x[0], cr.fetchall())
+ cr.execute('SELECT l.id '\
+ 'FROM account_move_line l '\
+ 'LEFT JOIN account_invoice i ON (i.move_id=l.move_id) '\
+ 'WHERE i.id IN %s '\
+ 'AND l.account_id=i.account_id',
+ (tuple(ids),))
+ res = map(itemgetter(0), cr.fetchall())
return res
def copy(self, cr, uid, id, default=None, context=None):
@@ -888,8 +890,9 @@ class account_invoice(osv.osv):
def action_number(self, cr, uid, ids, *args):
cr.execute('SELECT id, type, number, move_id, reference ' \
- 'FROM account_invoice ' \
- 'WHERE id IN ('+','.join(map(str, ids))+')')
+ 'FROM account_invoice ' \
+ 'WHERE id IN %s',
+ (tuple(ids),))
obj_inv = self.browse(cr, uid, ids)[0]
for (id, invtype, number, move_id, reference) in cr.fetchall():
if not number:
@@ -1112,7 +1115,9 @@ class account_invoice(osv.osv):
move_ids = [move_id,]
if invoice.move_id:
move_ids.append(invoice.move_id.id)
- cr.execute('SELECT id FROM account_move_line WHERE move_id = ANY(%s)',(move_ids,))
+ cr.execute('SELECT id FROM account_move_line '\
+ 'WHERE move_id in %s',
+ ((move_id, invoice.move_id.id),))
lines = line.browse(cr, uid, map(lambda x: x[0], cr.fetchall()) )
for l in lines+invoice.payment_ids:
if l.account_id.id==src_account_id:
diff --git a/addons/account/partner.py b/addons/account/partner.py
index 215c4286315..dc2acd506a9 100644
--- a/addons/account/partner.py
+++ b/addons/account/partner.py
@@ -18,6 +18,7 @@
# along with this program. If not, see .
#
##############################################################################
+from operator import itemgetter
from osv import fields, osv
import ir
@@ -88,22 +89,19 @@ class res_partner(osv.osv):
_name = 'res.partner'
_inherit = 'res.partner'
_description = 'Partner'
+
def _credit_debit_get(self, cr, uid, ids, field_names, arg, context):
query = self.pool.get('account.move.line')._query_get(cr, uid, context=context)
- cr.execute("""select
- l.partner_id, a.type, sum(l.debit-l.credit)
- from
- account_move_line l
- left join
- account_account a on (l.account_id=a.id)
- where
- a.type =ANY(%s) and
- l.partner_id =ANY(%s) and
- l.reconcile_id is null and
- """+query+"""
- group by
- l.partner_id, a.type
- """,(['receivable','payable'],ids,))
+ cr.execute("""SELECT l.partner_id, a.type, SUM(l.debit-l.credit)
+ FROM account_move_line l
+ LEFT JOIN account_account a ON (l.account_id=a.id)
+ WHERE a.type IN ('receivable','payable')
+ AND l.partner_id in %s
+ AND l.reconcile_id IS NULL
+ AND """ + query + """
+ GROUP BY l.partner_id, a.type
+ """,
+ (tuple(ids),))
tinvert = {
'credit': 'receivable',
'debit': 'payable'
@@ -116,28 +114,34 @@ class res_partner(osv.osv):
if val is None: val=0
res[pid][maps[type]] = (type=='receivable') and val or -val
return res
-
+
+ def _asset_difference_search(self, cr, uid, obj, name, type, args, context=None):
+ if not len(args):
+ return []
+ having_values = tuple(map(itemgetter(2), args))
+ where = ' AND '.join(
+ map(lambda x: '(SUM(debit-credit) %(operator)s %%s)' % {
+ 'operator':x[1]},args))
+ query = self.pool.get('account.move.line')._query_get(cr, uid, context=context)
+ 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),
+ (type,) + having_values)
+ res = cr.fetchall()
+ if not len(res):
+ return [('id','=','0')]
+ return [('id','in',map(itemgetter(0), res))]
+
def _credit_search(self, cr, uid, obj, name, args, context):
- if not len(args):
- return []
- where = ' and '.join(map(lambda x: '(sum(debit-credit)'+x[1]+str(x[2])+')',args))
- query = self.pool.get('account.move.line')._query_get(cr, uid, context={})
- 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',) )
- res = cr.fetchall()
- if not len(res):
- return [('id','=','0')]
- return [('id','in',map(lambda x:x[0], res))]
+ return self._asset_difference_search(cr, uid, obj, name, 'receivable', args, context=context)
def _debit_search(self, cr, uid, obj, name, args, context):
- if not len(args):
- return []
- query = self.pool.get('account.move.line')._query_get(cr, uid, context={})
- where = ' and '.join(map(lambda x: '(sum(debit-credit)'+x[1]+str(x[2])+')',args))
- 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',) )
- res = cr.fetchall()
- if not len(res):
- return [('id','=','0')]
- return [('id','in',map(lambda x:x[0], res))]
+ return self._asset_difference_search(cr, uid, obj, name, 'payable', args, context=context)
_columns = {
'credit': fields.function(_credit_debit_get,
diff --git a/addons/account/project/report/analytic_balance.py b/addons/account/project/report/analytic_balance.py
index f7b909ae452..57209f6d49f 100644
--- a/addons/account/project/report/analytic_balance.py
+++ b/addons/account/project/report/analytic_balance.py
@@ -32,15 +32,9 @@ class account_analytic_balance(report_sxw.rml_parse):
'get_objects': self._get_objects,
'lines_g': self._lines_g,
'move_sum': self._move_sum,
-# 'move_sum_debit': self._move_sum_debit,
-# 'move_sum_credit': self._move_sum_credit,
'sum_all': self._sum_all,
-# 'sum_debit': self._sum_debit,
-# 'sum_credit': self._sum_credit,
'sum_balance': self._sum_balance,
-# 'sum_quantity': self._sum_quantity,
'move_sum_balance': self._move_sum_balance,
-# 'move_sum_quantity': self._move_sum_quantity,
})
self.acc_ids = []
self.read_data = []
@@ -81,10 +75,10 @@ class account_analytic_balance(report_sxw.rml_parse):
sum(aal.amount) AS balance, sum(aal.unit_amount) AS quantity \
FROM account_analytic_line AS aal, account_account AS aa \
WHERE (aal.general_account_id=aa.id) \
- AND (aal.account_id in (" + ','.join(map(str, ids)) + "))\
+ AND (aal.account_id in aal.account_id in %s)\
AND (date>=%s) AND (date<=%s) AND aa.active \
GROUP BY aal.general_account_id, aa.name, aa.code, aal.code \
- ORDER BY aal.code", (date1, date2))
+ ORDER BY aal.code", (tuple(ids),date1, date2))
res = self.cr.dictfetchall()
for r in res:
@@ -107,62 +101,26 @@ class account_analytic_balance(report_sxw.rml_parse):
self.acc_data_dict[account_id] = ids
else:
ids = self.acc_data_dict[account_id]
-
+
+ query_params = (tuple(ids), date1, date2)
if option == "credit" :
self.cr.execute("SELECT -sum(amount) FROM account_analytic_line \
- WHERE account_id =ANY(%s) AND date>=%s AND date<=%s AND amount<0",
- (ids,date1, date2))
+ WHERE account_id in %s AND date>=%s AND date<=%s AND amount<0",query_params)
elif option == "debit" :
self.cr.execute("SELECT sum(amount) FROM account_analytic_line \
- WHERE account_id =ANY(%s)\
- AND date>=%s AND date<=%s AND amount>0",
- (ids,date1, date2))
+ WHERE account_id in %s\
+ AND date>=%s AND date<=%s AND amount>0",query_params)
elif option == "quantity" :
self.cr.execute("SELECT sum(unit_amount) FROM account_analytic_line \
- WHERE account_id =ANY(%s)\
- AND date>=%s AND date<=%s",
- (ids,date1, date2))
+ WHERE account_id in %s\
+ AND date>=%s AND date<=%s",query_params)
return self.cr.fetchone()[0] or 0.0
-
-# def _move_sum_debit(self, account_id, date1, date2):
-# account_analytic_obj = self.pool.get('account.analytic.account')
-# ids = account_analytic_obj.search(self.cr, self.uid,
-# [('parent_id', 'child_of', [account_id])])
-# 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))
-# return self.cr.fetchone()[0] or 0.0
-#
-# def _move_sum_credit(self, account_id, date1, date2):
-# account_analytic_obj = self.pool.get('account.analytic.account')
-# ids = account_analytic_obj.search(self.cr, self.uid,
-# [('parent_id', 'child_of', [account_id])])
-# 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))
-# return self.cr.fetchone()[0] or 0.0
-#
def _move_sum_balance(self, account_id, date1, date2):
debit = self._move_sum(account_id, date1, date2, 'debit')
credit = self._move_sum(account_id, date1, date2, 'credit')
return (debit-credit)
-# def _move_sum_quantity(self, account_id, date1, date2):
-# account_analytic_obj = self.pool.get('account.analytic.account')
-# ids = account_analytic_obj.search(self.cr, self.uid,
-# [('parent_id', 'child_of', [account_id])])
-# self.cr.execute("SELECT sum(unit_amount) \
-# FROM account_analytic_line \
-# WHERE account_id in ("+ ','.join(map(str, ids)) +") \
-# AND date>=%s AND date<=%s",
-# (date1, date2))
-# return self.cr.fetchone()[0] or 0.0
-
def _sum_all(self, accounts, date1, date2, option):
ids = map(lambda x: x['id'], accounts)
if not len(ids):
@@ -174,68 +132,25 @@ class account_analytic_balance(report_sxw.rml_parse):
self.acc_sum_list = ids2
else:
ids2 = self.acc_sum_list
+ query_params = (tuple(ids2), date1, date2)
if option == "debit" :
self.cr.execute("SELECT sum(amount) FROM account_analytic_line \
- WHERE account_id =ANY(%s) AND date>=%s AND date<=%s AND amount>0",
- (ids,date1, date2,))
+ WHERE account_id =ANY(%s) AND date>=%s AND date<=%s AND amount>0",query_params)
elif option == "credit" :
self.cr.execute("SELECT -sum(amount) FROM account_analytic_line \
- WHERE account_id =ANY(%s) AND date>=%s AND date<=%s AND amount<0",
- (ids,date1, date2,))
+ WHERE account_id =ANY(%s) AND date>=%s AND date<=%s AND amount<0",query_params)
elif option == "quantity" :
self.cr.execute("SELECT sum(unit_amount) FROM account_analytic_line \
- WHERE account_id =ANY(%s)AND date>=%s AND date<=%s",
- (ids,date1, date2,))
+ WHERE account_id =ANY(%s)AND date>=%s AND date<=%s",query_params)
return self.cr.fetchone()[0] or 0.0
-# def _sum_debit(self, accounts, date1, date2):
-# ids = map(lambda x: x['id'], accounts)
-# if not len(ids):
-# return 0.0
-# account_analytic_obj = self.pool.get('account.analytic.account')
-# ids2 = account_analytic_obj.search(self.cr, self.uid,
-# [('parent_id', 'child_of', ids)])
-# self.cr.execute("SELECT sum(amount) \
-# FROM account_analytic_line \
-# WHERE account_id IN ("+','.join(map(str, ids2))+") \
-# AND date>=%s AND date<=%s AND amount>0",
-# (date1, date2))
-# return self.cr.fetchone()[0] or 0.0
-#
-# def _sum_credit(self, accounts, date1, date2):
-# ids = map(lambda x: x['id'], accounts)
-# if not len(ids):
-# return 0.0
-# ids = map(lambda x: x['id'], accounts)
-# account_analytic_obj = self.pool.get('account.analytic.account')
-# ids2 = account_analytic_obj.search(self.cr, self.uid,
-# [('parent_id', 'child_of', ids)])
-# self.cr.execute("SELECT -sum(amount) \
-# FROM account_analytic_line \
-# WHERE account_id IN ("+','.join(map(str, ids2))+") \
-# AND date>=%s AND date<=%s AND amount<0",
-# (date1, date2))
-# return self.cr.fetchone()[0] or 0.0
def _sum_balance(self, accounts, date1, date2):
debit = self._sum_all(accounts, date1, date2, 'debit') or 0.0
credit = self._sum_all(accounts, date1, date2, 'credit') or 0.0
return (debit-credit)
-# def _sum_quantity(self, accounts, date1, date2):
-# ids = map(lambda x: x['id'], accounts)
-# if not len(ids):
-# return 0.0
-# account_analytic_obj = self.pool.get('account.analytic.account')
-# ids2 = account_analytic_obj.search(self.cr, self.uid,
-# [('parent_id', 'child_of', ids)])
-# self.cr.execute("SELECT sum(unit_amount) \
-# FROM account_analytic_line \
-# WHERE account_id IN ("+','.join(map(str, ids2))+") \
-# AND date>=%s AND date<=%s",
-# (date1, date2))
-# return self.cr.fetchone()[0] or 0.0
report_sxw.report_sxw('report.account.analytic.account.balance',
'account.analytic.account', 'addons/account/project/report/analytic_balance.rml',
diff --git a/addons/account/project/report/analytic_check.py b/addons/account/project/report/analytic_check.py
index 458827d8bf3..3075a7821bb 100644
--- a/addons/account/project/report/analytic_check.py
+++ b/addons/account/project/report/analytic_check.py
@@ -77,41 +77,6 @@ class account_analytic_analytic_check(report_sxw.rml_parse):
return res
-# def _lines_p(self, date1, date2):
-# res = []
-# acc_obj = self.pool.get('account.account')
-# for a in acc_obj.read(self.cr, self.uid, self.ids, ['name', 'code','sign']):
-# self.cr.execute("SELECT sum(debit), sum(credit) \
-# FROM account_move_line \
-# WHERE date>=%s AND date<=%s AND state<>'draft' AND account_id = %s", (date1, date2, a['id']))
-# (gd, gc) = self.cr.fetchone()
-# gd = gd or 0.0
-# gc = gc or 0.0
-#
-# self.cr.execute("SELECT abs(sum(amount)) AS balance \
-# FROM account_analytic_line \
-# WHERE date>=%s AND date<=%s AND amount*%s>0 AND general_account_id = %s", (date1, date2, a['sign'], a['id']))
-# (ad,) = self.cr.fetchone()
-# ad = ad or 0.0
-# self.cr.execute("SELECT abs(sum(amount)) AS balance \
-# FROM account_analytic_line \
-# WHERE date>=%s AND date<=%s AND amount*%s<0 AND general_account_id = %s", (date1, date2, a['sign'], a['id']))
-# (ac,) = self.cr.fetchone()
-# ac = ac or 0.0
-#
-# res.append({'code': a['code'], 'name': a['name'],
-# 'gen_debit': gd,
-# 'gen_credit': gc,
-# 'ana_debit': ad,
-# 'ana_credit': ac,
-# 'delta_debit': gd - ad,
-# 'delta_credit': gc - ac,})
-# self.sum_gen_deb += gd
-# self.sum_gen_cred += gc
-# self.sum_ana_deb += ad
-# self.sum_ana_cred += ac
-# return res
-
def _gen_deb(self, date1, date2):
return self.sum_gen_deb
diff --git a/addons/account/project/report/cost_ledger.py b/addons/account/project/report/cost_ledger.py
index 9163cd8e0d4..bd6a468db33 100644
--- a/addons/account/project/report/cost_ledger.py
+++ b/addons/account/project/report/cost_ledger.py
@@ -93,15 +93,14 @@ class account_analytic_cost_ledger(report_sxw.rml_parse):
ids = map(lambda x: x.id, accounts)
if not len(ids):
return 0.0
- self.cr.execute("SELECT sum(amount) FROM account_analytic_line WHERE account_id =ANY(%s) AND date>=%s AND date<=%s AND amount>0", (ids, date1, date2,))
+ self.cr.execute("SELECT sum(amount) FROM account_analytic_line WHERE account_id IN %s AND date>=%s AND date<=%s AND amount>0", (tuple(ids), date1, date2,))
return self.cr.fetchone()[0] or 0.0
def _sum_credit(self, accounts, date1, date2):
ids = map(lambda x: x.id, accounts)
if not len(ids):
return 0.0
- ids = map(lambda x: x.id, accounts)
- self.cr.execute("SELECT -sum(amount) FROM account_analytic_line WHERE account_id =ANY(%s) AND date>=%s AND date<=%s AND amount<0", (ids,date1, date2,))
+ self.cr.execute("SELECT -sum(amount) FROM account_analytic_line WHERE account_id in %s AND date>=%s AND date<=%s AND amount<0", (tuple(ids),date1, date2,))
return self.cr.fetchone()[0] or 0.0
def _sum_balance(self, accounts, date1, date2):
diff --git a/addons/account/project/report/inverted_analytic_balance.py b/addons/account/project/report/inverted_analytic_balance.py
index 37f469d4ef8..30703f7ec2c 100644
--- a/addons/account/project/report/inverted_analytic_balance.py
+++ b/addons/account/project/report/inverted_analytic_balance.py
@@ -38,12 +38,17 @@ class account_inverted_analytic_balance(report_sxw.rml_parse):
def _lines_g(self, accounts, date1, date2):
ids = map(lambda x: x.id, accounts)
- self.cr.execute("SELECT aa.name AS name, aa.code AS code, sum(aal.amount) AS balance, sum(aal.unit_amount) AS quantity, aa.id AS id \
+ self.cr.execute("SELECT aa.name AS name, aa.code AS code, "
+ "sum(aal.amount) AS balance, "
+ "sum(aal.unit_amount) AS quantity, aa.id AS id \
FROM account_analytic_line AS aal, account_account AS aa \
- WHERE (aal.general_account_id=aa.id) AND (aal.account_id =ANY(%s)) AND (date>=%s) AND (date<=%s) AND aa.active \
- GROUP BY aal.general_account_id, aa.name, aa.code, aal.code, aa.id ORDER BY aal.code", (ids,date1,date2,))
+ WHERE (aal.general_account_id=aa.id) "
+ "AND (aal.account_id IN %s) "
+ "AND (date>=%s) AND (date<=%s) AND aa.active \
+ GROUP BY aal.general_account_id, aa.name, aa.code, aal.code, aa.id "
+ "ORDER BY aal.code",
+ (tuple(ids), date1, date2))
res = self.cr.dictfetchall()
-
for r in res:
if r['balance'] > 0:
r['debit'] = r['balance']
@@ -58,10 +63,17 @@ class account_inverted_analytic_balance(report_sxw.rml_parse):
def _lines_a(self, accounts, general_account_id, date1, date2):
ids = map(lambda x: x.id, accounts)
- self.cr.execute("SELECT sum(aal.amount) AS balance, sum(aal.unit_amount) AS quantity, aaa.code AS code, aaa.name AS name, account_id \
- FROM account_analytic_line AS aal, account_analytic_account AS aaa \
- WHERE aal.account_id=aaa.id AND aal.account_id =ANY(%s) AND aal.general_account_id=%s AND aal.date>=%s AND aal.date<=%s \
- GROUP BY aal.account_id, general_account_id, aaa.code, aaa.name ORDER BY aal.account_id", (ids,general_account_id, date1, date2,))
+ self.cr.execute("SELECT sum(aal.amount) AS balance, "
+ "sum(aal.unit_amount) AS quantity, "
+ "aaa.code AS code, aaa.name AS name, account_id \
+ FROM account_analytic_line AS aal, "
+ "account_analytic_account AS aaa \
+ WHERE aal.account_id=aaa.id AND aal.account_id IN %s "
+ "AND aal.general_account_id=%s AND aal.date>=%s "
+ "AND aal.date<=%s \
+ GROUP BY aal.account_id, general_account_id, aaa.code, aaa.name "
+ "ORDER BY aal.account_id",
+ (tuple(ids), general_account_id, date1, date2))
res = self.cr.dictfetchall()
aaa_obj = self.pool.get('account.analytic.account')
@@ -86,14 +98,14 @@ class account_inverted_analytic_balance(report_sxw.rml_parse):
ids = map(lambda x: x.id, accounts)
self.cr.execute("SELECT sum(amount) \
FROM account_analytic_line \
- WHERE account_id =ANY(%s) AND date>=%s AND date<=%s AND amount>0", (ids,date1, date2,))
+ WHERE account_id in %s AND date>=%s AND date<=%s AND amount>0", (tuple(ids),date1, date2,))
return self.cr.fetchone()[0] or 0.0
def _sum_credit(self, accounts, date1, date2):
ids = map(lambda x: x.id, accounts)
self.cr.execute("SELECT -sum(amount) \
FROM account_analytic_line \
- WHERE account_id =ANY(%s) AND date>=%s AND date<=%s AND amount<0", (ids,date1, date2,))
+ WHERE account_id in %s AND date>=%s AND date<=%s AND amount<0", (tuple(ids),date1, date2,))
return self.cr.fetchone()[0] or 0.0
def _sum_balance(self, accounts, date1, date2):
@@ -105,7 +117,7 @@ class account_inverted_analytic_balance(report_sxw.rml_parse):
ids = map(lambda x: x.id, accounts)
self.cr.execute("SELECT sum(unit_amount) \
FROM account_analytic_line \
- WHERE account_id =ANY(%s) AND date>=%s AND date<=%s", (ids,date1, date2,))
+ WHERE account_id in %s AND date>=%s AND date<=%s", (tuple(ids),date1, date2,))
return self.cr.fetchone()[0] or 0.0
report_sxw.report_sxw('report.account.analytic.account.inverted.balance', 'account.analytic.account', 'addons/account/project/report/inverted_analytic_balance.rml',parser=account_inverted_analytic_balance, header=False)
diff --git a/addons/account/project/report/quantity_cost_ledger.py b/addons/account/project/report/quantity_cost_ledger.py
index 12bea390eba..6d32f7f5035 100644
--- a/addons/account/project/report/quantity_cost_ledger.py
+++ b/addons/account/project/report/quantity_cost_ledger.py
@@ -52,9 +52,9 @@ class account_analytic_quantity_cost_ledger(report_sxw.rml_parse):
WHERE (aal.account_id=%s) AND (aal.date>=%s) \
AND (aal.date<=%s) AND (aal.general_account_id=aa.id) \
AND aa.active \
- AND (aal.journal_id =ANY(%s) ) \
+ AND (aal.journal_id in %s ) \
GROUP BY aa.code, aa.name, aa.id ORDER BY aa.code",
- (account_id, date1, date2,journal_ids))
+ (account_id, date1, date2, tuple(journal_ids)))
res = self.cr.dictfetchall()
return res
@@ -79,9 +79,9 @@ class account_analytic_quantity_cost_ledger(report_sxw.rml_parse):
account_analytic_journal AS aaj \
WHERE (aal.general_account_id=%s) AND (aal.account_id=%s) \
AND (aal.date>=%s) AND (aal.date<=%s) \
- AND (aal.journal_id=aaj.id) AND (aaj.id =ANY(%s)) \
+ AND (aal.journal_id=aaj.id) AND (aaj.id IN %s) \
ORDER BY aal.date, aaj.code, aal.code",
- (general_account_id, account_id, date1, date2,journal_ids,))
+ (general_account_id, account_id, date1, date2,tuple(journal_ids)))
res = self.cr.dictfetchall()
return res
diff --git a/addons/account/report/aged_trial_balance.py b/addons/account/report/aged_trial_balance.py
index 26e24031c3a..43db65f25c9 100644
--- a/addons/account/report/aged_trial_balance.py
+++ b/addons/account/report/aged_trial_balance.py
@@ -80,13 +80,13 @@ class aged_trial_report(rml_parse.rml_parse):
self.cr.execute("""SELECT partner_id, SUM(debit-credit)
FROM account_move_line AS line, account_account
WHERE (line.account_id = account_account.id)
- AND (account_account.type =ANY(%s))
- AND (partner_id =ANY (%s))
+ AND (account_account.type IN %s)
+ AND (partner_id IN %s)
AND ((reconcile_id IS NULL)
OR (reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > %s )))
AND (account_account.company_id = %s)
AND account_account.active
- GROUP BY partner_id""" , (self.ACCOUNT_TYPE, partner_ids,form['date1'],form['company_id'],))
+ GROUP BY partner_id""" , (tuple(self.ACCOUNT_TYPE), tuple(partner_ids),form['date1'],form['company_id'],))
t = self.cr.fetchall()
for i in t:
totals[i[0]] = i[1]
@@ -97,14 +97,14 @@ class aged_trial_report(rml_parse.rml_parse):
self.cr.execute("""SELECT partner_id, SUM(debit-credit)
FROM account_move_line AS line, account_account
WHERE (line.account_id=account_account.id)
- AND (account_account.type =ANY (%s))
+ AND (account_account.type IN %s)
AND (COALESCE(date_maturity,date) < %s)
- AND (partner_id =ANY (%s))
+ AND (partner_id IN %s)
AND ((reconcile_id IS NULL)
OR (reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > %s )))
AND (account_account.company_id = %s)
AND account_account.active
- GROUP BY partner_id""", (self.ACCOUNT_TYPE, form['date1'], partner_ids,form['date1'], form['company_id'],))
+ GROUP BY partner_id""", (tuple(self.ACCOUNT_TYPE), form['date1'], tuple(partner_ids),form['date1'], form['company_id'],))
t = self.cr.fetchall()
for i in t:
future_past[i[0]] = i[1]
@@ -112,14 +112,14 @@ class aged_trial_report(rml_parse.rml_parse):
self.cr.execute("""SELECT partner_id, SUM(debit-credit)
FROM account_move_line AS line, account_account
WHERE (line.account_id=account_account.id)
- AND (account_account.type =ANY (%s))
+ AND (account_account.type IN %s)
AND (COALESCE(date_maturity,date) > %s)
- AND (partner_id =ANY (%s))
+ AND (partner_id IN %s)
AND ((reconcile_id IS NULL)
OR (reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > %s )))
AND (account_account.company_id = %s)
AND account_account.active
- GROUP BY partner_id""" , (self.ACCOUNT_TYPE, form['date1'], partner_ids, form['date1'], form['company_id'],))
+ GROUP BY partner_id""" , (tuple(self.ACCOUNT_TYPE), form['date1'], tuple(partner_ids), form['date1'], form['company_id'],))
t = self.cr.fetchall()
for i in t:
future_past[i[0]] = i[1]
@@ -131,14 +131,14 @@ class aged_trial_report(rml_parse.rml_parse):
self.cr.execute("""SELECT partner_id, SUM(debit-credit)
FROM account_move_line AS line, account_account
WHERE (line.account_id=account_account.id)
- AND (account_account.type =ANY (%s))
+ AND (account_account.type IN %s)
AND (COALESCE(date_maturity,date) BETWEEN %s AND %s)
- AND (partner_id =ANY (%s))
+ AND (partner_id IN %s)
AND ((reconcile_id IS NULL)
OR (reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > %s )))
AND (account_account.company_id = %s)
AND account_account.active
- GROUP BY partner_id""" , (self.ACCOUNT_TYPE, form[str(i)]['start'], form[str(i)]['stop'],partner_ids ,form['date1'] ,form['company_id'],))
+ GROUP BY partner_id""" , (tuple(self.ACCOUNT_TYPE), form[str(i)]['start'], form[str(i)]['stop'], tuple(partner_ids) ,form['date1'] ,form['company_id'],))
t = self.cr.fetchall()
d = {}
diff --git a/addons/account/report/general_journal.py b/addons/account/report/general_journal.py
index 112ce970694..6f31f9abcea 100644
--- a/addons/account/report/general_journal.py
+++ b/addons/account/report/general_journal.py
@@ -18,7 +18,7 @@
# along with this program. If not, see .
#
##############################################################################
-
+from operator import itemgetter
import pooler
import time
from report import report_sxw
@@ -41,10 +41,12 @@ class journal_print(report_sxw.rml_parse):
def set_context(self, objects, data, ids, report_type = None):
super(journal_print, self).set_context(objects, data, ids, report_type)
- self.cr.execute('select period_id, journal_id from account_journal_period where id =ANY(%s)',(ids,))
+ self.cr.execute('SELECT period_id, journal_id '
+ 'FROM account_journal_period '
+ 'WHERE id IN %s',
+ (tuple(ids),))
res = self.cr.fetchall()
- self.period_ids = map(lambda x:x[0],res)
- self.journal_ids = map(lambda x:x[1],res)
+ self.period_ids, self.journal_ids = zip(*res)
# returns a list of period objs
def periods(self, journal_period_objs):
@@ -74,7 +76,14 @@ class journal_print(report_sxw.rml_parse):
periods.append(data.period_id.id)
for period in periods:
period_data = self.pool.get('account.period').browse(self.cr, self.uid, period)
- self.cr.execute('select j.code, j.name, sum(l.debit) as debit, sum(l.credit) as credit from account_move_line l left join account_journal j on (l.journal_id=j.id) where period_id=%s and journal_id =ANY(%s) and l.state<>\'draft\' group by j.id, j.code, j.name', (period,journal_id,))
+ self.cr.execute(
+ 'SELECT j.code, j.name, '
+ 'SUM(l.debit) AS debit, SUM(l.credit) AS credit '
+ 'FROM account_move_line l '
+ 'LEFT JOIN account_journal j ON (l.journal_id=j.id) '
+ 'WHERE period_id=%s AND journal_id IN %s '
+ 'AND l.state<>\'draft\' '
+ 'GROUP BY j.id, j.code, j.name', (period, tuple(journal_id)))
res = self.cr.dictfetchall()
res[0].update({'period_name':period_data.name})
res[0].update({'pid':period})
@@ -82,45 +91,60 @@ class journal_print(report_sxw.rml_parse):
return lines_data
if not self.journal_ids:
return []
- self.cr.execute('select j.code, j.name, sum(l.debit) as debit, sum(l.credit) as credit from account_move_line l left join account_journal j on (l.journal_id=j.id) where period_id=%s and journal_id =ANY(%s) and l.state<>\'draft\' group by j.id, j.code, j.name', (period_id,self.journal_ids,))
+ print " self.journal_ids >>. " , self.journal_ids
+ 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 %s '
+ 'AND l.state<>\'draft\' '
+ 'GROUP BY j.id, j.code, j.name',
+ (period_id, tuple(self.journal_ids)))
res = self.cr.dictfetchall()
return res
def _sum_debit_period(self, period_id,journal_id=None):
- if type(journal_id)==type([]):
- self.cr.execute('select sum(debit) from account_move_line where period_id=%s and journal_id =ANY(%s) and state<>\'draft\'', (period_id,journal_id,))
- return self.cr.fetchone()[0] or 0.0
- if not self.journal_ids:
+ journals = journal_id or self.journal_ids
+ if not journals:
return 0.0
- self.cr.execute('select sum(debit) from account_move_line where period_id=%s and journal_id =ANY(%s) and state<>\'draft\'', (period_id,self.journal_ids,))
-
+ self.cr.execute('SELECT SUM(debit) FROM account_move_line '
+ 'WHERE period_id=%s AND journal_id IN %s '
+ 'AND state<>\'draft\'',
+ (period_id, tuple(journals)))
return self.cr.fetchone()[0] or 0.0
def _sum_credit_period(self, period_id,journal_id=None):
- if type(journal_id)==type([]):
- self.cr.execute('select sum(credit) from account_move_line where period_id=%s and journal_id =ANY(%s) and state<>\'draft\'', (period_id,journal_id,))
- return self.cr.fetchone()[0] or 0.0
- if not self.journal_ids:
+ journals = journal_id or self.journal_ids
+ if not journals:
return 0.0
- self.cr.execute('select sum(credit) from account_move_line where period_id=%s and journal_id =ANY(%s) and state<>\'draft\'', (period_id,self.journal_ids,))
+ self.cr.execute('SELECT SUM(credit) FROM account_move_line '
+ 'WHERE period_id=%s AND journal_id IN %s '
+ 'AND state<>\'draft\'',
+ (period_id, tuple(journals)))
return self.cr.fetchone()[0] or 0.0
def _sum_debit(self,period_id=None,journal_id=None):
- if type(period_id)==type([]):
- self.cr.execute('select sum(debit) from account_move_line where period_id =ANY(%s) and journal_id =ANY(%s) and state<>\'draft\'',(period_id,journal_id,))
- return self.cr.fetchone()[0] or 0.0
- if not self.journal_ids or not self.period_ids:
+ journals = journal_id or self.journal_ids
+ periods = period_id or self.period_ids
+ if not (journals and periods):
return 0.0
- self.cr.execute('select sum(debit) from account_move_line where period_id =ANY(%s) and journal_id =ANY(%s) and state<>\'draft\'',(self.period_ids,self.journal_ids,))
+ self.cr.execute('SELECT SUM(debit) FROM account_move_line '
+ 'WHERE period_id IN %s '
+ 'AND journal_id IN %s '
+ 'AND state<>\'draft\'',
+ (tuple(periods), tuple(journals)))
return self.cr.fetchone()[0] or 0.0
def _sum_credit(self,period_id=None,journal_id=None):
- if type(period_id)==type([]):
- self.cr.execute('select sum(credit) from account_move_line where period_id =ANY(%s) and journal_id =ANY(%s) and state<>\'draft\'',(period_id,journal_id,))
- return self.cr.fetchone()[0] or 0.0
- if not self.journal_ids or not self.period_ids:
+ periods = period_id or self.period_ids
+ journals = journal_id or self.journal_ids
+ if not (periods and journals):
return 0.0
- self.cr.execute('select sum(credit) from account_move_line where period_id =ANY(%s) and journal_id =ANY(%s) and state<>\'draft\'',(self.period_ids,self.journal_ids,))
+ self.cr.execute('SELECT SUM(credit) FROM account_move_line '
+ 'WHERE period_id IN %s '
+ 'AND journal_id IN %s '
+ 'AND state<>\'draft\'',
+ (tuple(periods), tuple(journals)))
return self.cr.fetchone()[0] or 0.0
report_sxw.report_sxw('report.account.general.journal', 'account.journal.period', 'addons/account/report/general_journal.rml', parser=journal_print)
report_sxw.report_sxw('report.account.general.journal.wiz', 'account.journal.period', 'addons/account/report/wizard_general_journal.rml', parser=journal_print, header=False)
diff --git a/addons/account/report/general_ledger.py b/addons/account/report/general_ledger.py
index e2c24fe96d2..699721e528f 100644
--- a/addons/account/report/general_ledger.py
+++ b/addons/account/report/general_ledger.py
@@ -87,14 +87,15 @@ class general_ledger(rml_parse.rml_parse):
#periods = form['periods'][0][2]
if not periods:
sql = """
- Select min(p.date_start) as start_date,max(p.date_stop) as stop_date from account_period as p where p.fiscalyear_id = """ + str(form['fiscalyear']) + """
+ 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
"""
+ sqlargs = (form['fiscalyear'],)
else:
- periods_id = ','.join(map(str, periods))
sql = """
- Select min(p.date_start) as start_date,max(p.date_stop) as stop_date from account_period as p where p.id in ( """ + periods_id + """)
+ 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
"""
- self.cr.execute(sql)
+ sqlargs = (tuple(periods),)
+ self.cr.execute(sql, sqlargs)
res = self.cr.dictfetchall()
borne_min = res[0]['start_date']
borne_max = res[0]['stop_date']
@@ -105,15 +106,22 @@ class general_ledger(rml_parse.rml_parse):
periods = form['periods']
#periods = form['periods'][0][2]
if not periods:
- sql = """
- Select min(p.date_start) as start_date,max(p.date_stop) as stop_date from account_period as p where p.fiscalyear_id = """ + str(form['fiscalyear']) + """
- """
+ sql = """
+ SELECT MIN(p.date_start) AS start_date,
+ MAX(p.date_stop) AS stop_date
+ FROM account_period AS p
+ WHERE p.fiscalyear_id = %s
+ """
+ sqlargs = (form['fiscalyear'],)
else:
- periods_id = ','.join(map(str, periods))
sql = """
- Select min(p.date_start) as start_date,max(p.date_stop) as stop_date from account_period as p where p.id in ( """ + periods_id + """)
+ 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
"""
- self.cr.execute(sql)
+ sqlargs = (tuple(periods),)
+ self.cr.execute(sql, sqlargs)
res = self.cr.dictfetchall()
period_min = res[0]['start_date']
period_max = res[0]['stop_date']
@@ -196,8 +204,12 @@ class general_ledger(rml_parse.rml_parse):
else:
## We will now compute solde initiaux
for move in res:
- SOLDEINIT = "SELECT sum(l.debit) AS sum_debit, sum(l.credit) AS sum_credit FROM account_move_line l WHERE l.account_id = " + str(move.id) + " AND l.date < '" + self.borne_date['max_date'] + "'" + " AND l.date > '" + self.borne_date['min_date'] + "'"
- self.cr.execute(SOLDEINIT)
+ 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"
+ self.cr.execute(SOLDEINIT, (move.id, self.borne_date['max_date'],self.borne_date['min_date']))
resultat = self.cr.dictfetchall()
if resultat[0] :
if resultat[0]['sum_debit'] == None:
@@ -322,7 +334,8 @@ class general_ledger(rml_parse.rml_parse):
return 0.0
self.cr.execute("SELECT sum(debit) "\
"FROM account_move_line l "\
- "WHERE l.account_id in ("+','.join(map(str, self.child_ids))+") AND "+self.query)
+ "WHERE l.account_id in %s AND "+self.query,
+ (tuple(self.child_ids),))
sum_debit = self.cr.fetchone()[0] or 0.0
return sum_debit
@@ -331,7 +344,8 @@ class general_ledger(rml_parse.rml_parse):
return 0.0
self.cr.execute("SELECT sum(credit) "\
"FROM account_move_line l "\
- "WHERE l.account_id in ("+','.join(map(str, self.child_ids))+") AND "+self.query)
+ "WHERE l.account_id in %s AND "+self.query,
+ (tuple(self.child_ids),))
## Add solde init to the result
#
sum_credit = self.cr.fetchone()[0] or 0.0
@@ -342,7 +356,8 @@ class general_ledger(rml_parse.rml_parse):
return 0.0
self.cr.execute("SELECT (sum(debit) - sum(credit)) as tot_solde "\
"FROM account_move_line l "\
- "WHERE l.account_id in ("+','.join(map(str, self.child_ids))+") AND "+self.query)
+ "WHERE l.account_id in %s AND "+self.query,
+ (tuple(self.child_ids),))
sum_solde = self.cr.fetchone()[0] or 0.0
return sum_solde
diff --git a/addons/account/report/partner_balance.py b/addons/account/report/partner_balance.py
index f296475cb3f..fed1bff126b 100644
--- a/addons/account/report/partner_balance.py
+++ b/addons/account/report/partner_balance.py
@@ -29,7 +29,6 @@ class partner_balance(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context):
super(partner_balance, self).__init__(cr, uid, name, context=context)
self.date_lst = []
- self.date_lst_string = ''
self.account_ids = ''
self.localcontext.update( {
'time': time,
@@ -166,28 +165,24 @@ class partner_balance(report_sxw.rml_parse):
self.transform_both_into_date_array(data)
- ##
- self.date_lst_string =''
- if self.date_lst:
- self.date_lst_string = '\'' + '\',\''.join(map(str, self.date_lst)) + '\''
## Compute Code
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
#
if (data['form']['result_selection'] == 'customer' ):
- self.ACCOUNT_TYPE = ['receivable']
+ self.ACCOUNT_TYPE = ('receivable',)
elif (data['form']['result_selection'] == 'supplier'):
- self.ACCOUNT_TYPE = ['payable']
+ self.ACCOUNT_TYPE = ('payable',)
else:
- self.ACCOUNT_TYPE = ['payable','receivable']
+ self.ACCOUNT_TYPE = ('payable','receivable')
#
self.cr.execute("SELECT a.id " \
"FROM account_account a " \
"LEFT JOIN account_account_type t " \
"ON (a.type = t.code) " \
"WHERE a.company_id = %s " \
- "AND a.type =ANY(%s) "\
- "AND a.active", (data['form']['company_id'],self.ACCOUNT_TYPE,))
+ "AND a.type IN %s " \
+ "AND a.active", (data['form']['company_id'],self.ACCOUNT_TYPE))
self.account_ids = [a for (a,) in self.cr.fetchall()]
super(partner_balance, self).set_context(objects, data, ids, report_type)
@@ -197,7 +192,7 @@ class partner_balance(report_sxw.rml_parse):
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
full_account = []
result_tmp = 0.0
- if self.date_lst_string:
+ if self.date_lst:
self.cr.execute(
"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, " \
"CASE WHEN sum(debit) > sum(credit) " \
@@ -211,16 +206,17 @@ class partner_balance(report_sxw.rml_parse):
"(SELECT sum(debit-credit) " \
"FROM account_move_line l " \
"WHERE partner_id = p.id " \
- "AND l.date IN (" + self.date_lst_string + ") " \
+ "AND l.date IN %s " \
"AND blocked = TRUE " \
") AS enlitige " \
"FROM account_move_line l LEFT JOIN res_partner p ON (l.partner_id=p.id) " \
"JOIN account_account ac ON (l.account_id = ac.id)" \
- "WHERE ac.type =ANY(%s) "
- "AND l.date IN (" + self.date_lst_string + ") " \
- "AND ac.company_id = %s" \
+ "WHERE ac.type IN %s " \
+ "AND l.date IN %s " \
+ "AND ac.company_id = %s " \
"GROUP BY p.id, p.ref, p.name,l.account_id,ac.name,ac.code " \
- "ORDER BY l.account_id,p.name",(self.ACCOUNT_TYPE,data['form']['company_id'],))
+ "ORDER BY l.account_id,p.name",
+ (tuple(self.date_lst), self.ACCOUNT_TYPE, tuple(self.date_lst), data['form']['company_id']))
res = self.cr.dictfetchall()
for r in res:
full_account.append(r)
@@ -353,12 +349,13 @@ class partner_balance(report_sxw.rml_parse):
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
result_tmp = 0.0
temp_res = 0.0
- if self.date_lst_string:
+ if self.date_lst:
self.cr.execute(
"SELECT sum(debit) " \
"FROM account_move_line AS l " \
- "WHERE l.account_id =ANY(%s)" \
- "AND l.date IN (" + self.date_lst_string + ")" ,(self.account_ids,))
+ "WHERE l.account_id IN %s" \
+ "AND l.date IN %s",
+ (tuple(self.account_ids), tuple(self.date_lst)))
temp_res = float(self.cr.fetchone()[0] or 0.0)
result_tmp = result_tmp + temp_res
@@ -371,12 +368,13 @@ class partner_balance(report_sxw.rml_parse):
result_tmp = 0.0
temp_res = 0.0
- if self.date_lst_string:
+ if self.date_lst:
self.cr.execute(
"SELECT sum(credit) " \
"FROM account_move_line AS l " \
- "WHERE l.account_id =ANY(%s)" \
- "AND l.date IN (" + self.date_lst_string + ")" ,(self.account_ids,))
+ "WHERE l.account_id IN %s" \
+ "AND l.date IN %s",
+ (tuple(self.account_ids), tuple(self.date_lst),))
temp_res = float(self.cr.fetchone()[0] or 0.0)
result_tmp = result_tmp + temp_res
@@ -388,13 +386,14 @@ class partner_balance(report_sxw.rml_parse):
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
result_tmp = 0.0
temp_res = 0.0
- if self.date_lst_string:
+ if self.date_lst:
self.cr.execute(
"SELECT sum(debit-credit) " \
"FROM account_move_line AS l " \
- "WHERE l.account_id =ANY(%s)" \
- "AND l.date IN (" + self.date_lst_string + ")"\
- "AND l.blocked=TRUE " ,(self.account_ids,))
+ "WHERE l.account_id IN %s" \
+ "AND l.date IN %s " \
+ "AND l.blocked=TRUE ",
+ (tuple(self.account_ids), tuple(self.date_lst),))
temp_res = float(self.cr.fetchone()[0] or 0.0)
result_tmp = result_tmp + temp_res
@@ -406,16 +405,17 @@ class partner_balance(report_sxw.rml_parse):
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
result_tmp = 0.0
a = 0.0
- if self.date_lst_string:
+ if self.date_lst:
self.cr.execute(
"SELECT CASE WHEN sum(debit) > sum(credit) " \
"THEN sum(debit) - sum(credit) " \
"ELSE 0 " \
"END " \
"FROM account_move_line AS l " \
- "WHERE l.account_id =ANY(%s)" \
- "AND l.date IN (" + self.date_lst_string + ")" \
- "GROUP BY l.partner_id",(self.account_ids,))
+ "WHERE l.account_id IN %s" \
+ "AND l.date IN %s " \
+ "GROUP BY l.partner_id",
+ (tuple(self.account_ids), tuple(self.date_lst),))
a = self.cr.fetchone()[0]
if self.cr.fetchone() != None:
@@ -433,16 +433,17 @@ class partner_balance(report_sxw.rml_parse):
result_tmp = 0.0
a = 0.0
- if self.date_lst_string:
+ if self.date_lst:
self.cr.execute(
"SELECT CASE WHEN sum(debit) < sum(credit) " \
"THEN sum(credit) - sum(debit) " \
"ELSE 0 " \
"END " \
"FROM account_move_line AS l " \
- "WHERE l.account_id =ANY(%s)" \
- "AND l.date IN (" + self.date_lst_string + ")" \
- "GROUP BY l.partner_id",(self.account_ids,))
+ "WHERE l.account_id IN %s" \
+ "AND l.date IN %s " \
+ "GROUP BY l.partner_id",
+ (tuple(self.account_ids), tuple(self.date_lst),))
a = self.cr.fetchone()[0] or 0.0
if self.cr.fetchone() != None:
diff --git a/addons/account/report/tax_report.py b/addons/account/report/tax_report.py
index daa010a0453..2075b1f139b 100644
--- a/addons/account/report/tax_report.py
+++ b/addons/account/report/tax_report.py
@@ -28,7 +28,6 @@ from report import report_sxw
class tax_report(rml_parse.rml_parse):
_name = 'report.account.vat.declaration'
def __init__(self, cr, uid, name, context={}):
- print "tax______init", name, context
super(tax_report, self).__init__(cr, uid, name, context=context)
self.localcontext.update({
'time': time,
@@ -86,9 +85,10 @@ class tax_report(rml_parse.rml_parse):
def _get_period(self, period_id, context={}):
return self.pool.get('account.period').browse(self.cr, self.uid, period_id, context=context).name
- def _get_general(self, tax_code_id,period_list ,company_id, based_on, context={}):
+ def _get_general(self, tax_code_id, period_list ,company_id, based_on, context={}):
res=[]
obj_account = self.pool.get('account.account')
+ periods_ids = tuple(period_list)
if based_on == 'payments':
self.cr.execute('SELECT SUM(line.tax_amount) AS tax_amount, \
SUM(line.debit) AS debit, \
@@ -107,11 +107,11 @@ class tax_report(rml_parse.rml_parse):
AND line.account_id = account.id \
AND account.company_id = %s \
AND move.id = line.move_id \
- AND line.period_id =ANY(%s) \
+ AND line.period_id IN %s \
AND ((invoice.state = %s) \
OR (invoice.id IS NULL)) \
GROUP BY account.id,account.name,account.code', ('draft', tax_code_id,
- company_id, period_list, 'paid',))
+ company_id, periods_ids, 'paid',))
else :
self.cr.execute('SELECT SUM(line.tax_amount) AS tax_amount, \
@@ -127,10 +127,10 @@ class tax_report(rml_parse.rml_parse):
AND line.tax_code_id = %s \
AND line.account_id = account.id \
AND account.company_id = %s \
- AND line.period_id =ANY(%s)\
+ AND line.period_id IN %s\
AND account.active \
GROUP BY account.id,account.name,account.code', ('draft', tax_code_id,
- company_id, period_list,))
+ company_id, periods_ids,))
res = self.cr.dictfetchall()
#AND line.period_id IN ('+ period_sql_list +') \
diff --git a/addons/account/wizard/account_balance_report.py b/addons/account/wizard/account_balance_report.py
index b131ff3123a..5d02f9fa972 100644
--- a/addons/account/wizard/account_balance_report.py
+++ b/addons/account/wizard/account_balance_report.py
@@ -117,7 +117,7 @@ class account_balance_report(osv.osv_memory):
context = {}
sql = """
SELECT f.id, f.date_start, f.date_stop FROM account_fiscalyear f Where %s between f.date_start and f.date_stop """
- cr.execute(sql,(data['form']['date_from'],))
+ cr.execute(sql, (data['form']['date_from'],))
res = cr.dictfetchall()
if res:
diff --git a/addons/account/wizard/account_fiscalyear_close.py b/addons/account/wizard/account_fiscalyear_close.py
index c71c85ea4a3..56b6410e3a2 100644
--- a/addons/account/wizard/account_fiscalyear_close.py
+++ b/addons/account/wizard/account_fiscalyear_close.py
@@ -160,10 +160,10 @@ class account_fiscalyear_close(osv.osv_memory):
'WHERE b.account_id = %s ' \
'AND b.reconcile_id is NOT NULL ' \
'AND a.reconcile_id = b.reconcile_id ' \
- 'AND b.period_id =ANY(%s)'\
- 'AND a.period_id =ANY(%s)' \
+ 'AND b.period_id IN %s'\
+ 'AND a.period_id IN %s' \
'ORDER BY id ' \
- 'LIMIT %s OFFSET %s', (account.id,period_ids,periods_fy2,limit, offset))
+ 'LIMIT %s OFFSET %s', (account.id,tuple(period_ids),tuple(periods_fy2),limit, offset))
result = cr.dictfetchall()
if not result:
break
diff --git a/addons/account/wizard/account_general_ledger_report.py b/addons/account/wizard/account_general_ledger_report.py
index 9809f4aad89..ad5e74786b0 100644
--- a/addons/account/wizard/account_general_ledger_report.py
+++ b/addons/account/wizard/account_general_ledger_report.py
@@ -96,7 +96,7 @@ class account_general_ledger_report(osv.osv_memory):
context = {}
sql = """
SELECT f.id, f.date_start, f.date_stop FROM account_fiscalyear f Where %s between f.date_start and f.date_stop """
- cr.execute(sql,(data['form']['date_from'],))
+ cr.execute(sql, (data['form']['date_from'],))
res = cr.dictfetchall()
if res:
if (data['form']['date_to'] > res[0]['date_stop'] or data['form']['date_to'] < res[0]['date_start']):
diff --git a/addons/account/wizard/account_open_closed_fiscalyear.py b/addons/account/wizard/account_open_closed_fiscalyear.py
index 552e630125d..1648394b04f 100644
--- a/addons/account/wizard/account_open_closed_fiscalyear.py
+++ b/addons/account/wizard/account_open_closed_fiscalyear.py
@@ -37,16 +37,7 @@ class account_open_closed_fiscalyear(osv.osv_memory):
period_journal = data_fyear.end_journal_period_id
ids_move = self.pool.get('account.move').search(cr,uid,[('journal_id','=',period_journal.journal_id.id),('period_id','=',period_journal.period_id.id)])
if ids_move:
- cr.execute('delete from account_move where id =ANY(%s)',(ids_move,))
- #cr.execute('UPDATE account_journal_period ' \
- # 'SET state = %s ' \
- # 'WHERE period_id IN (SELECT id FROM account_period WHERE fiscalyear_id = %s)',
- # ('draft',data_fyear))
- #cr.execute('UPDATE account_period SET state = %s ' \
- # 'WHERE fiscalyear_id = %s', ('draft',data_fyear))
- #cr.execute('UPDATE account_fiscalyear ' \
- # 'SET state = %s, end_journal_period_id = null '\
- # 'WHERE id = %s', ('draft',data_fyear))
+ cr.execute('delete from account_move where id IN %s', (tuple(ids_move),))
return {}
account_open_closed_fiscalyear()
diff --git a/addons/account/wizard/account_partner_balance_report.py b/addons/account/wizard/account_partner_balance_report.py
index 0c330ed6d1e..c6d82128256 100644
--- a/addons/account/wizard/account_partner_balance_report.py
+++ b/addons/account/wizard/account_partner_balance_report.py
@@ -72,7 +72,6 @@ class account_partner_balance(osv.osv_memory):
'model': 'res.partner',
'form': self.read(cr, uid, ids, [])[0],
}
-
if data['form']['state'] == 'bydate' :
return self._check_date(cr, uid, data, context)
if data['form']['state'] == 'byperiod':
@@ -89,7 +88,7 @@ class account_partner_balance(osv.osv_memory):
def _check_date(self, cr, uid, data, context):
sql = """
SELECT f.id, f.date_start, f.date_stop FROM account_fiscalyear f Where %s between f.date_start and f.date_stop """
- cr.execute(sql,(data['form']['date1'],))
+ cr.execute(sql, (data['form']['date1'],))
res = cr.dictfetchall()
if res:
if (data['form']['date2'] > res[0]['date_stop'] or data['form']['date2'] < res[0]['date_start']):
diff --git a/addons/account/wizard/account_third_party_ledger.py b/addons/account/wizard/account_third_party_ledger.py
index 7a6514e17c2..daff801f3bd 100644
--- a/addons/account/wizard/account_third_party_ledger.py
+++ b/addons/account/wizard/account_third_party_ledger.py
@@ -112,7 +112,7 @@ class account_partner_ledger(osv.osv_memory):
context = {}
sql = """
SELECT f.id, f.date_start, f.date_stop FROM account_fiscalyear f Where %s between f.date_start and f.date_stop """
- cr.execute(sql,(data['form']['date1'],))
+ cr.execute(sql, (data['form']['date1'],))
res = cr.dictfetchall()
if res:
if (data['form']['date2'] > res[0]['date_stop'] or data['form']['date2'] < res[0]['date_start']):
diff --git a/addons/account_analytic_analysis/account_analytic_analysis.py b/addons/account_analytic_analysis/account_analytic_analysis.py
index 742ef74cc84..c77d9cd8b56 100644
--- a/addons/account_analytic_analysis/account_analytic_analysis.py
+++ b/addons/account_analytic_analysis/account_analytic_analysis.py
@@ -32,31 +32,29 @@ class account_analytic_account(osv.osv):
def _ca_invoiced_calc(self, cr, uid, ids, name, arg, context={}):
res = {}
- ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)])
- if ids2:
- acc_set = ",".join(map(str, ids2))
+ parent_ids = tuple(self.search(cr, uid, [('parent_id', 'child_of', ids)]))
+ if parent_ids:
cr.execute("select account_analytic_line.account_id, COALESCE(sum(amount_currency),0.0) \
from account_analytic_line \
join account_analytic_journal \
on account_analytic_line.journal_id = account_analytic_journal.id \
- where account_analytic_line.account_id =ANY(%s) \
+ where account_analytic_line.account_id IN %s \
and account_analytic_journal.type = 'sale' \
- group by account_analytic_line.account_id" ,(ids2,))
+ group by account_analytic_line.account_id" ,(parent_ids,))
for account_id, sum in cr.fetchall():
res[account_id] = round(sum,2)
- return self._compute_currency_for_level_tree(cr, uid, ids, ids2, res, acc_set, context)
+ return self._compute_currency_for_level_tree(cr, uid, ids, parent_ids, res, context)
def _ca_to_invoice_calc(self, cr, uid, ids, name, arg, context={}):
res = {}
res2 = {}
- ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)])
- if ids2:
+ parent_ids = tuple(self.search(cr, uid, [('parent_id', 'child_of', ids)]))
+ if parent_ids:
# Amount uninvoiced hours to invoice at sale price
# Warning
# This computation doesn't take care of pricelist !
# Just consider list_price
- acc_set = ",".join(map(str, ids2))
cr.execute("""SELECT account_analytic_account.id, \
COALESCE(sum (product_template.list_price * \
account_analytic_line.unit_amount * \
@@ -73,11 +71,11 @@ class account_analytic_account(osv.osv):
on account_analytic_account.id = account_analytic_line.account_id \
JOIN hr_timesheet_invoice_factor \
on hr_timesheet_invoice_factor.id = account_analytic_account.to_invoice \
- WHERE account_analytic_account.id =ANY(%s) \
+ WHERE account_analytic_account.id IN %s \
AND account_analytic_line.invoice_id is null \
AND account_analytic_line.to_invoice IS NOT NULL \
and account_analytic_journal.type in ('purchase','general') \
- GROUP BY account_analytic_account.id;""",(ids2,))
+ GROUP BY account_analytic_account.id;""",(parent_ids,))
for account_id, sum in cr.fetchall():
res[account_id] = round(sum,2)
@@ -96,17 +94,17 @@ class account_analytic_account(osv.osv):
def _hours_qtt_non_invoiced_calc (self, cr, uid, ids, name, arg, context={}):
res = {}
- ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)])
- if ids2:
+ parent_ids = tuple(self.search(cr, uid, [('parent_id', 'child_of', ids)]))
+ if parent_ids:
cr.execute("select account_analytic_line.account_id, COALESCE(sum(unit_amount),0.0) \
from account_analytic_line \
join account_analytic_journal \
on account_analytic_line.journal_id = account_analytic_journal.id \
- where account_analytic_line.account_id =ANY(%s) \
+ where account_analytic_line.account_id IN %s \
and account_analytic_journal.type='general' \
and invoice_id is null \
AND to_invoice IS NOT NULL \
- GROUP BY account_analytic_line.account_id;",(ids2,))
+ GROUP BY account_analytic_line.account_id;",(parent_ids,))
for account_id, sum in cr.fetchall():
res[account_id] = round(sum,2)
for obj_id in ids:
@@ -121,15 +119,15 @@ class account_analytic_account(osv.osv):
def _hours_quantity_calc(self, cr, uid, ids, name, arg, context={}):
res = {}
- ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)])
- if ids2:
+ parent_ids = tuple(self.search(cr, uid, [('parent_id', 'child_of', ids)]))
+ if parent_ids:
cr.execute("select account_analytic_line.account_id,COALESCE(SUM(unit_amount),0.0) \
from account_analytic_line \
join account_analytic_journal \
on account_analytic_line.journal_id = account_analytic_journal.id \
- where account_analytic_line.account_id =ANY(%s) \
+ where account_analytic_line.account_id IN %s \
and account_analytic_journal.type='general' \
- GROUP BY account_analytic_line.account_id",(ids2,))
+ GROUP BY account_analytic_line.account_id",(parent_ids,))
ff = cr.fetchall()
for account_id, sum in ff:
res[account_id] = round(sum,2)
@@ -145,30 +143,29 @@ class account_analytic_account(osv.osv):
def _total_cost_calc(self, cr, uid, ids, name, arg, context={}):
res = {}
- ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)])
- if ids2:
- acc_set = ",".join(map(str, ids2))
+ parent_ids = tuple(self.search(cr, uid, [('parent_id', 'child_of', ids)]))
+ if parent_ids:
cr.execute("""select account_analytic_line.account_id,COALESCE(sum(amount_currency),0.0) \
from account_analytic_line \
join account_analytic_journal \
on account_analytic_line.journal_id = account_analytic_journal.id \
- where account_analytic_line.account_id =ANY(%s) \
+ where account_analytic_line.account_id IN %s \
and amount<0 \
- GROUP BY account_analytic_line.account_id""",(ids2,))
+ GROUP BY account_analytic_line.account_id""",(parent_ids,))
for account_id, sum in cr.fetchall():
res[account_id] = round(sum,2)
- return self._compute_currency_for_level_tree(cr, uid, ids, ids2, res, acc_set, context)
+ return self._compute_currency_for_level_tree(cr, uid, ids, parent_ids, res, context)
# TODO Take care of pricelist and purchase !
def _ca_theorical_calc(self, cr, uid, ids, name, arg, context={}):
res = {}
res2 = {}
- ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)])
+ parent_ids = tuple(self.search(cr, uid, [('parent_id', 'child_of', ids)]))
# Warning
# This computation doesn't take care of pricelist !
# Just consider list_price
- if ids2:
+ if parent_ids:
cr.execute("""select account_analytic_line.account_id as account_id, \
COALESCE(sum((account_analytic_line.unit_amount * pt.list_price) \
- (account_analytic_line.unit_amount * pt.list_price \
@@ -184,10 +181,10 @@ class account_analytic_account(osv.osv):
on (a.id=account_analytic_line.account_id) \
join hr_timesheet_invoice_factor hr \
on (hr.id=a.to_invoice) \
- where account_analytic_line.account_id =ANY(%s) \
+ where account_analytic_line.account_id IN %s \
and a.to_invoice IS NOT NULL \
and account_analytic_journal.type in ('purchase','general')
- GROUP BY account_analytic_line.account_id""",(ids2,))
+ GROUP BY account_analytic_line.account_id""",(parent_ids,))
for account_id, sum in cr.fetchall():
res2[account_id] = round(sum,2)
@@ -207,13 +204,13 @@ class account_analytic_account(osv.osv):
def _last_worked_date_calc (self, cr, uid, ids, name, arg, context={}):
res = {}
- ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)])
- if ids2:
+ parent_ids = tuple(self.search(cr, uid, [('parent_id', 'child_of', ids)]))
+ if parent_ids:
cr.execute("select account_analytic_line.account_id, max(date) \
from account_analytic_line \
- where account_id =ANY(%s) \
+ where account_id IN %s \
and invoice_id is null \
- GROUP BY account_analytic_line.account_id" ,(ids2,))
+ GROUP BY account_analytic_line.account_id" ,(parent_ids,))
for account_id, sum in cr.fetchall():
res[account_id] = sum
for obj_id in ids:
@@ -228,16 +225,16 @@ class account_analytic_account(osv.osv):
def _last_invoice_date_calc (self, cr, uid, ids, name, arg, context={}):
res = {}
- ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)])
- if ids2:
+ parent_ids = tuple(self.search(cr, uid, [('parent_id', 'child_of', ids)]))
+ if parent_ids:
cr.execute ("select account_analytic_line.account_id, \
date(max(account_invoice.date_invoice)) \
from account_analytic_line \
join account_invoice \
on account_analytic_line.invoice_id = account_invoice.id \
- where account_analytic_line.account_id =ANY(%s) \
+ where account_analytic_line.account_id IN %s \
and account_analytic_line.invoice_id is not null \
- GROUP BY account_analytic_line.account_id",(ids2,))
+ GROUP BY account_analytic_line.account_id",(parent_ids,))
for account_id, sum in cr.fetchall():
res[account_id] = sum
for obj_id in ids:
@@ -252,13 +249,13 @@ class account_analytic_account(osv.osv):
def _last_worked_invoiced_date_calc (self, cr, uid, ids, name, arg, context={}):
res = {}
- ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)])
- if ids2:
+ parent_ids = tuple(self.search(cr, uid, [('parent_id', 'child_of', ids)]))
+ if parent_ids:
cr.execute("select account_analytic_line.account_id, max(date) \
from account_analytic_line \
- where account_id =ANY(%s) \
+ where account_id IN %s \
and invoice_id is not null \
- GROUP BY account_analytic_line.account_id;",(ids2,))
+ GROUP BY account_analytic_line.account_id;",(parent_ids,))
for account_id, sum in cr.fetchall():
res[account_id] = sum
for obj_id in ids:
@@ -346,10 +343,10 @@ class account_analytic_account(osv.osv):
def _month(self, cr, uid, ids, name, arg, context=None):
res = {}
for id in ids:
- ids2 = self.search(cr, uid, [('parent_id', 'child_of', [id])])
- if ids2:
+ parent_ids = tuple(self.search(cr, uid, [('parent_id', 'child_of', ids)]))
+ if parent_ids:
cr.execute('SELECT DISTINCT(month_id) FROM account_analytic_analysis_summary_month ' \
- 'WHERE account_id =ANY(%s) AND unit_amount <> 0.0',(ids2,))
+ 'WHERE account_id IN %s AND unit_amount <> 0.0',(parent_ids,))
res[id] = [int(id * 1000000 + int(x[0])) for x in cr.fetchall()]
else:
res[id] = []
@@ -360,10 +357,10 @@ class account_analytic_account(osv.osv):
cr.execute('SELECT MAX(id) FROM res_users')
max_user = cr.fetchone()[0]
for id in ids:
- ids2 = self.search(cr, uid, [('parent_id', 'child_of', [id])])
- if ids2:
+ parent_ids = tuple(self.search(cr, uid, [('parent_id', 'child_of', ids)]))
+ if parent_ids:
cr.execute('SELECT DISTINCT("user") FROM account_analytic_analysis_summary_user ' \
- 'WHERE account_id =ANY(%s) AND unit_amount <> 0.0',(ids2,))
+ 'WHERE account_id IN %s AND unit_amount <> 0.0',(parent_ids,))
res[id] = [int((id * max_user) + x[0]) for x in cr.fetchall()]
else:
res[id] = []
@@ -405,12 +402,12 @@ class account_analytic_account_summary_user(osv.osv):
max_user = cr.fetchone()[0]
account_ids = [int(str(x/max_user - (x%max_user == 0 and 1 or 0))) for x in ids]
user_ids = [int(str(x-((x/max_user - (x%max_user == 0 and 1 or 0)) *max_user))) for x in ids]
- account_ids2 = account_obj.search(cr, uid, [('parent_id', 'child_of', account_ids)])
- if account_ids2:
+ parent_ids = tuple(self.search(cr, uid, [('parent_id', 'child_of', account_ids)]))
+ if parent_ids:
cr.execute('SELECT id, unit_amount ' \
'FROM account_analytic_analysis_summary_user ' \
- 'WHERE account_id =ANY(%s) ' \
- 'AND "user" =ANY(%s)',(account_ids2, user_ids,))
+ 'WHERE account_id IN %s ' \
+ 'AND "user" IN %s',(parent_ids, user_ids,))
for sum_id, unit_amount in cr.fetchall():
res[sum_id] = unit_amount
for obj_id in ids:
@@ -570,12 +567,12 @@ class account_analytic_account_summary_month(osv.osv):
account_obj = self.pool.get('account.analytic.account')
account_ids = [int(str(int(x))[:-6]) for x in ids]
month_ids = [int(str(int(x))[-6:]) for x in ids]
- account_ids2 = account_obj.search(cr, uid, [('parent_id', 'child_of', account_ids)])
- if account_ids2:
+ parent_ids = tuple(self.search(cr, uid, [('parent_id', 'child_of', account_ids)]))
+ if parent_ids:
cr.execute('SELECT id, unit_amount ' \
'FROM account_analytic_analysis_summary_month ' \
- 'WHERE account_id =ANY(%s) ' \
- 'AND month_id =ANY(%s) ',(account_ids2, month_ids,))
+ 'WHERE account_id IN %s ' \
+ 'AND month_id IN %s ',(parent_ids, month_ids,))
for sum_id, unit_amount in cr.fetchall():
res[sum_id] = unit_amount
for obj_id in ids:
diff --git a/addons/account_payment/account_move_line.py b/addons/account_payment/account_move_line.py
index 07fbcbbb237..27455183afd 100644
--- a/addons/account_payment/account_move_line.py
+++ b/addons/account_payment/account_move_line.py
@@ -18,7 +18,7 @@
# along with this program. If not, see .
#
##############################################################################
-
+from operator import itemgetter
from osv import fields, osv
from tools.translate import _
@@ -42,7 +42,7 @@ class account_move_line(osv.osv):
WHERE move_line_id = ml.id
AND po.state != 'cancel') as amount
FROM account_move_line ml
- WHERE id =ANY(%s)""" ,(ids,))
+ WHERE id IN %s""", (tuple(ids),))
r=dict(cr.fetchall())
return r
@@ -58,8 +58,10 @@ class account_move_line(osv.osv):
END - coalesce(sum(pl.amount_currency), 0)
FROM payment_line pl
INNER JOIN payment_order po ON (pl.order_id = po.id)
- WHERE move_line_id = l.id AND po.state != 'cancel')''' \
- + x[1] + str(x[2])+' ',args))
+ WHERE move_line_id = l.id
+ AND po.state != 'cancel'
+ ) %(operator)s %%s ''' % {'operator': x[1]}, args))
+ sql_args = tuple(map(itemgetter(2), args))
cr.execute(('''select id
from account_move_line l
@@ -68,7 +70,7 @@ class account_move_line(osv.osv):
where type=%s and active)
and reconcile_id is null
and credit > 0
- and ''' + where + ' and ' + query), ('payable',) )
+ and ''' + where + ' and ' + query), ('payable',)+sql_args )
res = cr.fetchall()
if not len(res):
diff --git a/addons/account_payment/payment.py b/addons/account_payment/payment.py
index 8e300f7072a..fc0277d448a 100644
--- a/addons/account_payment/payment.py
+++ b/addons/account_payment/payment.py
@@ -66,7 +66,6 @@ class payment_mode(osv.osv):
where pm.id = %s """, [payment_code])
return [x[0] for x in cr.fetchall()]
-
payment_mode()
@@ -151,19 +150,9 @@ class payment_line(osv.osv):
_name = 'payment.line'
_description = 'Payment Line'
- #~ def partner_payable(self, cr, uid, ids, name, args, context={}):
- #~ if not ids: return {}
- #~ partners= self.read(cr, uid, ids, ['partner_id'], context)
- #~ partners= dict(map(lambda x: (x['id'], x['partner_id'][0]), partners))
- #~ debit = self.pool.get('res.partner')._debit_get(cr, uid,
- #~ partners.values(), name, args, context)
- #~ for i in partners:
- #~ partners[i] = debit[partners[i]]
- #~ return partners
def translate(self, orig):
return {
-# "to_pay": "credit",
"due_date": "date_maturity",
"reference": "ref"}.get(orig, orig)
@@ -225,8 +214,8 @@ class payment_line(osv.osv):
from account_move_line ml
inner join payment_line pl
on (ml.id = pl.move_line_id)
- where pl.id =ANY(%s)""",
- (self.translate(name),ids,))
+ where pl.id IN %%s"""% self.translate(name),
+ (tuple(ids),))
res = dict(cr.fetchall())
if name == 'partner_id':
@@ -245,61 +234,6 @@ class payment_line(osv.osv):
res.setdefault(id, (False, ""))
return res
-# def _currency(self, cursor, user, ids, name, args, context=None):
-# if not ids:
-# return {}
-# res = {}
-#
-# currency_obj = self.pool.get('res.currency')
-# account_obj = self.pool.get('account.account')
-# cursor.execute('''SELECT pl.id, ml.currency_id, ml.account_id
-# FROM account_move_line ml
-# INNER JOIN payment_line pl
-# ON (ml.id = pl.move_line_id)
-# WHERE pl.id in (''' + ','.join([str(x) for x in ids]) + ')')
-#
-# res2 = {}
-# account_ids = []
-# for payment_line_id, currency_id, account_id in cursor.fetchall():
-# res2[payment_line_id] = [currency_id, account_id]
-# account_ids.append(account_id)
-#
-# account2currency_id = {}
-# for account in account_obj.browse(cursor, user, account_ids,
-# context=context):
-# account2currency_id[account.id] = account.company_currency_id.id
-#
-# for payment_line_id in ids:
-# if res2[payment_line_id][0]:
-# res[payment_line_id] = res2[payment_line_id][0]
-# else:
-# res[payment_line_id] = \
-# account2currency_id[res2[payment_line_id][1]]
-#
-# currency_names = {}
-# for currency_id, name in currency_obj.name_get(cursor, user, res.values(),
-# context=context):
-# currency_names[currency_id] = name
-# for payment_line_id in ids:
-# res[payment_line_id] = (res[payment_line_id],
-# currency_names[res[payment_line_id]])
-# return res
-#
-# def _to_pay_currency(self, cursor, user, ids, name , args, context=None):
-# if not ids:
-# return {}
-#
-# cursor.execute('''SELECT pl.id,
-# CASE WHEN ml.amount_currency < 0
-# THEN - ml.amount_currency
-# ELSE ml.credit
-# END
-# FROM account_move_line ml
-# INNER JOIN payment_line pl
-# ON (ml.id = pl.move_line_id)
-# WHERE pl.id in (''' + ','.join([str(x) for x in ids]) + ')')
-# return dict(cursor.fetchall())
-
def _amount(self, cursor, user, ids, name, args, context=None):
if not ids:
return {}
@@ -335,15 +269,6 @@ class payment_line(osv.osv):
else:
return self.pool.get('res.currency').search(cr, uid, [('rate','=',1.0)])[0]
-# def select_move_lines(*a):
-# print a
-# return []
-
-# def create(self, cr, uid, vals, context):
-# print "created!!!"
-# vals['company_currency'] = self._get_currency(cr, uid, context)
-# return super(payment_line, self).create(cr, uid, vals, context)
-
def _get_ml_inv_ref(self, cr, uid, ids, *a):
res={}
for id in self.browse(cr, uid, ids):
@@ -378,11 +303,6 @@ class payment_line(osv.osv):
'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.'),
'amount_currency': fields.float('Amount in Partner Currency', digits=(16,2),
required=True, help='Payment amount in the partner currency'),
-# 'to_pay_currency': fields.function(_to_pay_currency, string='To Pay',
-# method=True, type='float',
-# help='Amount to pay in the partner currency'),
-# 'currency': fields.function(_currency, string='Currency',
-# method=True, type='many2one', obj='res.currency'),
'currency': fields.many2one('res.currency','Partner Currency',required=True),
'company_currency': fields.many2one('res.currency','Company Currency',readonly=True),
'bank_id': fields.many2one('res.partner.bank', 'Destination Bank account'),
@@ -392,21 +312,12 @@ class payment_line(osv.osv):
'amount': fields.function(_amount, string='Amount in Company Currency',
method=True, type='float',
help='Payment amount in the company currency'),
-# 'to_pay': fields.function(select_by_name, string="To Pay", method=True,
-# type='float', help='Amount to pay in the company currency'),
-# 'due_date': fields.function(select_by_name, string="Due date",
-# method=True, type='date'),
'ml_date_created': fields.function(_get_ml_created_date, string="Effective Date",
method=True, type='date',help="Invoice Effective Date"),
-# 'reference': fields.function(select_by_name, string="Ref", method=True,
-# type='char'),
'ml_maturity_date': fields.function(_get_ml_maturity_date, method=True, type='date', string='Maturity Date'),
'ml_inv_ref': fields.function(_get_ml_inv_ref, method=True, type='many2one', relation='account.invoice', string='Invoice Ref.'),
'info_owner': fields.function(info_owner, string="Owner Account", method=True, type="text",help='Address of the Main Partner'),
'info_partner': fields.function(info_partner, string="Destination Account", method=True, type="text",help='Address of the Ordering Customer.'),
-# 'partner_payable': fields.function(partner_payable, string="Partner payable", method=True, type='float'),
-# 'value_date': fields.function(_value_date, string='Value Date',
-# method=True, type='date'),
'date': fields.date('Payment Date',help="If no payment date is specified, the bank will treat this payment line directly"),
'create_date': fields.datetime('Created' ,readonly=True),
'state': fields.selection([('normal','Free'), ('structured','Structured')], 'Communication Type', required=True)
diff --git a/addons/account_voucher/voucher.py b/addons/account_voucher/voucher.py
index f7ff9ad9ef1..596693801a6 100644
--- a/addons/account_voucher/voucher.py
+++ b/addons/account_voucher/voucher.py
@@ -440,7 +440,7 @@ class account_voucher(osv.osv):
def action_number(self, cr, uid, ids, *args):
cr.execute('SELECT id, type, number, move_id, reference ' \
'FROM account_voucher ' \
- 'WHERE id =ANY(%s)',(ids,))
+ 'WHERE id IN %s',(tuple(ids),))
for (id, invtype, number, move_id, reference) in cr.fetchall():
if not number:
number = self.pool.get('ir.sequence').get(cr, uid, invtype)
diff --git a/addons/analytic/project.py b/addons/analytic/project.py
index a3425c3925b..f6004b82d07 100644
--- a/addons/analytic/project.py
+++ b/addons/analytic/project.py
@@ -33,10 +33,10 @@ class account_analytic_account(osv.osv):
_name = 'account.analytic.account'
_description = 'Analytic Account'
- def _compute_currency_for_level_tree(self, cr, uid, ids, ids2, res, acc_set, context={}):
+ def _compute_currency_for_level_tree(self, cr, uid, ids, ids2, res, context={}):
# Handle multi-currency on each level of analytic account
# This is a refactoring of _balance_calc computation
- cr.execute("SELECT a.id, r.currency_id FROM account_analytic_account a INNER JOIN res_company r ON (a.company_id = r.id) where a.id in (%s)" % acc_set)
+ cr.execute("SELECT a.id, r.currency_id FROM account_analytic_account a INNER JOIN res_company r ON (a.company_id = r.id) where a.id IN %s" , (tuple(ids2),))
currency= dict(cr.fetchall())
res_currency= self.pool.get('res.currency')
for id in ids:
@@ -61,13 +61,11 @@ class account_analytic_account(osv.osv):
def _credit_calc(self, cr, uid, ids, name, arg, context={}):
res = {}
- ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)])
- acc_set = ",".join(map(str, ids2))
-
+ parent_ids = tuple(self.search(cr, uid, [('parent_id', 'child_of', ids)]))
for i in ids:
res.setdefault(i,0.0)
- if not ids2:
+ if not parent_ids:
return res
where_date = ''
@@ -75,19 +73,17 @@ class account_analytic_account(osv.osv):
where_date += " AND l.date >= '" + context['from_date'] + "'"
if context.get('to_date',False):
where_date += " AND l.date <= '" + context['to_date'] + "'"
- cr.execute("SELECT a.id, COALESCE(SUM(l.amount_currency),0) FROM account_analytic_account a LEFT JOIN account_analytic_line l ON (a.id=l.account_id "+where_date+") WHERE l.amount_currency<0 and a.id =ANY(%s) GROUP BY a.id",(ids2,))
+ cr.execute("SELECT a.id, COALESCE(SUM(l.amount_currency),0) FROM account_analytic_account a LEFT JOIN account_analytic_line l ON (a.id=l.account_id "+where_date+") WHERE l.amount_currency<0 and a.id IN %s GROUP BY a.id",(tuple(parent_ids),))
r = dict(cr.fetchall())
- return self._compute_currency_for_level_tree(cr, uid, ids, ids2, r, acc_set, context)
+ return self._compute_currency_for_level_tree(cr, uid, ids, parent_ids, r, context)
def _debit_calc(self, cr, uid, ids, name, arg, context={}):
res = {}
- ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)])
- acc_set = ",".join(map(str, ids2))
-
+ parent_ids = tuple(self.search(cr, uid, [('parent_id', 'child_of', ids)]))
for i in ids:
res.setdefault(i,0.0)
- if not ids2:
+ if not parent_ids:
return res
where_date = ''
@@ -95,19 +91,17 @@ class account_analytic_account(osv.osv):
where_date += " AND l.date >= '" + context['from_date'] + "'"
if context.get('to_date',False):
where_date += " AND l.date <= '" + context['to_date'] + "'"
- cr.execute("SELECT a.id, COALESCE(SUM(l.amount_currency),0) FROM account_analytic_account a LEFT JOIN account_analytic_line l ON (a.id=l.account_id "+where_date+") WHERE l.amount_currency>0 and a.id =ANY(%s) GROUP BY a.id" ,(ids2,))
+ cr.execute("SELECT a.id, COALESCE(SUM(l.amount_currency),0) FROM account_analytic_account a LEFT JOIN account_analytic_line l ON (a.id=l.account_id "+where_date+") WHERE l.amount_currency>0 and a.id IN %s GROUP BY a.id" ,(tuple(parent_ids),))
r= dict(cr.fetchall())
- return self._compute_currency_for_level_tree(cr, uid, ids, ids2, r, acc_set, context)
+ return self._compute_currency_for_level_tree(cr, uid, ids, parent_ids, r, context)
def _balance_calc(self, cr, uid, ids, name, arg, context={}):
res = {}
- ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)])
- acc_set = ",".join(map(str, ids2))
-
+ parent_ids = tuple(self.search(cr, uid, [('parent_id', 'child_of', ids)]))
for i in ids:
res.setdefault(i,0.0)
- if not ids2:
+ if not parent_ids:
return res
where_date = ''
@@ -115,23 +109,22 @@ class account_analytic_account(osv.osv):
where_date += " AND l.date >= '" + context['from_date'] + "'"
if context.get('to_date',False):
where_date += " AND l.date <= '" + context['to_date'] + "'"
- cr.execute("SELECT a.id, COALESCE(SUM(l.amount_currency),0) FROM account_analytic_account a LEFT JOIN account_analytic_line l ON (a.id=l.account_id "+where_date+") WHERE a.id =ANY(%s) GROUP BY a.id",(ids2,))
+ cr.execute("SELECT a.id, COALESCE(SUM(l.amount_currency),0) FROM account_analytic_account a LEFT JOIN account_analytic_line l ON (a.id=l.account_id "+where_date+") WHERE a.id IN %s GROUP BY a.id",(tuple(parent_ids),))
for account_id, sum in cr.fetchall():
res[account_id] = sum
- return self._compute_currency_for_level_tree(cr, uid, ids, ids2, res, acc_set, context)
+ return self._compute_currency_for_level_tree(cr, uid, ids, parent_ids, res, context)
def _quantity_calc(self, cr, uid, ids, name, arg, context={}):
#XXX must convert into one uom
res = {}
- ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)])
- acc_set = ",".join(map(str, ids2))
+ parent_ids = tuple(self.search(cr, uid, [('parent_id', 'child_of', ids)]))
for i in ids:
res.setdefault(i,0.0)
- if not ids2:
+ if not parent_ids:
return res
where_date = ''
@@ -143,13 +136,13 @@ class account_analytic_account(osv.osv):
cr.execute('SELECT a.id, COALESCE(SUM(l.unit_amount), 0) \
FROM account_analytic_account a \
LEFT JOIN account_analytic_line l ON (a.id = l.account_id ' + where_date + ') \
- WHERE a.id =ANY(%s) GROUP BY a.id',(ids2,))
+ WHERE a.id IN %s GROUP BY a.id',(tuple(parent_ids),))
for account_id, sum in cr.fetchall():
res[account_id] = sum
for id in ids:
- if id not in ids2:
+ if id not in parent_ids:
continue
for child in self.search(cr, uid, [('parent_id', 'child_of', [id])]):
if child != id:
diff --git a/addons/auction/auction.py b/addons/auction/auction.py
index b7a379cd387..dacdd183da2 100644
--- a/addons/auction/auction.py
+++ b/addons/auction/auction.py
@@ -98,9 +98,15 @@ class auction_dates(osv.osv):
#TODO: convert this query to tiny API
lots_obj = self.pool.get('auction.lots')
cr.execute('select count(*) as c from auction_lots where auction_id =ANY(%s) and state=%s and obj_price>0', (ids,'draft',))
+ cr.execute('SELECT COUNT(*) AS c '
+ 'FROM auction_lots '
+ 'WHERE auction_id IN %s '
+ 'AND state=%s AND obj_price>0', (tuple(ids), 'draft'))
nbr = cr.fetchone()[0]
ach_uids = {}
- cr.execute('select id from auction_lots where auction_id =ANY(%s) and state=%s and obj_price>0', (ids,'draft',))
+ cr.execute('SELECT id FROM auction_lots '
+ 'WHERE auction_id IN %s '
+ 'AND state=%s AND obj_price>0', (tuple(ids), 'draft'))
r = lots_obj.lots_invoice(cr, uid, [x[0] for x in cr.fetchall()],{},None)
cr.execute('select id from auction_lots where auction_id =ANY(%s) and obj_price>0',(ids,))
ids2 = [x[0] for x in cr.fetchall()]
@@ -115,7 +121,9 @@ auction_dates()
# Deposits
#----------------------------------------------------------
def _inv_uniq(cr, ids):
- cr.execute('select name from auction_deposit where id =ANY(%s)',(ids,))
+ cr.execute('SELECT id FROM auction_lots '
+ 'WHERE auction_id IN %s '
+ 'AND obj_price>0', (tuple(ids),))
for datas in cr.fetchall():
cr.execute('select count(*) from auction_deposit where name=%s', (datas[0],))
if cr.fetchone()[0]>1:
@@ -231,7 +239,9 @@ def _type_get(self, cr, uid,ids):
# Lots
#----------------------------------------------------------
def _inv_constraint(cr, ids):
- cr.execute('select id, bord_vnd_id, lot_num from auction_lots where id =ANY(%s)', (ids,))
+ cr.execute('SELECT id, bord_vnd_id, lot_num FROM auction_lots '
+ 'WHERE id IN %s',
+ (tuple(ids),))
for datas in cr.fetchall():
cr.execute('select count(*) from auction_lots where bord_vnd_id=%s and lot_num=%s', (datas[1],datas[2]))
if cr.fetchone()[0]>1:
diff --git a/addons/auction/report/auction_objects.py b/addons/auction/report/auction_objects.py
index b3f632bb27e..a83a75a873e 100644
--- a/addons/auction/report/auction_objects.py
+++ b/addons/auction/report/auction_objects.py
@@ -28,19 +28,8 @@ class auction_objects(report_sxw.rml_parse):
super(auction_objects, self).__init__(cr, uid, name, context=context)
self.localcontext.update({
'time': time,
- #'lines': self.lines
- #'get_data' : self.get_data
})
-# def lines(self, auction_id):
-#
-# cr.execute('select ad.name from auction_dates ad, a1uction_lots al where ad.id=al.%d group by ad.name',(auction_id))
-# return self.cr.fetchone()[0]
-# def get_data(self, auction_id):
-# res = self.pool.get('auction.bid.lines').read(self.cr,self.uid,[lot_id])
-# return True
-
-
report_sxw.report_sxw('report.auction.objects', 'auction.lots', 'addons/auction/report/auction_objects.rml', parser=auction_objects)
diff --git a/addons/auction/report/auction_total_rml.py b/addons/auction/report/auction_total_rml.py
index 0e207db62bc..489c68449a7 100644
--- a/addons/auction/report/auction_total_rml.py
+++ b/addons/auction/report/auction_total_rml.py
@@ -54,7 +54,10 @@ class auction_total_rml(report_sxw.rml_parse):
for lot_id in objects:
auc_lot_ids.append(lot_id.id)
self.total_obj=auc_lot_ids
- self.cr.execute('select auction_id from auction_lots where id =ANY(%s) group by auction_id',(auc_lot_ids,))
+ self.cr.execute('SELECT auction_id FROM auction_lots '
+ 'WHERE id IN %s '
+ 'GROUP BY auction_id',
+ (tuple(auc_lot_ids),))
auc_date_ids = self.cr.fetchall()
auct_dat=[]
for ad_id in auc_date_ids:
@@ -64,52 +67,52 @@ class auction_total_rml(report_sxw.rml_parse):
def sum_taxes(self,auction_id):
- self.cr.execute("select count(1) from auction_lots where id =ANY(%s) and auction_id=%s group by auction_id ", (self.total_obj,auction_id,))
+ self.cr.execute("select count(1) from auction_lots where id IN %s and auction_id=%s group by auction_id ", (tuple(self.total_obj),auction_id,))
res = self.cr.fetchone()
return res[0]
def sold_item(self, object_id):
- self.cr.execute("select count(1) from auction_lots where id =ANY(%s) and auction_id=%s and state in ('unsold') ", (self.total_obj,object_id,))
+ self.cr.execute("select count(1) from auction_lots where id IN %s and auction_id=%s and state in ('unsold') ", (tuple(self.total_obj),object_id,))
res = self.cr.fetchone()
return str(res[0])
def sum_buyer(self, auction_id):
- self.cr.execute("select count(*) from auction_lots where id =ANY(%s) and auction_id=%s and (ach_uid is not null or ach_login is not null) ", (self.total_obj,auction_id,))
+ self.cr.execute("select count(*) from auction_lots where id IN %s and auction_id=%s and (ach_uid is not null or ach_login is not null) ", (tuple(self.total_obj),auction_id,))
res = self.cr.fetchone()
return str(res[0])
def sum_seller(self, auction_id):
- self.cr.execute("select count(distinct bord_vnd_id) from auction_lots where id =ANY(%s) and auction_id=%s AND bord_vnd_id is not null ", (self.total_obj,auction_id,))
+ self.cr.execute("select count(distinct bord_vnd_id) from auction_lots where id IN %s and auction_id=%s AND bord_vnd_id is not null ", (tuple(self.total_obj),auction_id,))
res = self.cr.fetchone()
return res[0]
def sum_adj(self, auction_id):
- self.cr.execute("select sum(obj_price) from auction_lots where id =ANY(%s) and auction_id=%s ", (self.total_obj,auction_id,))
+ self.cr.execute("select sum(obj_price) from auction_lots where id IN %s and auction_id=%s ", (tuple(self.total_obj),auction_id,))
res = self.cr.fetchone()
return str(res[0])
def count_take(self, auction_id):
- self.cr.execute("select count(*) from auction_lots where id =ANY(%s) and auction_id=%s and ach_emp='True' ", (self.total_obj,auction_id,))
+ self.cr.execute("select count(*) from auction_lots where id IN %s and auction_id=%s and ach_emp='True' ", (tuple(self.total_obj),auction_id,))
res = self.cr.fetchone()
return str(res[0])
def chek_paid(self, auction_id):
- self.cr.execute("select count(1) from auction_lots where id =ANY(%s) and auction_id=%s and ((paid_ach='T') or (is_ok='T')) ", (self.total_obj,auction_id,))
+ self.cr.execute("select count(1) from auction_lots where id IN %s and auction_id=%s and ((paid_ach='T') or (is_ok='T')) ", (tuple(self.total_obj),auction_id,))
res = self.cr.fetchone()
return str(res[0])
def check_paid_seller(self,auction_id):
- self.cr.execute("select sum(seller_price) from auction_lots where id =ANY(%s) and auction_id=%s and paid_vnd != 'T' ", (self.total_obj,auction_id,))
+ self.cr.execute("select sum(seller_price) from auction_lots where id IN %s and auction_id=%s and paid_vnd != 'T' ", (tuple(self.total_obj),auction_id,))
res = self.cr.fetchone()
return str(res[0]) or 0.0
def sum_credit(self,auction_id):
- self.cr.execute("select sum(buyer_price) from auction_lots where id =ANY(%s) and auction_id=%s", (self.total_obj,auction_id,))
+ self.cr.execute("select sum(buyer_price) from auction_lots where id IN %s and auction_id=%s", (tuple(self.total_obj),auction_id,))
res = self.cr.fetchone()
return str(res[0])
def sum_debit_buyer(self,auction_id):
- self.cr.execute("select sum(buyer_price) from auction_lots where id =ANY(%s) and auction_id=%s", (self.total_obj,auction_id,))
+ self.cr.execute("select sum(buyer_price) from auction_lots where id IN %s and auction_id=%s", (tuple(self.total_obj),auction_id,))
res = self.cr.fetchone()
return str(res[0] or 0)
@@ -121,27 +124,27 @@ class auction_total_rml(report_sxw.rml_parse):
def sum_credit_seller(self, object_id):
- self.cr.execute("select sum(seller_price) from auction_lots where id =ANY(%s) and auction_id=%s", (self.total_obj,object_id,))
+ self.cr.execute("select sum(seller_price) from auction_lots where id IN %s and auction_id=%s", (tuple(self.total_obj),object_id,))
res = self.cr.fetchone()
return str(res[0] or 0)
def sum_minadj(self, auction_id):
- self.cr.execute('select sum(lot_est1) from auction_lots where id =ANY(%s) and auction_id=%s', (self.total_obj,auction_id,))
+ self.cr.execute('select sum(lot_est1) from auction_lots where id IN %s and auction_id=%s', (tuple(self.total_obj),auction_id,))
res = self.cr.fetchone()
return str(res[0]) or 0
def sum_maxadj(self, auction_id):
- self.cr.execute('select sum(lot_est2) from auction_lots where id =ANY(%s) and auction_id=%s', (self.total_obj,auction_id,))
+ self.cr.execute('select sum(lot_est2) from auction_lots where id IN %s and auction_id=%s', (tuple(self.total_obj),auction_id,))
res = self.cr.fetchone()
return str(res[0]) or 0
def sum_buyer_paid(self, auction_id):
- self.cr.execute("select count(*) from auction_lots where id =ANY(%s) and auction_id=%s and state = 'paid' ", (self.total_obj,auction_id,))
+ self.cr.execute("select count(*) from auction_lots where id IN %s and auction_id=%s and state = 'paid' ", (tuple(self.total_obj),auction_id,))
res = self.cr.fetchone()
return str(res[0])
def count_comm(self, auction_id):
- self.cr.execute("select count(*) from auction_lots where id =ANY(%s) and auction_id=%s and obj_comm is not null ", (self.total_obj,auction_id,))
+ self.cr.execute("select count(*) from auction_lots where id IN %s and auction_id=%s and obj_comm is not null ", (tuple(self.total_obj),auction_id,))
res = self.cr.fetchone()
return str(res[0])
diff --git a/addons/auction/report/buyer_list.py b/addons/auction/report/buyer_list.py
index 06430efdc85..a97c1eaa637 100644
--- a/addons/auction/report/buyer_list.py
+++ b/addons/auction/report/buyer_list.py
@@ -49,7 +49,8 @@ class buyer_list(report_sxw.rml_parse):
for lot_id in objects:
auc_lot_ids.append(lot_id.id)
self.auc_lot_ids=auc_lot_ids
- self.cr.execute('select auction_id from auction_lots where id =ANY(%s) group by auction_id',(auc_lot_ids,))
+ self.cr.execute('SELECT auction_id FROM auction_lots WHERE id IN %s GROUP BY auction_id',
+ (tuple(auc_lot_ids),))
auc_date_ids = self.cr.fetchall()
auct_dat=[]
for ad_id in auc_date_ids:
@@ -69,13 +70,16 @@ class buyer_list(report_sxw.rml_parse):
auc_date_ids = self.pool.get('auction.dates').search(self.cr,self.uid,([('name','like',obj['name'])]))
-# self.cr.execute('select ach_uid,count(1) as no_lot, sum(obj_price) as adj_price, sum(buyer_price)-sum(obj_price) as buyer_cost ,sum(buyer_price) as to_pay from auction_lots where id in ('+','.join(map(str,self.auc_lot_ids))+') and auction_id=%s and ach_uid is not null group by ach_uid ', (auc_date_ids[0],))
- self.cr.execute('select ach_login as ach_uid,count(1) as no_lot, sum(obj_price) as adj_price, sum(buyer_price)-sum(obj_price) as buyer_cost ,sum(buyer_price) as to_pay from auction_lots where id =ANY(%s) and auction_id=%s and ach_login is not null group by ach_login order by ach_login', (self.auc_lot_ids,auc_date_ids[0],))
+ 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 %s '\
+ 'AND auction_id=%s AND ach_login IS NOT NULL '\
+ 'GROUP BY ach_login ORDER BY ach_login',
+ (tuple(self.auc_lot_ids), auc_date_ids[0],))
res = self.cr.dictfetchall()
for r in res:
-# if r['ach_uid']:
-# tnm=self.pool.get('res.partner').read(self.cr,self.uid,[r['ach_uid']],['name'])#
-# r.__setitem__('ach_uid',tnm[0]['name'])
self.sum_adj_price_val = self.sum_adj_price_val + r['adj_price']
self.sum_buyer_obj_price_val = self.sum_buyer_obj_price_val + r['buyer_cost']
self.sum_buyer_price_val = self.sum_buyer_price_val + r['to_pay']
diff --git a/addons/auction/report/catalog2.py b/addons/auction/report/catalog2.py
index 3eb993c55ce..a88d05cf5b9 100644
--- a/addons/auction/report/catalog2.py
+++ b/addons/auction/report/catalog2.py
@@ -126,7 +126,7 @@ class auction_catalog(report_rml):
for test in ab:
if test.has_key('auction_id'):
auction_ids.append(test['auction_id'][0])
- cr.execute('select * from auction_lots where auction_id =ANY(%s)',(auction_ids,))
+ cr.execute('select * from auction_lots where auction_id IN %s',(tuple(auction_ids),))
res = cr.dictfetchall()
for cat in res:
product =doc.createElement('product')
diff --git a/addons/crm/crm.py b/addons/crm/crm.py
index d3c640efca3..789a51bde7e 100644
--- a/addons/crm/crm.py
+++ b/addons/crm/crm.py
@@ -466,7 +466,7 @@ class crm_case_section(osv.osv):
level = 100
while len(ids):
- cr.execute('select distinct parent_id from crm_case_section where id =ANY(%s)', (ids,))
+ cr.execute('select distinct parent_id from crm_case_section where id IN %s', (tuple(ids),))
ids = filter(None, map(lambda x: x[0], cr.fetchall()))
if not level:
return False
diff --git a/addons/crm/report/report_businessopp.py b/addons/crm/report/report_businessopp.py
index 9e08a9941ee..5bce5fc6ef0 100644
--- a/addons/crm/report/report_businessopp.py
+++ b/addons/crm/report/report_businessopp.py
@@ -69,7 +69,7 @@ class report_custom(report_int):
cr.execute('select probability, planned_revenue, planned_cost, user_id,\
res_users.name as name from crm_case left join res_users on \
- (crm_case.user_id=res_users.id) where crm_case.id =ANY(%s) order by user_id',(ids,))
+ (crm_case.user_id=res_users.id) where crm_case.id IN %s order by user_id',(tuple(ids),))
res = cr.dictfetchall()
for row in res:
diff --git a/addons/email_template/email_template_mailbox.py b/addons/email_template/email_template_mailbox.py
index 1934f4e0227..f0dc9f5c519 100755
--- a/addons/email_template/email_template_mailbox.py
+++ b/addons/email_template/email_template_mailbox.py
@@ -52,7 +52,6 @@ class email_template_mailbox(osv.osv):
for attid in values['attachments_ids']:
attachment = self.pool.get('ir.attachment').browse(cr, uid, attid, context)#,['datas_fname','datas'])
payload[attachment.datas_fname] = attachment.datas
- print "233333333333333"
result = account_obj.send_mail(cr, uid,
[values['account_id'][0]],
{'To':values.get('email_to', u'') or u'', 'CC':values.get('email_cc', u'') or u'', 'BCC':values.get('email_bcc', u'') or u''},
diff --git a/addons/email_template/wizard/email_template_send_wizard.py b/addons/email_template/wizard/email_template_send_wizard.py
index 7d27eab9adf..9934336d506 100755
--- a/addons/email_template/wizard/email_template_send_wizard.py
+++ b/addons/email_template/wizard/email_template_send_wizard.py
@@ -168,7 +168,6 @@ class email_template_send_wizard(osv.osv_memory):
mail_ids = []
template = self._get_template(cr, uid, context)
for id in context['src_rec_ids']:
- print "@22222222222222222222222",ids
screen_vals = self.read(cr, uid, ids[0], [],context)
account = self.pool.get('email_template.account').read(cr, uid, screen_vals['from'], context=context)
vals = {
diff --git a/addons/hr/hr.py b/addons/hr/hr.py
index 841370a97f2..6c8bea9699c 100644
--- a/addons/hr/hr.py
+++ b/addons/hr/hr.py
@@ -37,7 +37,7 @@ class hr_employee_category(osv.osv):
def _check_recursion(self, cr, uid, ids):
level = 100
while len(ids):
- cr.execute('select distinct parent_id from hr_employee_category where id=ANY(%s)',(ids,))
+ cr.execute('select distinct parent_id from hr_employee_category where id IN %s',(tuple(ids),))
ids = filter(None, map(lambda x:x[0], cr.fetchall()))
if not level:
return False
@@ -130,7 +130,7 @@ class hr_employee(osv.osv):
def _check_recursion(self, cr, uid, ids):
level = 100
while len(ids):
- cr.execute('select distinct parent_id from hr_employee where id =ANY(%s)',(ids,))
+ cr.execute('select distinct parent_id from hr_employee where id IN %s',(tuple(ids),))
ids = filter(None, map(lambda x:x[0], cr.fetchall()))
if not level:
return False
diff --git a/addons/hr/hr_department.py b/addons/hr/hr_department.py
index f31969129d8..136960d6a6f 100644
--- a/addons/hr/hr_department.py
+++ b/addons/hr/hr_department.py
@@ -61,7 +61,7 @@ class hr_department(osv.osv):
def _check_recursion(self, cr, uid, ids):
level = 100
while len(ids):
- cr.execute('select distinct parent_id from hr_department where id =ANY(%s)',(ids,))
+ cr.execute('select distinct parent_id from hr_department where id IN %s',(tuple(ids),))
ids = filter(None, map(lambda x:x[0], cr.fetchall()))
if not level:
return False
diff --git a/addons/hr_attendance/hr_attendance.py b/addons/hr_attendance/hr_attendance.py
index 043941eed88..9f5846601ef 100644
--- a/addons/hr_attendance/hr_attendance.py
+++ b/addons/hr_attendance/hr_attendance.py
@@ -104,7 +104,7 @@ class hr_employee(osv.osv):
LEFT JOIN hr_attendance \
ON (hr_attendance.employee_id = foo.employee_id \
AND hr_attendance.name = foo.name) \
- WHERE hr_attendance.employee_id =ANY(%s)',(ids,))
+ WHERE hr_attendance.employee_id IN %s',(tuple(ids),))
for res in cr.fetchall():
result[res[1]] = res[0] == 'sign_in' and 'present' or 'absent'
return result
diff --git a/addons/hr_attendance/wizard/hr_attendance_error.py b/addons/hr_attendance/wizard/hr_attendance_error.py
index c14ddcd9032..47029822741 100644
--- a/addons/hr_attendance/wizard/hr_attendance_error.py
+++ b/addons/hr_attendance/wizard/hr_attendance_error.py
@@ -44,7 +44,7 @@ class hr_attendance_error(osv.osv_memory):
data_error = self.read(cr, uid, ids)[0]
date_from = data_error['init_date']
date_to = data_error['end_date']
- cr.execute("select id from hr_attendance where employee_id =ANY(%s) and to_char(name,'YYYY-mm-dd')<=%s and to_char(name,'YYYY-mm-dd')>=%s and action =ANY(%s) order by name" ,(context['active_ids'], date_to, date_from, ['sign_in','sign_out']))
+ 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 order by name" ,(tuple(context['active_ids']), date_to, date_from, tuple(['sign_in','sign_out'])))
attendance_ids = [x[0] for x in cr.fetchall()]
if not attendance_ids:
raise osv.except_osv(_('No Data Available'), _('No records found for your selection!'))
diff --git a/addons/hr_expense/hr_expense.py b/addons/hr_expense/hr_expense.py
index 820d3467660..efeed1dbad4 100644
--- a/addons/hr_expense/hr_expense.py
+++ b/addons/hr_expense/hr_expense.py
@@ -38,7 +38,7 @@ class hr_expense_expense(osv.osv):
return super(hr_expense_expense, self).copy(cr, uid, id, default, context)
def _amount(self, cr, uid, ids, field_name, arg, context):
- cr.execute("SELECT s.id,COALESCE(SUM(l.unit_amount*l.unit_quantity),0) AS amount FROM hr_expense_expense s LEFT OUTER JOIN hr_expense_line l ON (s.id=l.expense_id) WHERE s.id =ANY(%s) GROUP BY s.id ",(ids,))
+ 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 %s GROUP BY s.id ",(tuple(ids),))
res = dict(cr.fetchall())
return res
@@ -188,7 +188,7 @@ class hr_expense_line(osv.osv):
def _amount(self, cr, uid, ids, field_name, arg, context):
if not len(ids):
return {}
- cr.execute("SELECT l.id,COALESCE(SUM(l.unit_amount*l.unit_quantity),0) AS amount FROM hr_expense_line l WHERE id =ANY(%s) GROUP BY l.id ",(ids,))
+ cr.execute("SELECT l.id,COALESCE(SUM(l.unit_amount*l.unit_quantity),0) AS amount FROM hr_expense_line l WHERE id IN %s GROUP BY l.id ",(tuple(ids),))
res = dict(cr.fetchall())
return res
diff --git a/addons/hr_timesheet_invoice/wizard/hr_timesheet_invoice_create.py b/addons/hr_timesheet_invoice/wizard/hr_timesheet_invoice_create.py
index 89ff5e92697..6fc942442be 100644
--- a/addons/hr_timesheet_invoice/wizard/hr_timesheet_invoice_create.py
+++ b/addons/hr_timesheet_invoice/wizard/hr_timesheet_invoice_create.py
@@ -54,7 +54,7 @@ class hr_timesheet_invoice_create(osv.osv_memory):
if obj_acc.invoice_id and obj_acc.invoice_id.state !='cancel':
raise osv.except_osv(_('Warning'),_('The analytic entry "%s" is already invoiced!')%(obj_acc.name,))
- cr.execute("SELECT distinct(account_id) from account_analytic_line where id =ANY(%s)",(context['active_ids'],))
+ cr.execute("SELECT distinct(account_id) from account_analytic_line where id IN %s",(tuple(context['active_ids']),))
account_ids = cr.fetchall()
return [x[0] for x in account_ids]
@@ -115,8 +115,8 @@ class hr_timesheet_invoice_create(osv.osv_memory):
cr.execute("SELECT product_id, to_invoice, sum(unit_amount) " \
"FROM account_analytic_line as line " \
"WHERE account_id = %s " \
- "AND id =ANY(%s) AND to_invoice IS NOT NULL " \
- "GROUP BY product_id,to_invoice", (account.id,context['active_ids'],))
+ "AND id IN %s AND to_invoice IS NOT NULL " \
+ "GROUP BY product_id,to_invoice", (account.id,tuple(context['active_ids']),))
for product_id,factor_id,qty in cr.fetchall():
product = pool.get('product.product').browse(cr, uid, product_id, context2)
@@ -159,7 +159,7 @@ class hr_timesheet_invoice_create(osv.osv_memory):
#
# Compute for lines
#
- cr.execute("SELECT * FROM account_analytic_line WHERE account_id = %s and id = ANY (%s) AND product_id=%s and to_invoice=%s", (account.id, data['ids'], product_id, factor_id))
+ cr.execute("SELECT * FROM account_analytic_line WHERE account_id = %s and id in %s AND product_id=%s and to_invoice=%s", (account.id, tuple(data['ids']), product_id, factor_id))
line_ids = cr.dictfetchall()
note = []
@@ -181,7 +181,7 @@ class hr_timesheet_invoice_create(osv.osv_memory):
curr_line['note'] = "\n".join(map(lambda x: unicode(x) or '',note))
pool.get('account.invoice.line').create(cr, uid, curr_line)
- cr.execute("update account_analytic_line set invoice_id=%s WHERE account_id = %s and id =ANY(%s)" ,(last_invoice, account.id,data['ids']))
+ cr.execute("update account_analytic_line set invoice_id=%s WHERE account_id = %s and id in %s" ,(last_invoice, account.id,tuple(data['ids'])))
self.pool.get('account.invoice').button_reset_taxes(cr, uid, [last_invoice], context)
diff --git a/addons/hr_timesheet_sheet/hr_timesheet_sheet.py b/addons/hr_timesheet_sheet/hr_timesheet_sheet.py
index 5ace7f64ebd..2eb352974d7 100644
--- a/addons/hr_timesheet_sheet/hr_timesheet_sheet.py
+++ b/addons/hr_timesheet_sheet/hr_timesheet_sheet.py
@@ -102,7 +102,7 @@ class hr_timesheet_sheet(osv.osv):
LEFT JOIN hr_timesheet_sheet_sheet_day AS day \
ON (sheet.id = day.sheet_id \
AND day.name = sheet.date_current) \
- WHERE sheet.id =ANY(%s)',(ids,))
+ WHERE sheet.id IN %s',(tuple(ids),))
for record in cr.fetchall():
res[record[0]] = {}
res[record[0]]['total_attendance_day'] = record[1]
@@ -118,7 +118,7 @@ class hr_timesheet_sheet(osv.osv):
FROM hr_timesheet_sheet_sheet s \
LEFT JOIN hr_timesheet_sheet_sheet_day d \
ON (s.id = d.sheet_id) \
- WHERE s.id =ANY(%s) GROUP BY s.id',(ids,))
+ WHERE s.id IN %s GROUP BY s.id',(tuple(ids),))
for record in cr.fetchall():
res[record[0]] = {}
res[record[0]]['total_attendance'] = record[1]
@@ -368,7 +368,7 @@ class hr_timesheet_line(osv.osv):
ON (s.date_to >= al.date \
AND s.date_from <= al.date \
AND s.user_id = al.user_id) \
- WHERE l.id =ANY(%s) GROUP BY l.id',(ids,))
+ WHERE l.id IN %s GROUP BY l.id',(tuple(ids),))
res = dict(cursor.fetchall())
sheet_names = {}
for sheet_id, name in sheet_obj.name_get(cursor, user, res.values(),
@@ -487,7 +487,7 @@ class hr_attendance(osv.osv):
ON (s.date_to >= date_trunc('day',a.name) \
AND s.date_from <= a.name \
AND s.user_id = r.user_id) \
- WHERE a.id =ANY(%s) GROUP BY a.id",(ids,))
+ WHERE a.id IN %s GROUP BY a.id",(tuple(ids),))
res = dict(cursor.fetchall())
sheet_names = {}
for sheet_id, name in sheet_obj.name_get(cursor, user, res.values(),
diff --git a/addons/idea/idea.py b/addons/idea/idea.py
index 14fb24ee607..171ff85505f 100644
--- a/addons/idea/idea.py
+++ b/addons/idea/idea.py
@@ -66,11 +66,11 @@ class idea_idea(osv.osv):
sql = """SELECT i.id, avg(v.score::integer)
FROM idea_idea i LEFT OUTER JOIN idea_vote v ON i.id = v.idea_id
- WHERE i.id = ANY(%s)
+ WHERE i.id IN %s
GROUP BY i.id
"""
- cr.execute(sql, (ids,))
+ cr.execute(sql, (tuple(ids),))
return dict(cr.fetchall())
def _vote_count(self, cr, uid, ids, name, arg, context=None):
@@ -86,11 +86,11 @@ class idea_idea(osv.osv):
sql = """SELECT i.id, COUNT(1)
FROM idea_idea i LEFT OUTER JOIN idea_vote v ON i.id = v.idea_id
- WHERE i.id = ANY(%s)
+ WHERE i.id IN %s
GROUP BY i.id
"""
- cr.execute(sql, (ids,))
+ cr.execute(sql, (tuple(ids),))
return dict(cr.fetchall())
def _comment_count(self, cr, uid, ids, name, arg, context=None):
@@ -106,11 +106,11 @@ class idea_idea(osv.osv):
sql = """SELECT i.id, COUNT(1)
FROM idea_idea i LEFT OUTER JOIN idea_comment c ON i.id = c.idea_id
- WHERE i.id = ANY(%s)
+ WHERE i.id IN %s
GROUP BY i.id
"""
- cr.execute(sql, (ids,))
+ cr.execute(sql, (tuple(ids),))
return dict(cr.fetchall())
def _vote_read(self, cr, uid, ids, name, arg, context = None):
diff --git a/addons/l10n_be/wizard/l10_be_partner_vat_listing.py b/addons/l10n_be/wizard/l10_be_partner_vat_listing.py
index 24a9541a2a2..415db0ba067 100644
--- a/addons/l10n_be/wizard/l10_be_partner_vat_listing.py
+++ b/addons/l10n_be/wizard/l10_be_partner_vat_listing.py
@@ -81,7 +81,7 @@ class partner_vat(osv.osv_memory):
break
if not go_ahead:
continue
- cursor.execute('select b.code, sum(credit)-sum(debit) from account_move_line l left join account_account a on (l.account_id=a.id) left join account_account_type b on (a.user_type=b.id) where b.code in %s and l.partner_id=%s and l.period_id=ANY(%s) group by b.code',(('produit','tax'),obj_partner.id,period,))
+ cursor.execute('select b.code, sum(credit)-sum(debit) from account_move_line l left join account_account a on (l.account_id=a.id) left join account_account_type b on (a.user_type=b.id) where b.code IN %s and l.partner_id=%s and l.period_id IN %s group by b.code',(('produit','tax'),obj_partner.id,tuple(period),))
line_info = cursor.fetchall()
if not line_info:
continue
diff --git a/addons/l10n_ch/wizard/bvr_import.py b/addons/l10n_ch/wizard/bvr_import.py
index 55caf5c4162..12e8012f643 100644
--- a/addons/l10n_ch/wizard/bvr_import.py
+++ b/addons/l10n_ch/wizard/bvr_import.py
@@ -71,7 +71,7 @@ def _reconstruct_invoice_ref(cursor, user, reference, context):
cursor.execute('SELECT l.id ' \
'FROM account_move_line l, account_invoice i ' \
'WHERE l.move_id = i.move_id AND l.reconcile_id is NULL ' \
- 'AND i.id =ANY(%s)',([id_invoice],))
+ 'AND i.id IN %s',(tuple([id_invoice]),))
inv_line = []
for id_line in cursor.fetchall():
inv_line.append(id_line[0])
diff --git a/addons/lunch/wizard/lunch_cashbox_clean.py b/addons/lunch/wizard/lunch_cashbox_clean.py
index 1956dc6d4b7..4f08d869801 100644
--- a/addons/lunch/wizard/lunch_cashbox_clean.py
+++ b/addons/lunch/wizard/lunch_cashbox_clean.py
@@ -40,12 +40,12 @@ class lunch_cashbox_clean(osv.osv_memory):
cashmove_ref = self.pool.get('lunch.cashmove')
cr.execute("select user_cashmove, box,sum(amount) from lunch_cashmove \
- where active = 't' and box in (%s) group by user_cashmove, \
- box" % ','.join(map(str, data)))
+ where active = 't' and box IN (%s) group by user_cashmove, \
+ box" , (tuple(data),))
res = cr.fetchall()
cr.execute("update lunch_cashmove set active = 'f' where active= 't' \
- and box in (%s)" % ','.join(map(str, data)))
+ and box IN (%s)" , (tuple(data),))
for (user_id, box_id, amount) in res:
cashmove_ref.create(cr, uid, {'name': 'Summary for user' + str(user_id),
diff --git a/addons/membership/membership.py b/addons/membership/membership.py
index 23f9cd19275..227f1644512 100644
--- a/addons/membership/membership.py
+++ b/addons/membership/membership.py
@@ -150,7 +150,7 @@ class membership_line(osv.osv):
)
JOIN account_invoice ai ON (
ai.id = ail.invoice_id)
- WHERE ml.id =ANY(%s)''',(ids,))
+ WHERE ml.id IN %s''',(tuple(ids),))
res = cr.fetchall()
for r in res:
if r[0] and r[0] < 0:
@@ -412,7 +412,7 @@ class Partner(osv.osv):
def _check_recursion(self, cr, uid, ids):
level = 100
while len(ids):
- cr.execute('select distinct associate_member from res_partner where id =ANY(%s)',(ids,))
+ cr.execute('select distinct associate_member from res_partner where id IN %s',(tuple(ids),))
ids = filter(None, map(lambda x:x[0], cr.fetchall()))
if not level:
return False
diff --git a/addons/membership/wizard/membership_invoice.py b/addons/membership/wizard/membership_invoice.py
index 45d5c538b15..39589f58e27 100644
--- a/addons/membership/wizard/membership_invoice.py
+++ b/addons/membership/wizard/membership_invoice.py
@@ -43,7 +43,7 @@ class membership_invoice(osv.osv_memory):
cr.execute('''
SELECT partner_id, id, type
FROM res_partner_address
- WHERE partner_id =ANY(%s)''',(partner_ids,))
+ WHERE partner_id IN %s''',(tuple(partner_ids),))
fetchal = cr.fetchall()
if not fetchal:
raise osv.except_osv(_('Error !'), _('No Address defined for this partner'))
diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py
index 685d289a194..42e8ef25d4a 100644
--- a/addons/mrp/mrp.py
+++ b/addons/mrp/mrp.py
@@ -223,7 +223,7 @@ class mrp_bom(osv.osv):
def _check_recursion(self, cr, uid, ids):
level = 100
while len(ids):
- cr.execute('select distinct bom_id from mrp_bom where id =ANY(%s)',(ids,))
+ cr.execute('select distinct bom_id from mrp_bom where id IN %s',(tuple(ids),))
ids = filter(None, map(lambda x:x[0], cr.fetchall()))
if not level:
return False
diff --git a/addons/mrp/report/workcenter_load.py b/addons/mrp/report/workcenter_load.py
index 248e9e5707e..8e5b9bff7ba 100644
--- a/addons/mrp/report/workcenter_load.py
+++ b/addons/mrp/report/workcenter_load.py
@@ -104,7 +104,7 @@ class report_custom(report_int):
"WHERE mrp_production_workcenter_line.production_id=mrp_production.id "\
"AND mrp_production_workcenter_line.workcenter_id=mrp_workcenter.id "\
"AND mrp_production.state NOT IN ('cancel','done') "\
- "AND mrp_workcenter.id =ANY(%s)",(ids,))
+ "AND mrp_workcenter.id IN %s",(tuple(ids),))
res = cr.dictfetchone()
if not res['stop']:
res['stop'] = time.strftime('%Y-%m-%d %H:%M:%S')
@@ -135,8 +135,8 @@ class report_custom(report_int):
# select workcenters
cr.execute(
"SELECT mw.id, rs.name FROM mrp_workcenter mw, resource_resource rs " \
- "WHERE mw.id=ANY(%s) and mw.resource_id=rs.id " \
- "ORDER BY mw.id" ,(ids,))
+ "WHERE mw.id IN %s and mw.resource_id=rs.id " \
+ "ORDER BY mw.id" ,(tuple(ids),))
workcenters = cr.dictfetchall()
data = []
diff --git a/addons/point_of_sale/pos.py b/addons/point_of_sale/pos.py
index dcc2086eb26..517b2d8b4a0 100644
--- a/addons/point_of_sale/pos.py
+++ b/addons/point_of_sale/pos.py
@@ -96,7 +96,7 @@ class pos_order(osv.osv):
) AS amount
FROM pos_order p
LEFT OUTER JOIN pos_order_line l ON (p.id=l.order_id)
- WHERE p.id =ANY(%s) GROUP BY p.id """,(ids,))
+ WHERE p.id IN %s GROUP BY p.id """,(tuple(ids),))
res = dict(cr.fetchall())
for rec in self.browse(cr, uid, ids, context):
if rec.partner_id \
diff --git a/addons/point_of_sale/report/pos_sales_user_today.py b/addons/point_of_sale/report/pos_sales_user_today.py
index a5caf899069..8344f4221c7 100644
--- a/addons/point_of_sale/report/pos_sales_user_today.py
+++ b/addons/point_of_sale/report/pos_sales_user_today.py
@@ -37,12 +37,11 @@ class pos_sales_user_today(report_sxw.rml_parse):
def _get_data(self,form):
data={}
ids = form['user_id']
- idss = map(str, ids)
self.cr.execute("select po.name as pos,po.date_order,ru.name as user,po.state,rc.name " \
"from pos_order as po,res_users as ru,res_company as rc " \
"where to_char(date_trunc('day',po.date_order),'YYYY-MM-DD')::date = current_date " \
- "and po.company_id=rc.id and po.user_id=ru.id and po.user_id in (%s)"% (",".join(idss), ))
+ "and po.company_id=rc.id and po.user_id=ru.id and po.user_id IN %s" ,(tuple(ids), ))
data = self.cr.dictfetchall()
return data
diff --git a/addons/product/product.py b/addons/product/product.py
index aaa369cdfcf..122f3a2112e 100644
--- a/addons/product/product.py
+++ b/addons/product/product.py
@@ -219,7 +219,7 @@ class product_category(osv.osv):
def _check_recursion(self, cr, uid, ids):
level = 100
while len(ids):
- cr.execute('select distinct parent_id from product_category where id =ANY(%s)',(ids,))
+ cr.execute('select distinct parent_id from product_category where id IN %s',(tuple(ids),))
ids = filter(None, map(lambda x:x[0], cr.fetchall()))
if not level:
return False
diff --git a/addons/project/project.py b/addons/project/project.py
index 61720675f49..4d9952dd841 100644
--- a/addons/project/project.py
+++ b/addons/project/project.py
@@ -92,10 +92,10 @@ class project(osv.osv):
FROM
project_task
WHERE
- project_id =ANY(%s) AND
+ project_id IN %s AND
state<>'cancelled'
GROUP BY
- project_id''',(ids2,))
+ project_id''',(tuple(ids2),))
progress = dict(map(lambda x: (x[0], (x[1], x[2], x[3])), cr.fetchall()))
for project in self.browse(cr, uid, ids, context=context):
s = [0.0, 0.0, 0.0]
@@ -196,7 +196,7 @@ class project(osv.osv):
res = super(project, self).copy(cr, uid, id, default, context)
ids = self.search(cr, uid, [('parent_id','child_of', [res])])
if ids:
- cr.execute('update project_task set active=True where project_id =ANY(%s)',(ids,))
+ cr.execute('update project_task set active=True where project_id IN %s',(tuple(ids),))
return res
def duplicate_template(self, cr, uid, ids, context={}):
@@ -272,7 +272,7 @@ class task(osv.osv):
# Compute: effective_hours, total_hours, progress
def _hours_get(self, cr, uid, ids, field_names, args, context=None):
res = {}
- cr.execute("SELECT task_id, COALESCE(SUM(hours),0) FROM project_task_work WHERE task_id =ANY(%s) GROUP BY task_id",(ids,))
+ cr.execute("SELECT task_id, COALESCE(SUM(hours),0) FROM project_task_work WHERE task_id IN %s GROUP BY task_id",(tuple(ids),))
hours = dict(cr.fetchall())
for task in self.browse(cr, uid, ids, context=context):
res[task.id] = {'effective_hours': hours.get(task.id, 0.0), 'total_hours': task.remaining_hours + hours.get(task.id, 0.0)}
diff --git a/addons/purchase/purchase.py b/addons/purchase/purchase.py
index c2e871f685a..6a4381e7c08 100644
--- a/addons/purchase/purchase.py
+++ b/addons/purchase/purchase.py
@@ -116,7 +116,7 @@ class purchase_order(osv.osv):
LEFT JOIN
stock_picking p on (p.id=m.picking_id)
WHERE
- p.purchase_id = ANY(%s) GROUP BY m.state, p.purchase_id''',(ids,))
+ p.purchase_id IN %s GROUP BY m.state, p.purchase_id''',(tuple(ids),))
for oid,nbr,state in cr.fetchall():
if state=='cancel':
continue
diff --git a/addons/sale/sale.py b/addons/sale/sale.py
index e684a1a6c1d..b92f0ed392f 100644
--- a/addons/sale/sale.py
+++ b/addons/sale/sale.py
@@ -114,7 +114,7 @@ class sale_order(osv.osv):
LEFT JOIN
mrp_procurement mp on (mp.move_id=m.id)
WHERE
- p.sale_id = ANY(%s) GROUP BY mp.state, p.sale_id''',(ids,))
+ p.sale_id IN %s GROUP BY mp.state, p.sale_id''',(tuple(ids),))
for oid, nbr, mp_state in cr.fetchall():
if mp_state == 'cancel':
continue
@@ -322,7 +322,7 @@ class sale_order(osv.osv):
def action_cancel_draft(self, cr, uid, ids, *args):
if not len(ids):
return False
- cr.execute('select id from sale_order_line where order_id = ANY(%s) and state=%s',(ids,'cancel'))
+ cr.execute('select id from sale_order_line where order_id IN %s and state=%s',(tuple(ids),'cancel'))
line_ids = map(lambda x: x[0], cr.fetchall())
self.write(cr, uid, ids, {'state': 'draft', 'invoice_ids': [], 'shipped': 0})
self.pool.get('sale.order.line').write(cr, uid, line_ids, {'invoiced': False, 'state': 'draft', 'invoice_lines': [(6, 0, [])]})
diff --git a/addons/scrum/report/_burndown.py b/addons/scrum/report/_burndown.py
index 7f5239e1224..6f0db24bcb6 100644
--- a/addons/scrum/report/_burndown.py
+++ b/addons/scrum/report/_burndown.py
@@ -26,13 +26,13 @@ import time
def compute_burndown(cr, uid, tasks_id, date_start, date_stop):
latest = False
if len(tasks_id):
- cr.execute('select id,create_date,state,planned_hours from project_task where id = ANY(%s) order by create_date',(tasks_id,))
+ cr.execute('select id,create_date,state,planned_hours from project_task where id IN %s order by create_date',(tuple(tasks_id),))
tasks = cr.fetchall()
- cr.execute('select w.date,w.hours from project_task_work w left join project_task t on (t.id=w.task_id) where t.id = ANY(%s) and t.state in (%s,%s) order by date',(tasks_id,'open','progress',))
+ cr.execute('select w.date,w.hours from project_task_work w left join project_task t on (t.id=w.task_id) where t.id IN %s and t.state in (%s,%s) order by date',(tuple(tasks_id),'open','progress',))
tasks2 = cr.fetchall()
- cr.execute('select date_end,planned_hours from project_task where id =ANY(%s) and state in (%s,%s) order by date_end' ,(tasks_id,'cancelled','done',))
+ cr.execute('select date_end,planned_hours from project_task where id IN %s and state in (%s,%s) order by date_end' ,(tuple(tasks_id),'cancelled','done',))
tasks2 += cr.fetchall()
tasks2.sort()
else:
diff --git a/addons/scrum/report/task_burndown.py b/addons/scrum/report/task_burndown.py
index 36296bcee5f..efd285c357e 100644
--- a/addons/scrum/report/task_burndown.py
+++ b/addons/scrum/report/task_burndown.py
@@ -43,9 +43,9 @@ class external_pdf(render):
def burndown_chart(cr, uid, tasks_id, date_start, date_stop):
latest = False
- cr.execute('select id,date_start,state,planned_hours from project_task where id = ANY(%s) order by date_start'(tasks_id,))
+ cr.execute('select id,date_start,state,planned_hours from project_task where id IN %s order by date_start'(tuple(tasks_id),))
tasks = cr.fetchall()
- cr.execute('select id,date_end,state,planned_hours*progress/100 from project_task where id =ANY(%s) and state in (%s,%s) order by date_end', (tasks_id,'progress','done',))
+ cr.execute('select id,date_end,state,planned_hours*progress/100 from project_task where id IN %s and state in (%s,%s) order by date_end', (tuple(tasks_id),'progress','done',))
tasks2 = cr.fetchall()
current_date = date_start
total = 0
@@ -72,14 +72,14 @@ class report_tasks(report_int):
io = StringIO.StringIO()
if 'date_start' not in datas:
- cr.execute('select min(date_start) from project_task where id = ANY(%s)',(ids,))
+ cr.execute('select min(date_start) from project_task where id IN %s',(tuple(ids),))
dt = cr.fetchone()[0]
if dt:
datas['date_start'] = dt[:10]
else:
datas['date_start'] = time.strftime('%Y-%m-%d')
if 'date_stop' not in datas:
- cr.execute('select max(date_start),max(date_end) from project_task where id = ANY(%s)',(ids,))
+ cr.execute('select max(date_start),max(date_end) from project_task where id IN %s',(tuple(ids),))
res = cr.fetchone()
datas['date_stop'] = (res[0] and res[0][:10]) or time.strftime('%Y-%m-%d')
if res[1] and datas['date_stop']