diff options
| author | HDA (OpenERP) <hda@tinyerp.com> | 2010-02-01 13:59:39 +0530 |
|---|---|---|
| committer | HDA (OpenERP) <hda@tinyerp.com> | 2010-02-01 13:59:39 +0530 |
| commit | 93bd614c8e25553ae6fc7eef8eb52105c22a02e6 (patch) | |
| tree | a91657d0fbef7e2ad4c663172ce757955f20f23e | |
| parent | a31a105e3329f55c28a5d289f152091a1bf1cc31 (diff) | |
| parent | 59ea96657ad15d170f582a80b7bf1cd80ff896f3 (diff) | |
merged to remove sql injection
bzr revid: hda@tinyerp.com-20100201082939-fj0u5f0pvlgq7j3k
78 files changed, 854 insertions, 978 deletions
diff --git a/addons/account/account.py b/addons/account/account.py index 3772a660de9..ddb90cc13cc 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -201,20 +201,19 @@ class account_account(osv.osv): } #get all the necessary accounts ids2 = self._get_children_and_consol(cr, uid, ids, context) - acc_set = ",".join(map(str, ids2)) #compute for each account the balance/debit/credit from the move lines accounts = {} if ids2: query = self.pool.get('account.move.line')._query_get(cr, uid, context=context) - cr.execute(("SELECT l.account_id as id, " +\ + cr.execute("SELECT l.account_id as id, " +\ ' , '.join(map(lambda x: mapping[x], field_names)) + "FROM " \ "account_move_line l " \ "WHERE " \ - "l.account_id IN (%s) " \ + "l.account_id =ANY(%s) " \ "AND " + query + " " \ - "GROUP BY l.account_id") % (acc_set, )) + "GROUP BY l.account_id",(ids2,)) for res in cr.dictfetchall(): accounts[res['id']] = res @@ -334,7 +333,7 @@ class account_account(osv.osv): if (obj_self in obj_self.child_consol_ids) or (p_id and (p_id is obj_self.id)): return False while(ids): - cr.execute('select distinct child_id from account_account_consol_rel where parent_id in ('+','.join(map(str, ids))+')') + cr.execute('select distinct child_id from account_account_consol_rel where parent_id =ANY(%s)',(ids,)) child_ids = filter(None, map(lambda x: x[0], cr.fetchall())) c_ids = child_ids if (p_id and (p_id in c_ids)) or (obj_self.id in c_ids): @@ -774,7 +773,7 @@ class account_move(osv.osv): def _amount_compute(self, cr, uid, ids, name, args, context, where =''): if not ids: return {} - cr.execute('select move_id,sum(debit) from account_move_line where move_id in ('+','.join(map(str,map(int, ids)))+') group by move_id') + cr.execute('select move_id,sum(debit) from account_move_line where move_id =ANY(%s) group by move_id',(ids,)) result = dict(cr.fetchall()) for id in ids: result.setdefault(id, 0.0) @@ -872,7 +871,7 @@ class account_move(osv.osv): if new_name: self.write(cr, uid, [move.id], {'name':new_name}) - cr.execute('update account_move set state=%s where id in ('+','.join(map(str, ids))+')', ('posted',)) + cr.execute('update account_move set state=%s where id =ANY(%s) ',('posted',ids,)) else: raise osv.except_osv(_('Integrity Error !'), _('You can not validate a non-balanced entry !')) return True @@ -885,7 +884,7 @@ class account_move(osv.osv): if not line.journal_id.update_posted: raise osv.except_osv(_('Error !'), _('You can not modify a posted entry of this journal !\nYou should set the journal to allow cancelling entries if you want to do that.')) if len(ids): - cr.execute('update account_move set state=%s where id in ('+','.join(map(str, ids))+')', ('draft',)) + cr.execute('update account_move set state=%s where id =ANY(%s)',('draft',ids,)) return True def write(self, cr, uid, ids, vals, context={}): @@ -1155,23 +1154,22 @@ class account_tax_code(osv.osv): """ def _sum(self, cr, uid, ids, name, args, context, where =''): ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)]) - acc_set = ",".join(map(str, ids2)) if context.get('based_on', 'invoices') == 'payments': cr.execute('SELECT line.tax_code_id, sum(line.tax_amount) \ FROM account_move_line AS line, \ account_move AS move \ LEFT JOIN account_invoice invoice ON \ (invoice.move_id = move.id) \ - WHERE line.tax_code_id in ('+acc_set+') '+where+' \ + WHERE line.tax_code_id =ANY(%s) '+where+' \ AND move.id = line.move_id \ AND ((invoice.state = \'paid\') \ OR (invoice.id IS NULL)) \ - GROUP BY line.tax_code_id') + GROUP BY line.tax_code_id',(ids2,)) else: cr.execute('SELECT line.tax_code_id, sum(line.tax_amount) \ FROM account_move_line AS line \ - WHERE line.tax_code_id in ('+acc_set+') '+where+' \ - GROUP BY line.tax_code_id') + WHERE line.tax_code_id =ANY(%s) '+where+' \ + GROUP BY line.tax_code_id',(ids2,)) res=dict(cr.fetchall()) for record in self.browse(cr, uid, ids, context): def _rec_get(record): @@ -1246,7 +1244,7 @@ class account_tax_code(osv.osv): def _check_recursion(self, cr, uid, ids): level = 100 while len(ids): - cr.execute('select distinct parent_id from account_tax_code where id in ('+','.join(map(str, ids))+')') + cr.execute('select distinct parent_id from account_tax_code where id =ANY(%s)',(ids,)) ids = filter(None, map(lambda x:x[0], cr.fetchall())) if not level: return False @@ -1858,7 +1856,7 @@ class account_account_template(osv.osv): def _check_recursion(self, cr, uid, ids): level = 100 while len(ids): - cr.execute('select parent_id from account_account_template where id in ('+','.join(map(str, ids))+')') + cr.execute('select parent_id from account_account_template where id =ANY(%s)',(ids,)) ids = filter(None, map(lambda x:x[0], cr.fetchall())) if not level: return False @@ -1978,7 +1976,7 @@ class account_tax_code_template(osv.osv): def _check_recursion(self, cr, uid, ids): level = 100 while len(ids): - cr.execute('select distinct parent_id from account_tax_code_template where id in ('+','.join(map(str, ids))+')') + cr.execute('select distinct parent_id from account_tax_code_template where id =ANY(%s)',(ids,)) ids = filter(None, map(lambda x:x[0], cr.fetchall())) if not level: return False diff --git a/addons/account/account_move_line.py b/addons/account/account_move_line.py index 9b126658157..e5e16ee73cc 100644 --- a/addons/account/account_move_line.py +++ b/addons/account/account_move_line.py @@ -258,7 +258,7 @@ class account_move_line(osv.osv): cursor.execute('SELECT l.id, i.id ' \ 'FROM account_move_line l, account_invoice i ' \ 'WHERE l.move_id = i.move_id ' \ - 'AND l.id in (' + ','.join([str(x) for x in ids]) + ')') + 'AND l.id =ANY(%s)',(ids,)) invoice_ids = [] for line_id, invoice_id in cursor.fetchall(): res[line_id] = invoice_id @@ -553,8 +553,6 @@ class account_move_line(osv.osv): return True def reconcile(self, cr, uid, ids, type='auto', writeoff_acc_id=False, writeoff_period_id=False, writeoff_journal_id=False, context={}): - id_set = ','.join(map(str, ids)) - lines = self.browse(cr, uid, ids, context=context) unrec_lines = filter(lambda x: not x['reconcile_id'], lines) credit = debit = 0.0 @@ -579,10 +577,10 @@ class account_move_line(osv.osv): cr.execute('SELECT account_id, reconcile_id \ FROM account_move_line \ - WHERE id IN ('+id_set+') \ - GROUP BY account_id,reconcile_id') + WHERE id =ANY(%s) \ + GROUP BY account_id,reconcile_id',(ids,)) r = cr.fetchall() -#TODO: move this check to a constraint in the account_move_reconcile object + #TODO: move this check to a constraint in the account_move_reconcile object if (len(r) != 1) and not context.get('fy_closing', False): raise osv.except_osv(_('Error'), _('Entries are not of the same account or already reconciled ! ')) if not unrec_lines: diff --git a/addons/account/partner.py b/addons/account/partner.py index a3985ee68e9..215c4286315 100644 --- a/addons/account/partner.py +++ b/addons/account/partner.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). # @@ -15,7 +15,7 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. +# along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## @@ -90,20 +90,20 @@ class res_partner(osv.osv): _description = 'Partner' def _credit_debit_get(self, cr, uid, ids, field_names, arg, context): query = self.pool.get('account.move.line')._query_get(cr, uid, context=context) - cr.execute(("""select + cr.execute("""select l.partner_id, a.type, sum(l.debit-l.credit) from account_move_line l left join account_account a on (l.account_id=a.id) where - a.type in ('receivable','payable') and - l.partner_id in (%s) and + a.type =ANY(%s) and + l.partner_id =ANY(%s) and l.reconcile_id is null and - """ % (','.join(map(str, ids)),))+query+""" + """+query+""" group by l.partner_id, a.type - """) + """,(['receivable','payable'],ids,)) tinvert = { 'credit': 'receivable', 'debit': 'payable' diff --git a/addons/account/project/project.py b/addons/account/project/project.py index e39e5b00d77..a381f587f8a 100644 --- a/addons/account/project/project.py +++ b/addons/account/project/project.py @@ -34,7 +34,6 @@ class account_analytic_account(osv.osv): _description = 'Analytic Accounts' def _credit_calc(self, cr, uid, ids, name, arg, context={}): - acc_set = ",".join(map(str, ids)) where_date = '' if context.get('from_date',False): @@ -42,7 +41,7 @@ class account_analytic_account(osv.osv): if context.get('to_date',False): where_date += " AND l.date <= '" + context['to_date'] + "'" - cr.execute("SELECT a.id, COALESCE(SUM(l.amount),0) FROM account_analytic_account a LEFT JOIN account_analytic_line l ON (a.id=l.account_id %s) WHERE l.amount<0 and a.id IN (%s) GROUP BY a.id" % (where_date,acc_set)) + cr.execute("SELECT a.id, COALESCE(SUM(l.amount),0) FROM account_analytic_account a LEFT JOIN account_analytic_line l ON (a.id=l.account_id "+where_date+") WHERE l.amount<0 and a.id =ANY(%s) GROUP BY a.id",(ids,)) r = dict(cr.fetchall()) for i in ids: r.setdefault(i,0.0) @@ -50,15 +49,13 @@ class account_analytic_account(osv.osv): def _debit_calc(self, cr, uid, ids, name, arg, context={}): - acc_set = ",".join(map(str, ids)) - where_date = '' if context.get('from_date',False): where_date += " AND l.date >= '" + context['from_date'] + "'" if context.get('to_date',False): where_date += " AND l.date <= '" + context['to_date'] + "'" - cr.execute("SELECT a.id, COALESCE(SUM(l.amount),0) FROM account_analytic_account a LEFT JOIN account_analytic_line l ON (a.id=l.account_id %s) WHERE l.amount>0 and a.id IN (%s) GROUP BY a.id" % (where_date,acc_set)) + cr.execute("SELECT a.id, COALESCE(SUM(l.amount),0) FROM account_analytic_account a LEFT JOIN account_analytic_line l ON (a.id=l.account_id "+where_date+") WHERE l.amount>0 and a.id =ANY(%s) GROUP BY a.id" ,(ids,)) r= dict(cr.fetchall()) for i in ids: r.setdefault(i,0.0) @@ -67,12 +64,9 @@ class account_analytic_account(osv.osv): def _balance_calc(self, cr, uid, ids, name, arg, context={}): res = {} ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)]) - acc_set = ",".join(map(str, ids2)) - for i in ids: res.setdefault(i,0.0) - - if not acc_set: + if not ids2: return res where_date = '' @@ -81,12 +75,12 @@ class account_analytic_account(osv.osv): if context.get('to_date',False): where_date += " AND l.date <= '" + context['to_date'] + "'" - cr.execute("SELECT a.id, COALESCE(SUM(l.amount),0) FROM account_analytic_account a LEFT JOIN account_analytic_line l ON (a.id=l.account_id %s) WHERE a.id IN (%s) GROUP BY a.id" % (where_date,acc_set)) + cr.execute("SELECT a.id, COALESCE(SUM(l.amount),0) FROM account_analytic_account a LEFT JOIN account_analytic_line l ON (a.id=l.account_id "+where_date+") WHERE a.id =ANY(%s) GROUP BY a.id",(ids2,)) for account_id, sum in cr.fetchall(): res[account_id] = sum - cr.execute("SELECT a.id, r.currency_id FROM account_analytic_account a INNER JOIN res_company r ON (a.company_id = r.id) where a.id in (%s)" % acc_set) + cr.execute("SELECT a.id, r.currency_id FROM account_analytic_account a INNER JOIN res_company r ON (a.company_id = r.id) where a.id =ANY(%s)",(ids2,)) currency= dict(cr.fetchall()) @@ -131,7 +125,7 @@ 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 IN ('+acc_set+') GROUP BY a.id') + WHERE a.id =ANY(%s) GROUP BY a.id',(ids2,)) for account_id, sum in cr.fetchall(): res[account_id] = sum diff --git a/addons/account/project/report/analytic_balance.py b/addons/account/project/report/analytic_balance.py index ab4c5f87ac0..f7b909ae452 100644 --- a/addons/account/project/report/analytic_balance.py +++ b/addons/account/project/report/analytic_balance.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). # @@ -15,7 +15,7 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. +# along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## @@ -47,7 +47,7 @@ class account_analytic_balance(report_sxw.rml_parse): self.empty_acc = False self.acc_data_dict = {}# maintains a relation with an account with its successors. self.acc_sum_list = []# maintains a list of all ids - + def get_children(self, ids): ids2 = [] read_data = self.pool.get('account.analytic.account').read(self.cr, self.uid, ids,['child_ids','code','complete_name','balance']) @@ -56,23 +56,23 @@ class account_analytic_balance(report_sxw.rml_parse): inculde_empty = True if (not self.empty_acc) and data['balance'] == 0.00: inculde_empty = False - if inculde_empty: + if inculde_empty: self.acc_ids.append(data['id']) self.read_data.append(data) if data['child_ids']: - res = self.get_children(data['child_ids']) - return True - - + res = self.get_children(data['child_ids']) + return True + + def _get_objects(self, empty_acc): if self.read_data: return self.read_data self.empty_acc = empty_acc self.read_data = [] self.get_children(self.ids) - + return self.read_data - + def _lines_g(self, account_id, date1, date2): account_analytic_obj = self.pool.get('account.analytic.account') ids = account_analytic_obj.search(self.cr, self.uid, @@ -86,7 +86,7 @@ class account_analytic_balance(report_sxw.rml_parse): GROUP BY aal.general_account_id, aa.name, aa.code, aal.code \ ORDER BY aal.code", (date1, date2)) res = self.cr.dictfetchall() - + for r in res: if r['balance'] > 0: r['debit'] = r['balance'] @@ -99,7 +99,7 @@ class account_analytic_balance(report_sxw.rml_parse): r['debit'] = 0.0 r['credit'] = 0.0 return res - + def _move_sum(self, account_id, date1, date2, option): if account_id not in self.acc_data_dict: account_analytic_obj = self.pool.get('account.analytic.account') @@ -107,24 +107,23 @@ class account_analytic_balance(report_sxw.rml_parse): self.acc_data_dict[account_id] = ids else: ids = self.acc_data_dict[account_id] - + if option == "credit" : self.cr.execute("SELECT -sum(amount) FROM account_analytic_line \ - WHERE account_id in ("+ ','.join(map(str, ids)) +") \ - AND date>=%s AND date<=%s AND amount<0", - (date1, date2)) + WHERE account_id =ANY(%s) AND date>=%s AND date<=%s AND amount<0", + (ids,date1, date2)) elif option == "debit" : self.cr.execute("SELECT sum(amount) FROM account_analytic_line \ - WHERE account_id in ("+ ','.join(map(str, ids)) +") \ + WHERE account_id =ANY(%s)\ AND date>=%s AND date<=%s AND amount>0", - (date1, date2)) + (ids,date1, date2)) elif option == "quantity" : self.cr.execute("SELECT sum(unit_amount) FROM account_analytic_line \ - WHERE account_id in ("+ ','.join(map(str, ids)) +") \ + WHERE account_id =ANY(%s)\ AND date>=%s AND date<=%s", - (date1, date2)) + (ids,date1, date2)) return self.cr.fetchone()[0] or 0.0 - + # def _move_sum_debit(self, account_id, date1, date2): # account_analytic_obj = self.pool.get('account.analytic.account') @@ -147,12 +146,12 @@ class account_analytic_balance(report_sxw.rml_parse): # AND date>=%s AND date<=%s AND amount<0", # (date1, date2)) # return self.cr.fetchone()[0] or 0.0 -# +# def _move_sum_balance(self, account_id, date1, date2): - debit = self._move_sum(account_id, date1, date2, 'debit') + debit = self._move_sum(account_id, date1, date2, 'debit') credit = self._move_sum(account_id, date1, date2, 'credit') return (debit-credit) - + # def _move_sum_quantity(self, account_id, date1, date2): # account_analytic_obj = self.pool.get('account.analytic.account') # ids = account_analytic_obj.search(self.cr, self.uid, @@ -166,7 +165,6 @@ class account_analytic_balance(report_sxw.rml_parse): def _sum_all(self, accounts, date1, date2, option): ids = map(lambda x: x['id'], accounts) - if not len(ids): return 0.0 @@ -176,25 +174,21 @@ class account_analytic_balance(report_sxw.rml_parse): self.acc_sum_list = ids2 else: ids2 = self.acc_sum_list - if option == "debit" : self.cr.execute("SELECT sum(amount) FROM account_analytic_line \ - WHERE account_id IN ("+','.join(map(str, ids2))+") \ - AND date>=%s AND date<=%s AND amount>0", - (date1, date2)) + WHERE account_id =ANY(%s) AND date>=%s AND date<=%s AND amount>0", + (ids,date1, date2,)) elif option == "credit" : self.cr.execute("SELECT -sum(amount) FROM account_analytic_line \ - WHERE account_id IN ("+','.join(map(str, ids2))+") \ - AND date>=%s AND date<=%s AND amount<0", - (date1, date2)) + WHERE account_id =ANY(%s) AND date>=%s AND date<=%s AND amount<0", + (ids,date1, date2,)) elif option == "quantity" : self.cr.execute("SELECT sum(unit_amount) FROM account_analytic_line \ - WHERE account_id IN ("+','.join(map(str, ids2))+") \ - AND date>=%s AND date<=%s", - (date1, date2)) + WHERE account_id =ANY(%s)AND date>=%s AND date<=%s", + (ids,date1, date2,)) return self.cr.fetchone()[0] or 0.0 - + # def _sum_debit(self, accounts, date1, date2): # ids = map(lambda x: x['id'], accounts) # if not len(ids): @@ -208,7 +202,7 @@ class account_analytic_balance(report_sxw.rml_parse): # AND date>=%s AND date<=%s AND amount>0", # (date1, date2)) # return self.cr.fetchone()[0] or 0.0 -# +# # def _sum_credit(self, accounts, date1, date2): # ids = map(lambda x: x['id'], accounts) # if not len(ids): diff --git a/addons/account/project/report/analytic_check.py b/addons/account/project/report/analytic_check.py index a97f94757af..0469c3b6918 100644 --- a/addons/account/project/report/analytic_check.py +++ b/addons/account/project/report/analytic_check.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). # @@ -15,7 +15,7 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. +# along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## @@ -43,7 +43,6 @@ class account_analytic_analytic_check(report_sxw.rml_parse): def _lines_p(self, date1, date2): res = [] acc_obj = self.pool.get('account.account') - # print"3333333acc_obj3333333",acc_obj.read(self.cr, self.uid, self.ids, ['name', 'code','user_type']) for a in acc_obj.read(self.cr, self.uid, self.ids, ['name', 'code']): self.cr.execute("SELECT sum(debit), sum(credit) \ diff --git a/addons/account/project/report/cost_ledger.py b/addons/account/project/report/cost_ledger.py index 1109549ace4..9163cd8e0d4 100644 --- a/addons/account/project/report/cost_ledger.py +++ b/addons/account/project/report/cost_ledger.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). # @@ -15,7 +15,7 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. +# along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## @@ -85,7 +85,7 @@ class account_analytic_cost_ledger(report_sxw.rml_parse): return self.cr.fetchone()[0] or 0.0 def _account_sum_balance(self, account_id, date1, date2): - debit = self._account_sum_debit(account_id, date1, date2) + debit = self._account_sum_debit(account_id, date1, date2) credit = self._account_sum_credit(account_id, date1, date2) return (debit-credit) @@ -93,7 +93,7 @@ class account_analytic_cost_ledger(report_sxw.rml_parse): ids = map(lambda x: x.id, accounts) if not len(ids): return 0.0 - self.cr.execute("SELECT sum(amount) FROM account_analytic_line WHERE account_id IN ("+','.join(map(str, ids))+") AND date>=%s AND date<=%s AND amount>0", (date1, date2)) + self.cr.execute("SELECT sum(amount) FROM account_analytic_line WHERE account_id =ANY(%s) AND date>=%s AND date<=%s AND amount>0", (ids, date1, date2,)) return self.cr.fetchone()[0] or 0.0 def _sum_credit(self, accounts, date1, date2): @@ -101,7 +101,7 @@ class account_analytic_cost_ledger(report_sxw.rml_parse): if not len(ids): return 0.0 ids = map(lambda x: x.id, accounts) - self.cr.execute("SELECT -sum(amount) FROM account_analytic_line WHERE account_id IN ("+','.join(map(str, ids))+") AND date>=%s AND date<=%s AND amount<0", (date1, date2)) + self.cr.execute("SELECT -sum(amount) FROM account_analytic_line WHERE account_id =ANY(%s) AND date>=%s AND date<=%s AND amount<0", (ids,date1, date2,)) return self.cr.fetchone()[0] or 0.0 def _sum_balance(self, accounts, date1, date2): diff --git a/addons/account/project/report/inverted_analytic_balance.py b/addons/account/project/report/inverted_analytic_balance.py index 7071062e08a..37f469d4ef8 100644 --- a/addons/account/project/report/inverted_analytic_balance.py +++ b/addons/account/project/report/inverted_analytic_balance.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). # @@ -15,7 +15,7 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. +# along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## @@ -40,8 +40,8 @@ class account_inverted_analytic_balance(report_sxw.rml_parse): ids = map(lambda x: x.id, accounts) self.cr.execute("SELECT aa.name AS name, aa.code AS code, sum(aal.amount) AS balance, sum(aal.unit_amount) AS quantity, aa.id AS id \ FROM account_analytic_line AS aal, account_account AS aa \ - WHERE (aal.general_account_id=aa.id) AND (aal.account_id IN ("+','.join(map(str, ids))+")) AND (date>=%s) AND (date<=%s) AND aa.active \ - GROUP BY aal.general_account_id, aa.name, aa.code, aal.code, aa.id ORDER BY aal.code", (date1, date2)) + WHERE (aal.general_account_id=aa.id) AND (aal.account_id =ANY(%s)) AND (date>=%s) AND (date<=%s) AND aa.active \ + GROUP BY aal.general_account_id, aa.name, aa.code, aal.code, aa.id ORDER BY aal.code", (ids,date1,date2,)) res = self.cr.dictfetchall() for r in res: @@ -60,8 +60,8 @@ class account_inverted_analytic_balance(report_sxw.rml_parse): ids = map(lambda x: x.id, accounts) self.cr.execute("SELECT sum(aal.amount) AS balance, sum(aal.unit_amount) AS quantity, aaa.code AS code, aaa.name AS name, account_id \ FROM account_analytic_line AS aal, account_analytic_account AS aaa \ - WHERE aal.account_id=aaa.id AND aal.account_id IN ("+','.join(map(str, ids))+") AND aal.general_account_id=%s AND aal.date>=%s AND aal.date<=%s \ - GROUP BY aal.account_id, general_account_id, aaa.code, aaa.name ORDER BY aal.account_id", (general_account_id, date1, date2)) + WHERE aal.account_id=aaa.id AND aal.account_id =ANY(%s) AND aal.general_account_id=%s AND aal.date>=%s AND aal.date<=%s \ + GROUP BY aal.account_id, general_account_id, aaa.code, aaa.name ORDER BY aal.account_id", (ids,general_account_id, date1, date2,)) res = self.cr.dictfetchall() aaa_obj = self.pool.get('account.analytic.account') @@ -86,14 +86,14 @@ class account_inverted_analytic_balance(report_sxw.rml_parse): ids = map(lambda x: x.id, accounts) self.cr.execute("SELECT sum(amount) \ FROM account_analytic_line \ - WHERE account_id IN ("+','.join(map(str, ids))+") AND date>=%s AND date<=%s AND amount>0", (date1, date2)) + WHERE account_id =ANY(%s) AND date>=%s AND date<=%s AND amount>0", (ids,date1, date2,)) return self.cr.fetchone()[0] or 0.0 - + def _sum_credit(self, accounts, date1, date2): ids = map(lambda x: x.id, accounts) self.cr.execute("SELECT -sum(amount) \ FROM account_analytic_line \ - WHERE account_id IN ("+','.join(map(str, ids))+") AND date>=%s AND date<=%s AND amount<0", (date1, date2)) + WHERE account_id =ANY(%s) AND date>=%s AND date<=%s AND amount<0", (ids,date1, date2,)) return self.cr.fetchone()[0] or 0.0 def _sum_balance(self, accounts, date1, date2): @@ -105,7 +105,7 @@ class account_inverted_analytic_balance(report_sxw.rml_parse): ids = map(lambda x: x.id, accounts) self.cr.execute("SELECT sum(unit_amount) \ FROM account_analytic_line \ - WHERE account_id IN ("+','.join(map(str, ids))+") AND date>=%s AND date<=%s", (date1, date2)) + WHERE account_id =ANY(%s) AND date>=%s AND date<=%s", (ids,date1, date2,)) return self.cr.fetchone()[0] or 0.0 report_sxw.report_sxw('report.account.analytic.account.inverted.balance', 'account.analytic.account', 'addons/account/project/report/inverted_analytic_balance.rml',parser=account_inverted_analytic_balance, header=False) diff --git a/addons/account/project/report/quantity_cost_ledger.py b/addons/account/project/report/quantity_cost_ledger.py index 6d4b0579794..c841c2131ab 100644 --- a/addons/account/project/report/quantity_cost_ledger.py +++ b/addons/account/project/report/quantity_cost_ledger.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). # @@ -15,7 +15,7 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. +# along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## @@ -52,10 +52,9 @@ class account_analytic_quantity_cost_ledger(report_sxw.rml_parse): WHERE (aal.account_id=%s) AND (aal.date>=%s) \ AND (aal.date<=%s) AND (aal.general_account_id=aa.id) \ AND aa.active \ - AND (aal.journal_id IN (" + - ','.join(map(str, journal_ids)) + ")) \ + AND (aal.journal_id =ANY(%s) ) \ GROUP BY aa.code, aa.name, aa.id ORDER BY aa.code", - (account_id, date1, date2)) + (account_id, date1, date2,journal_ids)) res = self.cr.dictfetchall() return res @@ -80,10 +79,9 @@ class account_analytic_quantity_cost_ledger(report_sxw.rml_parse): account_analytic_journal AS aaj \ WHERE (aal.general_account_id=%s) AND (aal.account_id=%s) \ AND (aal.date>=%s) AND (aal.date<=%s) \ - AND (aal.journal_id=aaj.id) AND (aaj.id IN (" + - ','.join(map(str, journal_ids)) + ")) \ - ORDER BY aal.date, aaj.code, aal.code", - (general_account_id, account_id, date1, date2)) + AND (aal.journal_id=aaj.id) AND (aaj.id =ANY(%s)) \ + ORDER BY aal.date, aaj.code, aal.code", + (general_account_id, account_id, date1, date2,journal_ids,)) res = self.cr.dictfetchall() return res @@ -98,9 +96,8 @@ class account_analytic_quantity_cost_ledger(report_sxw.rml_parse): self.cr.execute("SELECT sum(unit_amount) \ FROM account_analytic_line \ WHERE account_id = %s AND date >= %s AND date <= %s \ - AND journal_id IN (" + - ','.join(map(str, journal_ids)) + ")", - (account_id, date1, date2)) + AND journal_id =ANY(%s)", + (account_id, date1, date2,journal_ids,)) return self.cr.fetchone()[0] or 0.0 def _sum_quantity(self, accounts, date1, date2, journals): @@ -110,18 +107,14 @@ class account_analytic_quantity_cost_ledger(report_sxw.rml_parse): if not journals or not journals[0][2]: self.cr.execute("SELECT sum(unit_amount) \ FROM account_analytic_line \ - WHERE account_id IN (" + - ','.join(map(str, ids)) + ") AND date>=%s AND date<=%s", - (date1, date2)) + WHERE account_id =ANY(%s) AND date>=%s AND date<=%s", + (date1, date2,ids,)) else: journal_ids = journals[0][2] self.cr.execute("SELECT sum(unit_amount) \ FROM account_analytic_line \ - WHERE account_id IN (" + - ','.join(map(str, ids)) + ") AND date >= %s AND date <= %s \ - AND journal_id IN (" + - ','.join(map(str, journal_ids)) + ")", - (date1, date2)) + WHERE account_id =ANY(%s) AND date >= %s AND date <= %s \ + AND journal_id =ANY(%s)",(ids,date1, date2,journal_ids)) return self.cr.fetchone()[0] or 0.0 report_sxw.report_sxw('report.account.analytic.account.quantity_cost_ledger', diff --git a/addons/account/report/account_balance.py b/addons/account/report/account_balance.py index 5c846dae7e1..1a93c371d20 100644 --- a/addons/account/report/account_balance.py +++ b/addons/account/report/account_balance.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). # @@ -15,7 +15,7 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. +# along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## @@ -57,10 +57,10 @@ class account_balance(report_sxw.rml_parse): def get_periods(self, form): result='' if form.has_key('periods') and form['periods'][0][2]: - period_ids = ",".join([str(x) for x in form['periods'][0][2] if x]) - self.cr.execute("select name from account_period where id in (%s)" % (period_ids)) + period_ids = form['periods'][0][2] + self.cr.execute("select name from account_period where id =ANY(%s)" ,(period_ids)) res = self.cr.fetchall() - len_res = len(res) + len_res = len(res) for r in res: if (r == res[len_res-1]): result+=r[0]+". " @@ -75,10 +75,10 @@ class account_balance(report_sxw.rml_parse): result+=r.name+". " else: result+=r.name+", " - + return str(result and result[:-1]) or '' - + def lines(self, form, ids={}, done=None, level=1): if not ids: ids = self.ids @@ -98,7 +98,7 @@ class account_balance(report_sxw.rml_parse): ctx['periods'] = form['periods'][0][2] elif form['state']== 'bydate': ctx['date_from'] = form['date_from'] - ctx['date_to'] = form['date_to'] + ctx['date_to'] = form['date_to'] elif form['state'] == 'all' : ctx['periods'] = form['periods'][0][2] ctx['date_from'] = form['date_from'] @@ -165,7 +165,7 @@ class account_balance(report_sxw.rml_parse): # # result_acc += self.lines(form, ids2, done, level+1) return result_acc - + def _sum_credit(self): return self.sum_credit diff --git a/addons/account/report/aged_trial_balance.py b/addons/account/report/aged_trial_balance.py index 5d3f1ae777d..c13ea96ea50 100644 --- a/addons/account/report/aged_trial_balance.py +++ b/addons/account/report/aged_trial_balance.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). # @@ -15,7 +15,7 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. +# along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## @@ -47,26 +47,26 @@ class aged_trial_report(rml_parse.rml_parse): def _get_lines(self, form): if (form['result_selection'] == 'customer' ): - self.ACCOUNT_TYPE = "('receivable')" + self.ACCOUNT_TYPE = ['receivable'] elif (form['result_selection'] == 'supplier'): - self.ACCOUNT_TYPE = "('payable')" + self.ACCOUNT_TYPE = ['payable'] else: - self.ACCOUNT_TYPE = "('payable','receivable')" + self.ACCOUNT_TYPE = ['payable','receivable'] res = [] account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line') self.line_query = account_move_line_obj._query_get(self.cr, self.uid, obj='line', context={'fiscalyear': form['fiscalyear']}) - self.cr.execute("""SELECT DISTINCT res_partner.id AS id, - res_partner.name AS name - FROM res_partner,account_move_line AS line, account_account - WHERE (line.account_id=account_account.id) - AND ((reconcile_id IS NULL) - OR (reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > '%s' ))) - AND (line.partner_id=res_partner.id) - AND (account_account.company_id = %s) - ORDER BY res_partner.name""" % (form['date1'],form['company_id'])) + self.cr.execute("""SELECT DISTINCT res_partner.id AS id, + res_partner.name AS name + FROM res_partner,account_move_line AS line, account_account + WHERE (line.account_id=account_account.id) + AND ((reconcile_id IS NULL) + OR (reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > %s ))) + AND (line.partner_id=res_partner.id) + AND (account_account.company_id = %s) + ORDER BY res_partner.name""" , (form['date1'],form['company_id'])) partners = self.cr.dictfetchall() ## mise a 0 du total for i in range(7): @@ -74,20 +74,20 @@ class aged_trial_report(rml_parse.rml_parse): # # Build a string like (1,2,3) for easy use in SQL query - partner_ids = '(' + ','.join( [str(x['id']) for x in partners] ) + ')' + partner_ids = [x['id'] for x in partners] # This dictionary will store the debit-credit for all partners, using partner_id as key. totals = {} - self.cr.execute("""SELECT partner_id, SUM(debit-credit) + self.cr.execute("""SELECT partner_id, SUM(debit-credit) FROM account_move_line AS line, account_account - WHERE (line.account_id = account_account.id) - AND (account_account.type IN %s) - AND (partner_id in %s) + WHERE (line.account_id = account_account.id) + AND (account_account.type =ANY(%s)) + AND (partner_id =ANY (%s)) AND ((reconcile_id IS NULL) - OR (reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > '%s' ))) - AND (account_account.company_id = %s) - AND account_account.active - GROUP BY partner_id""" % (self.ACCOUNT_TYPE, partner_ids,form['date1'],form['company_id'])) + OR (reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > %s ))) + AND (account_account.company_id = %s) + AND account_account.active + GROUP BY partner_id""" , (self.ACCOUNT_TYPE, partner_ids,form['date1'],form['company_id'],)) t = self.cr.fetchall() for i in t: totals[i[0]] = i[1] @@ -95,17 +95,17 @@ class aged_trial_report(rml_parse.rml_parse): # This dictionary will store the future or past of all partners future_past = {} if form['direction_selection'] == 'future': - self.cr.execute("""SELECT partner_id, SUM(debit-credit) - FROM account_move_line AS line, account_account - WHERE (line.account_id=account_account.id) - AND (account_account.type IN %s) - AND (COALESCE(date_maturity,date) < '%s') - AND (partner_id in %s) + self.cr.execute("""SELECT partner_id, SUM(debit-credit) + FROM account_move_line AS line, account_account + WHERE (line.account_id=account_account.id) + AND (account_account.type =ANY (%s)) + AND (COALESCE(date_maturity,date) < %s) + AND (partner_id =ANY (%s)) AND ((reconcile_id IS NULL) - OR (reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > '%s' ))) - AND (account_account.company_id = %s) - AND account_account.active - GROUP BY partner_id"""% (self.ACCOUNT_TYPE, form['date1'], partner_ids,form['date1'], form['company_id'])) + OR (reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > %s ))) + AND (account_account.company_id = %s) + AND account_account.active + GROUP BY partner_id""", (self.ACCOUNT_TYPE, form['date1'], partner_ids,form['date1'], form['company_id'],)) t = self.cr.fetchall() for i in t: future_past[i[0]] = i[1] @@ -113,14 +113,14 @@ class aged_trial_report(rml_parse.rml_parse): self.cr.execute("""SELECT partner_id, SUM(debit-credit) FROM account_move_line AS line, account_account WHERE (line.account_id=account_account.id) - AND (account_account.type IN %s) - AND (COALESCE(date_maturity,date) > '%s') - AND (partner_id in %s) + AND (account_account.type =ANY (%s)) + AND (COALESCE(date_maturity,date) > %s) + AND (partner_id =ANY (%s)) AND ((reconcile_id IS NULL) - OR (reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > '%s' ))) + OR (reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > %s ))) AND (account_account.company_id = %s) AND account_account.active - GROUP BY partner_id""" % (self.ACCOUNT_TYPE, form['date1'], partner_ids, form['date1'], form['company_id'])) + GROUP BY partner_id""" , (self.ACCOUNT_TYPE, form['date1'], partner_ids, form['date1'], form['company_id'],)) t = self.cr.fetchall() for i in t: future_past[i[0]] = i[1] @@ -132,14 +132,14 @@ class aged_trial_report(rml_parse.rml_parse): self.cr.execute("""SELECT partner_id, SUM(debit-credit) FROM account_move_line AS line, account_account WHERE (line.account_id=account_account.id) - AND (account_account.type IN %s) - AND (COALESCE(date_maturity,date) BETWEEN '%s' AND '%s') - AND (partner_id in %s ) + AND (account_account.type =ANY (%s)) + AND (COALESCE(date_maturity,date) BETWEEN %s AND %s) + AND (partner_id =ANY (%s)) AND ((reconcile_id IS NULL) - OR (reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > '%s' ))) + OR (reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > %s ))) AND (account_account.company_id = %s) AND account_account.active - GROUP BY partner_id""" % (self.ACCOUNT_TYPE, form[str(i)]['start'], form[str(i)]['stop'],partner_ids ,form['date1'] ,form['company_id'])) + GROUP BY partner_id""" , (self.ACCOUNT_TYPE, form[str(i)]['start'], form[str(i)]['stop'],partner_ids ,form['date1'] ,form['company_id'],)) t = self.cr.fetchall() d = {} diff --git a/addons/account/report/general_journal.py b/addons/account/report/general_journal.py index 6d21ff2f513..2da07e04cfd 100644 --- a/addons/account/report/general_journal.py +++ b/addons/account/report/general_journal.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). # @@ -15,7 +15,7 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. +# along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## @@ -41,10 +41,10 @@ class journal_print(report_sxw.rml_parse): def set_context(self, objects, data, ids, report_type = None): super(journal_print, self).set_context(objects, data, ids, report_type) - self.cr.execute('select period_id, journal_id from account_journal_period where id in (' + ','.join([str(id) for id in ids]) + ')') + self.cr.execute('select period_id, journal_id from account_journal_period where id =ANY(%s)',(ids,)) res = self.cr.fetchall() - self.period_ids = ','.join([str(x[0]) for x in res]) - self.journal_ids = ','.join([str(x[1]) for x in res]) + self.period_ids = map(lambda x:x[0],res) + self.journal_ids = map(lambda x:x[1],res) # returns a list of period objs def periods(self, journal_period_objs): @@ -74,7 +74,7 @@ class journal_print(report_sxw.rml_parse): periods.append(data.period_id.id) for period in periods: period_data = self.pool.get('account.period').browse(self.cr, self.uid, period) - self.cr.execute('select j.code, j.name, sum(l.debit) as debit, sum(l.credit) as credit from account_move_line l left join account_journal j on (l.journal_id=j.id) where period_id=%s and journal_id in (' + ','.join(map(str, journal_id)) + ') and l.state<>\'draft\' group by j.id, j.code, j.name', (period,)) + self.cr.execute('select j.code, j.name, sum(l.debit) as debit, sum(l.credit) as credit from account_move_line l left join account_journal j on (l.journal_id=j.id) where period_id=%s and journal_id =ANY(%s) and l.state<>\'draft\' group by j.id, j.code, j.name', (period,journal_id,)) res = self.cr.dictfetchall() res[0].update({'period_name':period_data.name}) res[0].update({'pid':period}) @@ -82,45 +82,45 @@ class journal_print(report_sxw.rml_parse): return lines_data if not self.journal_ids: return [] - self.cr.execute('select j.code, j.name, sum(l.debit) as debit, sum(l.credit) as credit from account_move_line l left join account_journal j on (l.journal_id=j.id) where period_id=%s and journal_id in (' + self.journal_ids + ') and l.state<>\'draft\' group by j.id, j.code, j.name', (period_id,)) + self.cr.execute('select j.code, j.name, sum(l.debit) as debit, sum(l.credit) as credit from account_move_line l left join account_journal j on (l.journal_id=j.id) where period_id=%s and journal_id =ANY(%s) and l.state<>\'draft\' group by j.id, j.code, j.name', (period_id,self.journal_ids,)) res = self.cr.dictfetchall() return res def _sum_debit_period(self, period_id,journal_id=None): if type(journal_id)==type([]): - self.cr.execute('select sum(debit) from account_move_line where period_id=%s and journal_id in (' + ','.join(map(str, journal_id)) + ') and state<>\'draft\'', (period_id,)) + self.cr.execute('select sum(debit) from account_move_line where period_id=%s and journal_id =ANY(%s) and state<>\'draft\'', (period_id,journal_id,)) return self.cr.fetchone()[0] or 0.0 if not self.journal_ids: return 0.0 - self.cr.execute('select sum(debit) from account_move_line where period_id=%s and journal_id in (' + self.journal_ids + ') and state<>\'draft\'', (period_id,)) + self.cr.execute('select sum(debit) from account_move_line where period_id=%s and journal_id =ANY(%s) and state<>\'draft\'', (period_id,self.journal_ids,)) return self.cr.fetchone()[0] or 0.0 def _sum_credit_period(self, period_id,journal_id=None): if type(journal_id)==type([]): - self.cr.execute('select sum(credit) from account_move_line where period_id=%s and journal_id in (' + ','.join(map(str, journal_id)) + ') and state<>\'draft\'', (period_id,)) + self.cr.execute('select sum(credit) from account_move_line where period_id=%s and journal_id =ANY(%s) and state<>\'draft\'', (period_id,journal_id,)) return self.cr.fetchone()[0] or 0.0 if not self.journal_ids: return 0.0 - self.cr.execute('select sum(credit) from account_move_line where period_id=%s and journal_id in (' + self.journal_ids + ') and state<>\'draft\'', (period_id,)) + self.cr.execute('select sum(credit) from account_move_line where period_id=%s and journal_id =ANY(%s) and state<>\'draft\'', (period_id,self.journal_ids,)) return self.cr.fetchone()[0] or 0.0 def _sum_debit(self,period_id=None,journal_id=None): if type(period_id)==type([]): - self.cr.execute('select sum(debit) from account_move_line where period_id in (' + ','.join(map(str, period_id)) + ') and journal_id in (' + ','.join(map(str, journal_id)) + ') and state<>\'draft\'') + self.cr.execute('select sum(debit) from account_move_line where period_id =ANY(%s) and journal_id =ANY(%s) and state<>\'draft\'',(period_id,journal_id,)) return self.cr.fetchone()[0] or 0.0 if not self.journal_ids or not self.period_ids: return 0.0 - self.cr.execute('select sum(debit) from account_move_line where period_id in (' + self.period_ids + ') and journal_id in (' + self.journal_ids + ') and state<>\'draft\'') + self.cr.execute('select sum(debit) from account_move_line where period_id =ANY(%s) and journal_id =ANY(%s) and state<>\'draft\'',(self.period_ids,self.journal_ids,)) return self.cr.fetchone()[0] or 0.0 def _sum_credit(self,period_id=None,journal_id=None): if type(period_id)==type([]): - self.cr.execute('select sum(credit) from account_move_line where period_id in (' + ','.join(map(str, period_id)) + ') and journal_id in (' + ','.join(map(str, journal_id)) + ') and state<>\'draft\'') + self.cr.execute('select sum(credit) from account_move_line where period_id =ANY(%s) and journal_id =ANY(%s) and state<>\'draft\'',(period_id,journal_id,)) return self.cr.fetchone()[0] or 0.0 if not self.journal_ids or not self.period_ids: return 0.0 - self.cr.execute('select sum(credit) from account_move_line where period_id in (' + self.period_ids + ') and journal_id in (' + self.journal_ids + ') and state<>\'draft\'') + self.cr.execute('select sum(credit) from account_move_line where period_id =ANY(%s) and journal_id =ANY(%s) and state<>\'draft\'',(self.period_ids,self.journal_ids,)) return self.cr.fetchone()[0] or 0.0 report_sxw.report_sxw('report.account.general.journal', 'account.journal.period', 'addons/account/report/general_journal.rml',parser=journal_print) report_sxw.report_sxw('report.account.general.journal.wiz', 'account.journal.period', 'addons/account/report/wizard_general_journal.rml',parser=journal_print, header=False) diff --git a/addons/account/report/general_ledger.py b/addons/account/report/general_ledger.py index beb96f3cf24..5db2545d070 100644 --- a/addons/account/report/general_ledger.py +++ b/addons/account/report/general_ledger.py @@ -89,7 +89,7 @@ class general_ledger(rml_parse.rml_parse): # We have the account ID we will search all account move line from now until this time # We are in the case of we are on the top of the account move Line cr.execute('SELECT distinct(ac.code) as code_rest,ac.name as name_rest from account_account AS ac, account_move_line mv\ - where ac.id = mv.account_id and mv.move_id = ' + num_id_move +' and mv.account_id <> ' + account_id ) + where ac.id = mv.account_id and mv.move_id = %s and mv.account_id <> %s' ,(num_id_move,account_id,)) res_mv = cr.dictfetchall() # we need a result more than 2 line to make the test so we will made the the on 1 because we have exclude the current line if (len(res_mv) >=1): @@ -120,15 +120,11 @@ class general_ledger(rml_parse.rml_parse): ## This function will return the most aged date periods = form['periods'][0][2] if not periods: - sql = """ - Select min(p.date_start) as start_date,max(p.date_stop) as stop_date from account_period as p where p.fiscalyear_id = """ + str(form['fiscalyear']) + """ - """ + self.cr.execute(""" + Select min(p.date_start) as start_date,max(p.date_stop) as stop_date from account_period as p where p.fiscalyear_id = %s""",(form['fiscalyear'],)) else: - periods_id = ','.join(map(str, periods)) - sql = """ - Select min(p.date_start) as start_date,max(p.date_stop) as stop_date from account_period as p where p.id in ( """ + periods_id + """) - """ - self.cr.execute(sql) + self.cr.execute(""" + Select min(p.date_start) as start_date,max(p.date_stop) as stop_date from account_period as p where p.id =ANY(%s)""",(periods,)) res = self.cr.dictfetchall() borne_min = res[0]['start_date'] borne_max = res[0]['stop_date'] @@ -138,15 +134,11 @@ class general_ledger(rml_parse.rml_parse): elif form['state'] == 'all': periods = form['periods'][0][2] if not periods: - sql = """ - Select min(p.date_start) as start_date,max(p.date_stop) as stop_date from account_period as p where p.fiscalyear_id = """ + str(form['fiscalyear']) + """ - """ + self.cr.execute(""" + Select min(p.date_start) as start_date,max(p.date_stop) as stop_date from account_period as p where p.fiscalyear_id = %s""",(form['fiscalyear'],)) else: - periods_id = ','.join(map(str, periods)) - sql = """ - Select min(p.date_start) as start_date,max(p.date_stop) as stop_date from account_period as p where p.id in ( """ + periods_id + """) - """ - self.cr.execute(sql) + self.cr.execute(""" + Select min(p.date_start) as start_date,max(p.date_stop) as stop_date from account_period as p where p.id =ANY(%s)""",(periods,)) res = self.cr.dictfetchall() period_min = res[0]['start_date'] period_max = res[0]['stop_date'] @@ -230,8 +222,8 @@ class general_ledger(rml_parse.rml_parse): else: ## We will now compute solde initiaux for move in res: - SOLDEINIT = "SELECT sum(l.debit) AS sum_debit, sum(l.credit) AS sum_credit FROM account_move_line l WHERE l.account_id = " + str(move.id) + " AND l.date < '" + self.borne_date['max_date'] + "'" + " AND l.date > '" + self.borne_date['min_date'] + "'" - self.cr.execute(SOLDEINIT) + self.cr.execute("""SELECT sum(l.debit) AS sum_debit, sum(l.credit) AS sum_credit FROM account_move_line l \ + WHERE l.account_id = %s AND l.date < %s AND l.date > %s""",(move.id,self.borne_date['max_date'],self.borne_date['min_date'])) resultat = self.cr.dictfetchall() if resultat[0] : if resultat[0]['sum_debit'] == None: @@ -284,7 +276,7 @@ class general_ledger(rml_parse.rml_parse): for l in res: line = self.pool.get('account.move.line').browse(self.cr, self.uid, l['id']) l['move'] = line.move_id.name - self.cr.execute('Select id from account_invoice where move_id =%s'%(line.move_id.id)) + self.cr.execute('Select id from account_invoice where move_id =%s',(line.move_id.id,)) tmpres = self.cr.dictfetchall() if len(tmpres) > 0 : inv = self.pool.get('account.invoice').browse(self.cr, self.uid, tmpres[0]['id']) @@ -312,7 +304,7 @@ class general_ledger(rml_parse.rml_parse): self.cr.execute("SELECT sum(debit) "\ "FROM account_move_line l "\ - "WHERE l.account_id = %s AND %s "%(account.id, self.query)) + "WHERE l.account_id = %s AND "+self.query,(account.id,)) ## Add solde init to the result # sum_debit = self.cr.fetchone()[0] or 0.0 @@ -326,7 +318,7 @@ class general_ledger(rml_parse.rml_parse): self.cr.execute("SELECT sum(credit) "\ "FROM account_move_line l "\ - "WHERE l.account_id = %s AND %s "%(account.id,self.query)) + "WHERE l.account_id = %s AND "+ self.query,(account.id,)) ## Add solde init to the result # sum_credit = self.cr.fetchone()[0] or 0.0 @@ -340,7 +332,7 @@ class general_ledger(rml_parse.rml_parse): def _sum_solde_account(self, account, form): self.cr.execute("SELECT (sum(debit) - sum(credit)) as tot_solde "\ "FROM account_move_line l "\ - "WHERE l.account_id = %s AND %s"%(account.id,self.query)) + "WHERE l.account_id = %s AND "+ self.query,(account.id,)) sum_solde = self.cr.fetchone()[0] or 0.0 if form.get('soldeinit', False): sum_solde += account.init_debit - account.init_credit @@ -352,7 +344,7 @@ class general_ledger(rml_parse.rml_parse): return 0.0 self.cr.execute("SELECT sum(debit) "\ "FROM account_move_line l "\ - "WHERE l.account_id in ("+','.join(map(str, self.child_ids))+") AND "+self.query) + "WHERE l.account_id =ANY(%s) AND "+ self.query,(self.child_ids,)) sum_debit = self.cr.fetchone()[0] or 0.0 return sum_debit @@ -361,7 +353,7 @@ class general_ledger(rml_parse.rml_parse): return 0.0 self.cr.execute("SELECT sum(credit) "\ "FROM account_move_line l "\ - "WHERE l.account_id in ("+','.join(map(str, self.child_ids))+") AND "+self.query) + "WHERE l.account_id =ANY(%s) AND "+ self.query,(self.child_ids,)) ## Add solde init to the result # sum_credit = self.cr.fetchone()[0] or 0.0 @@ -372,14 +364,14 @@ class general_ledger(rml_parse.rml_parse): return 0.0 self.cr.execute("SELECT (sum(debit) - sum(credit)) as tot_solde "\ "FROM account_move_line l "\ - "WHERE l.account_id in ("+','.join(map(str, self.child_ids))+") AND "+self.query) + "WHERE l.account_id =ANY(%s) AND "+ self.query,(self.child_ids,)) sum_solde = self.cr.fetchone()[0] or 0.0 return sum_solde def _set_get_account_currency_code(self, account_id): self.cr.execute("SELECT c.code as code "\ "FROM res_currency c,account_account as ac "\ - "WHERE ac.id = %s AND ac.currency_id = c.id"%(account_id)) + "WHERE ac.id = %s AND ac.currency_id = c.id",(account_id,)) result = self.cr.fetchone() if result: self.account_currency = result[0] diff --git a/addons/account/report/general_ledger_landscape.py b/addons/account/report/general_ledger_landscape.py index c1f9a374145..c0d48ad6e0e 100644 --- a/addons/account/report/general_ledger_landscape.py +++ b/addons/account/report/general_ledger_landscape.py @@ -22,7 +22,7 @@ # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # ############################################################################## @@ -83,14 +83,14 @@ class general_ledger_landscape(rml_parse.rml_parse): # # result[account_line.id] = ' ' - num_id_move = str(account_line.move_id.id) - num_id_line = str(account_line.id) - account_id = str(account_line.account_id.id) + num_id_move = account_line.move_id.id + num_id_line = account_line.id + account_id = account_line.account_id.id # search the basic account # We have the account ID we will search all account move line from now until this time # We are in the case of we are on the top of the account move Line cr.execute('SELECT distinct(ac.code) as code_rest,ac.name as name_rest from account_account AS ac, account_move_line mv\ - where ac.id = mv.account_id and mv.move_id = ' + num_id_move +' and mv.account_id <> ' + account_id ) + where ac.id = mv.account_id and mv.move_id = %s and mv.account_id <> %s' , (num_id_move,account_id,)) res_mv = cr.dictfetchall() # we need a result more than 2 line to make the test so we will made the the on 1 because we have exclude the current line if (len(res_mv) >=1): @@ -121,15 +121,12 @@ class general_ledger_landscape(rml_parse.rml_parse): ## This function will return the most aged date periods = form['periods'][0][2] if not periods: - sql = """ - Select min(p.date_start) as start_date,max(p.date_stop) as stop_date from account_period as p where p.fiscalyear_id = """ + str(form['fiscalyear']) + """ - """ + self.cr.execute(""" + Select min(p.date_start) as start_date,max(p.date_stop) as stop_date from account_period as p where p.fiscalyear_id = %s""" ,(form['fiscalyear'],)) else: - periods_id = ','.join(map(str, periods)) - sql = """ - Select min(p.date_start) as start_date,max(p.date_stop) as stop_date from account_period as p where p.id in ( """ + periods_id + """) - """ - self.cr.execute(sql) + self.cr.execute(""" + Select min(p.date_start) as start_date,max(p.date_stop) as stop_date from account_period as p where p.id =ANY(%s)""",(periods,)) + res = self.cr.dictfetchall() borne_min = res[0]['start_date'] borne_max = res[0]['stop_date'] @@ -139,15 +136,12 @@ class general_ledger_landscape(rml_parse.rml_parse): elif form['state'] == 'all': periods = form['periods'][0][2] if not periods: - sql = """ - Select min(p.date_start) as start_date,max(p.date_stop) as stop_date from account_period as p where p.fiscalyear_id = """ + str(form['fiscalyear']) + """ - """ + self.cr.execute(""" + Select min(p.date_start) as start_date,max(p.date_stop) as stop_date from account_period as p where p.fiscalyear_id = = %s""" ,(form['fiscalyear'],)) + else: - periods_id = ','.join(map(str, periods)) - sql = """ - Select min(p.date_start) as start_date,max(p.date_stop) as stop_date from account_period as p where p.id in ( """ + periods_id + """) - """ - self.cr.execute(sql) + self.cr.execute(""" + Select min(p.date_start) as start_date,max(p.date_stop) as stop_date from account_period as p where p.id =ANY(%s)""",(periods,)) res = self.cr.dictfetchall() period_min = res[0]['start_date'] period_max = res[0]['stop_date'] @@ -178,8 +172,6 @@ class general_ledger_landscape(rml_parse.rml_parse): def get_children_accounts(self, account, form): - - print self.ids self.child_ids = self.pool.get('account.account').search(self.cr, self.uid, [('parent_id', 'child_of', self.ids)]) # @@ -233,8 +225,8 @@ class general_ledger_landscape(rml_parse.rml_parse): else: ## We will now compute solde initiaux for move in res: - SOLDEINIT = "SELECT sum(l.debit) AS sum_debit, sum(l.credit) AS sum_credit FROM account_move_line l WHERE l.account_id = " + str(move.id) + " AND l.date < '" + self.borne_date['max_date'] + "'" + " AND l.date > '" + self.borne_date['min_date'] + "'" - self.cr.execute(SOLDEINIT) + self.cr.execute("""SELECT sum(l.debit) AS sum_debit, sum(l.credit) AS sum_credit FROM account_move_line l \ + WHERE l.account_id = %s AND l.date < %s AND l.date > %s""",(move.id,self.borne_date['max_date'],self.borne_date['min_date'])) resultat = self.cr.dictfetchall() if resultat[0] : if resultat[0]['sum_debit'] == None: @@ -287,7 +279,7 @@ class general_ledger_landscape(rml_parse.rml_parse): for l in res: line = self.pool.get('account.move.line').browse(self.cr, self.uid, l['id']) l['move'] = line.move_id.name - self.cr.execute('Select id from account_invoice where move_id =%s'%(line.move_id.id)) + self.cr.execute('Select id from account_invoice where move_id =%s',(line.move_id.id,)) tmpres = self.cr.dictfetchall() if len(tmpres) > 0 : inv = self.pool.get('account.invoice').browse(self.cr, self.uid, tmpres[0]['id']) @@ -315,7 +307,7 @@ class general_ledger_landscape(rml_parse.rml_parse): self.cr.execute("SELECT sum(debit) "\ "FROM account_move_line l "\ - "WHERE l.account_id = %s AND %s "%(account.id, self.query)) + "WHERE l.account_id = %s AND "+self.query,(account.id,)) ## Add solde init to the result # sum_debit = self.cr.fetchone()[0] or 0.0 @@ -329,7 +321,7 @@ class general_ledger_landscape(rml_parse.rml_parse): self.cr.execute("SELECT sum(credit) "\ "FROM account_move_line l "\ - "WHERE l.account_id = %s AND %s "%(account.id,self.query)) + "WHERE l.account_id = %s AND "+self.query,(account.id,)) ## Add solde init to the result # sum_credit = self.cr.fetchone()[0] or 0.0 @@ -343,7 +335,7 @@ class general_ledger_landscape(rml_parse.rml_parse): def _sum_solde_account(self, account, form): self.cr.execute("SELECT (sum(debit) - sum(credit)) as tot_solde "\ "FROM account_move_line l "\ - "WHERE l.account_id = %s AND %s"%(account.id,self.query)) + "WHERE l.account_id = %s AND "+self.query,(account.id,)) sum_solde = self.cr.fetchone()[0] or 0.0 if form.get('soldeinit',False): sum_solde += account.init_debit - account.init_credit @@ -355,7 +347,7 @@ class general_ledger_landscape(rml_parse.rml_parse): return 0.0 self.cr.execute("SELECT sum(debit) "\ "FROM account_move_line l "\ - "WHERE l.account_id in ("+','.join(map(str, self.child_ids))+") AND "+self.query) + "WHERE l.account_id =ANY(%s) AND "+self.query,(self.child_ids,)) sum_debit = self.cr.fetchone()[0] or 0.0 return sum_debit @@ -364,7 +356,7 @@ class general_ledger_landscape(rml_parse.rml_parse): return 0.0 self.cr.execute("SELECT sum(credit) "\ "FROM account_move_line l "\ - "WHERE l.account_id in ("+','.join(map(str, self.child_ids))+") AND "+self.query) + "WHERE l.account_id =ANY(%s) AND "+self.query,(self.child_ids,)) ## Add solde init to the result # sum_credit = self.cr.fetchone()[0] or 0.0 @@ -375,14 +367,14 @@ class general_ledger_landscape(rml_parse.rml_parse): return 0.0 self.cr.execute("SELECT (sum(debit) - sum(credit)) as tot_solde "\ "FROM account_move_line l "\ - "WHERE l.account_id in ("+','.join(map(str, self.child_ids))+") AND "+self.query) + "WHERE l.account_id =ANY(%s) AND "+self.query,(self.child_ids,)) sum_solde = self.cr.fetchone()[0] or 0.0 return sum_solde def _set_get_account_currency_code(self, account_id): self.cr.execute("SELECT c.code as code "\ "FROM res_currency c,account_account as ac "\ - "WHERE ac.id = %s AND ac.currency_id = c.id"%(account_id)) + "WHERE ac.id = %s AND ac.currency_id = c.id",(account_id,)) result = self.cr.fetchone() if result: self.account_currency = result[0] diff --git a/addons/account/report/partner_balance.py b/addons/account/report/partner_balance.py index 2b52a0616f0..a5b746a0bde 100755 --- a/addons/account/report/partner_balance.py +++ b/addons/account/report/partner_balance.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). # @@ -15,7 +15,7 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. +# along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## @@ -166,27 +166,26 @@ class partner_balance(report_sxw.rml_parse): ## self.date_lst_string ='' if self.date_lst: - self.date_lst_string = '\'' + '\',\''.join(map(str, self.date_lst)) + '\'' - + self.date_lst_string = '\'' + '\',\''.join(map(str, self.date_lst)) + '\'' ## Compute Code account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line') # if (data['form']['result_selection'] == 'customer' ): - self.ACCOUNT_TYPE = "('receivable')" + self.ACCOUNT_TYPE = ['receivable'] elif (data['form']['result_selection'] == 'supplier'): - self.ACCOUNT_TYPE = "('payable')" + self.ACCOUNT_TYPE = ['payable'] else: - self.ACCOUNT_TYPE = "('payable','receivable')" + self.ACCOUNT_TYPE = ['payable','receivable'] # self.cr.execute("SELECT a.id " \ "FROM account_account a " \ "LEFT JOIN account_account_type t " \ "ON (a.type = t.code) " \ "WHERE a.company_id = %s " \ - "AND a.type IN " + self.ACCOUNT_TYPE + " " \ - "AND a.active", (data['form']['company_id'],)) - self.account_ids = ','.join([str(a) for (a,) in self.cr.fetchall()]) + "AND a.type =ANY(%s) "\ + "AND a.active", (data['form']['company_id'],self.ACCOUNT_TYPE,)) + self.account_ids = [a for (a,) in self.cr.fetchall()] super(partner_balance, self).set_context(objects, data, ids, report_type) @@ -214,11 +213,11 @@ class partner_balance(report_sxw.rml_parse): ") AS enlitige " \ "FROM account_move_line l LEFT JOIN res_partner p ON (l.partner_id=p.id) " \ "JOIN account_account ac ON (l.account_id = ac.id)" \ - "WHERE ac.type IN " + self.ACCOUNT_TYPE + " " \ + "WHERE ac.type =ANY(%s) " "AND l.date IN (" + self.date_lst_string + ") " \ - "AND ac.company_id = "+ str(data['form']['company_id']) +" " \ + "AND ac.company_id = %s" \ "GROUP BY p.id, p.ref, p.name,l.account_id,ac.name,ac.code " \ - "ORDER BY l.account_id,p.name") + "ORDER BY l.account_id,p.name",(self.ACCOUNT_TYPE,data['form']['company_id'],)) res = self.cr.dictfetchall() for r in res: full_account.append(r) @@ -355,8 +354,8 @@ class partner_balance(report_sxw.rml_parse): self.cr.execute( "SELECT sum(debit) " \ "FROM account_move_line AS l " \ - "WHERE l.account_id IN (" + self.account_ids + ") " \ - "AND l.date IN (" + self.date_lst_string + ") " ) + "WHERE l.account_id =ANY(%s)" \ + "AND l.date IN (" + self.date_lst_string + ")" ,(self.account_ids,)) temp_res = float(self.cr.fetchone()[0] or 0.0) result_tmp = result_tmp + temp_res @@ -373,8 +372,8 @@ class partner_balance(report_sxw.rml_parse): self.cr.execute( "SELECT sum(credit) " \ "FROM account_move_line AS l " \ - "WHERE l.account_id IN (" + self.account_ids + ") " \ - "AND l.date IN (" + self.date_lst_string + ") " ) + "WHERE l.account_id =ANY(%s)" \ + "AND l.date IN (" + self.date_lst_string + ")" ,(self.account_ids,)) temp_res = float(self.cr.fetchone()[0] or 0.0) result_tmp = result_tmp + temp_res @@ -390,9 +389,9 @@ class partner_balance(report_sxw.rml_parse): self.cr.execute( "SELECT sum(debit-credit) " \ "FROM account_move_line AS l " \ - "WHERE l.account_id IN (" + self.account_ids + ") " \ - "AND l.date IN (" + self.date_lst_string + ") " \ - "AND l.blocked=TRUE " ) + "WHERE l.account_id =ANY(%s)" \ + "AND l.date IN (" + self.date_lst_string + ")"\ + "AND l.blocked=TRUE " ,(self.account_ids,)) temp_res = float(self.cr.fetchone()[0] or 0.0) result_tmp = result_tmp + temp_res @@ -411,9 +410,9 @@ class partner_balance(report_sxw.rml_parse): "ELSE 0 " \ "END " \ "FROM account_move_line AS l " \ - "WHERE l.account_id IN (" + self.account_ids + ") " \ - "AND l.date IN (" + self.date_lst_string + ") " \ - "GROUP BY l.partner_id") + "WHERE l.account_id =ANY(%s)" \ + "AND l.date IN (" + self.date_lst_string + ")" \ + "GROUP BY l.partner_id",(self.account_ids,)) a = self.cr.fetchone()[0] if self.cr.fetchone() != None: @@ -438,9 +437,9 @@ class partner_balance(report_sxw.rml_parse): "ELSE 0 " \ "END " \ "FROM account_move_line AS l " \ - "WHERE l.account_id IN (" + self.account_ids + ") " \ - "AND l.date IN (" + self.date_lst_string + ") " \ - "GROUP BY l.partner_id") + "WHERE l.account_id =ANY(%s)" \ + "AND l.date IN (" + self.date_lst_string + ")" \ + "GROUP BY l.partner_id",(self.account_ids,)) a = self.cr.fetchone()[0] or 0.0 if self.cr.fetchone() != None: diff --git a/addons/account/report/tax_report.py b/addons/account/report/tax_report.py index ccc62a53de0..3910622ad68 100644 --- a/addons/account/report/tax_report.py +++ b/addons/account/report/tax_report.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). # @@ -15,7 +15,7 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. +# along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## @@ -41,25 +41,25 @@ class tax_report(rml_parse.rml_parse): 'get_lines' : self._get_lines, }) - + def _get_lines(self, based_on,period_list,company_id=False, parent=False, level=0): res = self._get_codes(based_on,company_id,parent,level,period_list) - + if period_list[0][2] : res = self._add_codes(based_on,res,period_list) else : self.cr.execute ("select id from account_fiscalyear") fy = self.cr.fetchall() - self.cr.execute ("select id from account_period where fiscalyear_id = %d"%(fy[0][0])) + self.cr.execute ("select id from account_period where fiscalyear_id = %s",(fy[0][0],)) periods = self.cr.fetchall() for p in periods : period_list[0][2].append(p[0]) res = self._add_codes(based_on,res,period_list) - + i = 0 top_result = [] while i < len(res): - + res_dict = { 'code' : res[i][1].code, 'name' : res[i][1].name, 'debit' : 0, @@ -69,7 +69,7 @@ class tax_report(rml_parse.rml_parse): 'level' : res[i][0], 'pos' : 0 } - + top_result.append(res_dict) res_general = self._get_general(res[i][1].id,period_list,company_id,based_on) ind_general = 0 @@ -89,7 +89,6 @@ class tax_report(rml_parse.rml_parse): def _get_general(self, tax_code_id,period_list ,company_id, based_on): res=[] - period_sql_list = ','.join(map(str, period_list[0][2])) if based_on == 'payments': self.cr.execute('SELECT SUM(line.tax_amount) AS tax_amount, \ SUM(line.debit) AS debit, \ @@ -108,11 +107,11 @@ class tax_report(rml_parse.rml_parse): AND line.account_id = account.id \ AND account.company_id = %s \ AND move.id = line.move_id \ - AND line.period_id IN ('+ period_sql_list +') \ + AND line.period_id =ANY(%s) \ AND ((invoice.state = %s) \ OR (invoice.id IS NULL)) \ GROUP BY account.id,account.name,account.code', ('draft',tax_code_id, - company_id, 'paid')) + company_id, period_list[0][2],'paid',)) else : self.cr.execute('SELECT SUM(line.tax_amount) AS tax_amount, \ @@ -128,14 +127,14 @@ class tax_report(rml_parse.rml_parse): AND line.tax_code_id = %s \ AND line.account_id = account.id \ AND account.company_id = %s \ - AND line.period_id IN ('+ period_sql_list +') \ + AND line.period_id =ANY(%s)\ AND account.active \ GROUP BY account.id,account.name,account.code', ('draft',tax_code_id, - company_id)) + company_id,period_list[0][2],)) res = self.cr.dictfetchall() - + #AND line.period_id IN ('+ period_sql_list +') \ - + i = 0 while i<len(res): res[i]['account'] = self.pool.get('account.account').browse(self.cr, self.uid, res[i]['account_id']) @@ -145,14 +144,14 @@ class tax_report(rml_parse.rml_parse): def _get_codes(self,based_on, company_id, parent=False, level=0,period_list=[]): tc = self.pool.get('account.tax.code') ids = tc.search(self.cr, self.uid, [('parent_id','=',parent),('company_id','=',company_id)]) - + res = [] for code in tc.browse(self.cr, self.uid, ids, {'based_on': based_on}): res.append(('.'*2*level,code)) - + res += self._get_codes(based_on, company_id, code.id, level+1) return res - + def _add_codes(self,based_on, account_list=[],period_list=[]): res = [] for account in account_list: @@ -162,19 +161,19 @@ class tax_report(rml_parse.rml_parse): for period_ind in period_list[0][2]: for code in tc.browse(self.cr, self.uid, ids, {'period_id':period_ind,'based_on': based_on}): sum_tax_add = sum_tax_add + code.sum_period - + code.sum_period = sum_tax_add - + res.append((account[0],code)) return res - + def _get_company(self, form): return pooler.get_pool(self.cr.dbname).get('res.company').browse(self.cr, self.uid, form['company_id']).name def _get_currency(self, form): return pooler.get_pool(self.cr.dbname).get('res.company').browse(self.cr, self.uid, form['company_id']).currency_id.name - + def sort_result(self,accounts): # On boucle sur notre rapport result_accounts = [] @@ -184,13 +183,13 @@ class tax_report(rml_parse.rml_parse): # account_elem = accounts[ind] # - + # # we will now check if the level is lower than the previous level, in this case we will make a subtotal if (account_elem['level'] < old_level): bcl_current_level = old_level bcl_rup_ind = ind - 1 - + while (bcl_current_level >= int(accounts[bcl_rup_ind]['level']) and bcl_rup_ind >= 0 ): tot_elem = copy.copy(accounts[bcl_rup_ind]) res_tot = { 'code' : accounts[bcl_rup_ind]['code'], @@ -202,21 +201,21 @@ class tax_report(rml_parse.rml_parse): 'level' : 0, 'pos' : 0 } - + if res_tot['type'] == 1: # on change le type pour afficher le total res_tot['type'] = 2 result_accounts.append(res_tot) bcl_current_level = accounts[bcl_rup_ind]['level'] bcl_rup_ind -= 1 - + old_level = account_elem['level'] result_accounts.append(account_elem) ind+=1 - - + + return result_accounts - + report_sxw.report_sxw('report.account.vat.declaration', 'account.tax.code', 'addons/account/report/tax_report.rml', parser=tax_report, header=False) diff --git a/addons/account/report/third_party_ledger.py b/addons/account/report/third_party_ledger.py index affd7881218..0ae5bf8ce1a 100644 --- a/addons/account/report/third_party_ledger.py +++ b/addons/account/report/third_party_ledger.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). # @@ -15,7 +15,7 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. +# along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## @@ -142,7 +142,8 @@ class third_party_ledger(rml_parse.rml_parse): if (data['model'] == 'res.partner'): ## Si on imprime depuis les partenaires if ids: - PARTNER_REQUEST = "AND line.partner_id IN (" + ','.join(map(str, ids)) + ")" + #PARTNER_REQUEST = "AND line.partner_id IN (" + ','.join(map(str, ids)) + ")" + PARTNER_REQUEST = "AND line.partner_id =ANY(%s)" %ids # Transformation des date # # @@ -166,11 +167,11 @@ class third_party_ledger(rml_parse.rml_parse): # #new_ids = [id for (id,) in self.cr.fetchall()] if data['form']['result_selection'] == 'supplier': - self.ACCOUNT_TYPE = "('receivable')" + self.ACCOUNT_TYPE = ['receivable'] elif data['form']['result_selection'] == 'customer': - self.ACCOUNT_TYPE = "('payable')" + self.ACCOUNT_TYPE = ['payable'] elif data['form']['result_selection'] == 'all': - self.ACCOUNT_TYPE = "('payable','receivable')" + self.ACCOUNT_TYPE = ['payable','receivable'] self.cr.execute( "SELECT a.id " \ @@ -178,9 +179,9 @@ class third_party_ledger(rml_parse.rml_parse): "LEFT JOIN account_account_type t " \ "ON (a.type=t.code) " \ "WHERE a.company_id = %s " \ - 'AND a.type IN ' + self.ACCOUNT_TYPE + " " \ - "AND a.active", (data['form']['company_id'],)) - self.account_ids = ','.join([str(a) for (a,) in self.cr.fetchall()]) + 'AND a.type =ANY(%s)' \ + "AND a.active", (data['form']['company_id'],self.ACCOUNT_TYPE,)) + self.account_ids = [a for (a,) in self.cr.fetchall()] account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line') partner_to_use = [] @@ -195,11 +196,11 @@ class third_party_ledger(rml_parse.rml_parse): "AND line.date >= %s " \ "AND line.date <= %s " \ "AND line.reconcile_id IS NULL " \ - "AND line.account_id IN (" + self.account_ids + ") " \ + "AND line.account_id =ANY(%s)" \ " " + PARTNER_REQUEST + " " \ "AND account.company_id = %s " \ "AND account.active " , - (self.date_lst[0],self.date_lst[len(self.date_lst)-1],data['form']['company_id'])) + (self.date_lst[0],self.date_lst[len(self.date_lst)-1],self.account_ids,data['form']['company_id'],)) # else: # # self.cr.execute( @@ -220,7 +221,8 @@ class third_party_ledger(rml_parse.rml_parse): partner_to_use.append(res_line['partner_id']) new_ids = partner_to_use - self.partner_ids = ','.join(map(str, new_ids)) + #self.partner_ids = ','.join(map(str, new_ids)) + self.partner_ids = new_ids objects = self.pool.get('res.partner').browse(self.cr, self.uid, new_ids) super(third_party_ledger, self).set_context(objects, data, new_ids, report_type) @@ -259,11 +261,11 @@ class third_party_ledger(rml_parse.rml_parse): "LEFT JOIN account_journal j " \ "ON (l.journal_id = j.id) " \ "WHERE l.partner_id = %s " \ - "AND l.account_id IN (" + self.account_ids + ") " \ - "AND l.date IN (" + self.date_lst_string + ") " \ + "AND l.account_id =ANY(%s)"\ + "AND l.date IN (" + self.date_lst_string + ")" " " + RECONCILE_TAG + " "\ "ORDER BY l.id", - (partner.id,)) + (partner.id,self.account_ids,)) res = self.cr.dictfetchall() sum = 0.0 for r in res: @@ -286,10 +288,10 @@ class third_party_ledger(rml_parse.rml_parse): "SELECT sum(debit) " \ "FROM account_move_line " \ "WHERE partner_id = %s " \ - "AND account_id IN (" + self.account_ids + ") " \ + "AND account_id =ANY(%s)" \ "AND reconcile_id IS NULL " \ "AND date < %s " , - (partner.id, self.date_lst[0],)) + (partner.id, self.account_ids,self.date_lst[0],)) contemp = self.cr.fetchone() if contemp != None: result_tmp = contemp[0] or 0.0 @@ -301,10 +303,10 @@ class third_party_ledger(rml_parse.rml_parse): "SELECT sum(debit) " \ "FROM account_move_line " \ "WHERE partner_id = %s " \ - "AND account_id IN (" + self.account_ids + ") " \ + "AND account_id =ANY(%s)" \ " " + RECONCILE_TAG + " " \ - "AND date IN (" + self.date_lst_string + ") " , - (partner.id,)) + "AND date IN (" + self.date_lst_string + ")" , + (partner.id,self.account_ids,)) contemp = self.cr.fetchone() if contemp != None: @@ -325,10 +327,10 @@ class third_party_ledger(rml_parse.rml_parse): "SELECT sum(credit) " \ "FROM account_move_line " \ "WHERE partner_id=%s " \ - "AND account_id IN (" + self.account_ids + ") " \ + "AND account_id =ANY(%s)" \ "AND reconcile_id IS NULL " \ "AND date < %s " , - (partner.id,self.date_lst[0],)) + (partner.id,self.account_ids,self.date_lst[0],)) contemp = self.cr.fetchone() if contemp != None: result_tmp = contemp[0] or 0.0 @@ -340,10 +342,10 @@ class third_party_ledger(rml_parse.rml_parse): "SELECT sum(credit) " \ "FROM account_move_line " \ "WHERE partner_id=%s " \ - "AND account_id IN (" + self.account_ids + ") " \ + "AND account_id =ANY(%s)" \ " " + RECONCILE_TAG + " " \ - "AND date IN (" + self.date_lst_string + ") " , - (partner.id,)) + "AND date IN (" + self.date_lst_string + ")", + (partner.id,self.account_ids,)) contemp = self.cr.fetchone() if contemp != None: @@ -365,11 +367,11 @@ class third_party_ledger(rml_parse.rml_parse): self.cr.execute( "SELECT sum(debit) " \ "FROM account_move_line " \ - "WHERE partner_id IN (" + self.partner_ids + ") " \ - "AND account_id IN (" + self.account_ids + ") " \ + "WHERE partner_id =ANY(%s)" \ + "AND account_id =ANY(%s)" \ "AND reconcile_id IS NULL " \ "AND date < %s " , - (self.date_lst[0],)) + (self.partner_ids,self.account_ids,self.date_lst[0],)) contemp = self.cr.fetchone() if contemp != None: result_tmp = contemp[0] or 0.0 @@ -380,12 +382,10 @@ class third_party_ledger(rml_parse.rml_parse): self.cr.execute( "SELECT sum(debit) " \ "FROM account_move_line " \ - "WHERE partner_id IN (" + self.partner_ids + ") " \ - "AND account_id IN (" + self.account_ids + ") " \ + "WHERE partner_id =ANY(%s)" \ + "AND account_id =ANY(%s)" \ " " + RECONCILE_TAG + " " \ - "AND date IN (" + self.date_lst_string + ") " - ) - + "AND date IN (" + self.date_lst_string + ")",(self.partner_ids,self.account_ids,)) contemp = self.cr.fetchone() if contemp != None: result_tmp = contemp[0] or 0.0 @@ -408,11 +408,11 @@ class third_party_ledger(rml_parse.rml_parse): self.cr.execute( "SELECT sum(credit) " \ "FROM account_move_line " \ - "WHERE partner_id IN (" + self.partner_ids + ") " \ - "AND account_id IN (" + self.account_ids + ") " \ + "WHERE partner_id =ANY(%s)" \ + "AND account_id =ANY(%s)" \ "AND reconcile_id IS NULL " \ "AND date < %s " , - (self.date_lst[0],)) + (self.partner_ids,self.account_ids,self.date_lst[0],)) contemp = self.cr.fetchone() if contemp != None: result_tmp = contemp[0] or 0.0 @@ -423,11 +423,10 @@ class third_party_ledger(rml_parse.rml_parse): self.cr.execute( "SELECT sum(credit) " \ "FROM account_move_line " \ - "WHERE partner_id IN (" + self.partner_ids + ") " \ - "AND account_id IN (" + self.account_ids + ") " \ + "WHERE partner_id =ANY(%s)" \ + "AND account_id =ANY(%s)" \ " " + RECONCILE_TAG + " " \ - "AND date IN (" + self.date_lst_string + ") " - ) + "AND date IN (" + self.date_lst_string + ")",(self.partner_ids,self.account_ids,)) contemp = self.cr.fetchone() if contemp != None: result_tmp = contemp[0] or 0.0 diff --git a/addons/account/wizard/wizard_account_balance_report.py b/addons/account/wizard/wizard_account_balance_report.py index 62485a9f21a..26538d06b4b 100644 --- a/addons/account/wizard/wizard_account_balance_report.py +++ b/addons/account/wizard/wizard_account_balance_report.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). # @@ -15,7 +15,7 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. +# along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## @@ -102,7 +102,7 @@ class wizard_report(wizard.interface): # else : # data['form']['fiscalyear'] = 1 return data['form'] - + def _check_path(self, cr, uid, data, context): if data['model'] == 'account.account': return 'checktype' @@ -111,8 +111,8 @@ class wizard_report(wizard.interface): def _check_date(self, cr, uid, data, context): sql = """ - SELECT f.id, f.date_start, f.date_stop FROM account_fiscalyear f Where '%s' between f.date_start and f.date_stop """%(data['form']['date_from']) - cr.execute(sql) + SELECT f.id, f.date_start, f.date_stop FROM account_fiscalyear f Where %s between f.date_start and f.date_stop """ + cr.execute(sql,(data['form']['date_from'],)) res = cr.dictfetchall() if res: if (data['form']['date_to'] > res[0]['date_stop'] or data['form']['date_to'] < res[0]['date_start']): diff --git a/addons/account/wizard/wizard_fiscalyear_close.py b/addons/account/wizard/wizard_fiscalyear_close.py index 7e48f7c496c..42e35276802 100644 --- a/addons/account/wizard/wizard_fiscalyear_close.py +++ b/addons/account/wizard/wizard_fiscalyear_close.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). # @@ -15,7 +15,7 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. +# along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## @@ -56,14 +56,12 @@ def _data_save(self, cr, uid, data, context): fy_id = data['form']['fy_id'] period_ids = pool.get('account.period').search(cr, uid, [('fiscalyear_id', '=', fy_id)]) - fy_period_set = ','.join(map(str, period_ids)) periods_fy2 = pool.get('account.period').search(cr, uid, [('fiscalyear_id', '=', data['form']['fy2_id'])]) - fy2_period_set = ','.join(map(str, periods_fy2)) period = pool.get('account.period').browse(cr, uid, data['form']['period_id'], context=context) new_fyear = pool.get('account.fiscalyear').browse(cr, uid, data['form']['fy2_id'], context=context) old_fyear = pool.get('account.fiscalyear').browse(cr, uid, data['form']['fy_id'], context=context) - + new_journal = data['form']['journal_id'] new_journal = pool.get('account.journal').browse(cr, uid, new_journal, context=context) @@ -89,7 +87,7 @@ def _data_save(self, cr, uid, data, context): ids = map(lambda x: x[0], cr.fetchall()) for account in pool.get('account.account').browse(cr, uid, ids, context={'fiscalyear': fy_id}): - + accnt_type_data = account.user_type if not accnt_type_data: continue @@ -135,7 +133,7 @@ def _data_save(self, cr, uid, data, context): }) offset += limit - #We have also to consider all move_lines that were reconciled + #We have also to consider all move_lines that were reconciled #on another fiscal year, and report them too offset = 0 limit = 100 @@ -149,10 +147,10 @@ def _data_save(self, cr, uid, data, context): 'WHERE b.account_id = %s ' \ 'AND b.reconcile_id is NOT NULL ' \ 'AND a.reconcile_id = b.reconcile_id ' \ - 'AND b.period_id IN ('+fy_period_set+') ' \ - 'AND a.period_id IN ('+fy2_period_set+') ' \ + 'AND b.period_id =ANY(%s)'\ + 'AND a.period_id =ANY(%s)' \ 'ORDER BY id ' \ - 'LIMIT %s OFFSET %s', (account.id, limit, offset)) + 'LIMIT %s OFFSET %s', (account.id,period_ids,periods_fy2,limit, offset)) result = cr.dictfetchall() if not result: break @@ -180,7 +178,7 @@ def _data_save(self, cr, uid, data, context): 'AND ' + query_line + ' ' \ 'ORDER BY id ' \ 'LIMIT %s OFFSET %s', (account.id, limit, offset)) - + result = cr.dictfetchall() if not result: break @@ -210,7 +208,6 @@ def _data_save(self, cr, uid, data, context): cr.execute('UPDATE account_fiscalyear ' \ 'SET end_journal_period_id = %s ' \ 'WHERE id = %s', (ids[0], old_fyear.id)) - return {} class wiz_journal_close(wizard.interface): diff --git a/addons/account/wizard/wizard_general_ledger_report.py b/addons/account/wizard/wizard_general_ledger_report.py index ac8df1e1142..d5f8ac0fa98 100644 --- a/addons/account/wizard/wizard_general_ledger_report.py +++ b/addons/account/wizard/wizard_general_ledger_report.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). # @@ -15,7 +15,7 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. +# along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## @@ -46,7 +46,7 @@ period_form = '''<?xml version="1.0"?> <field name="sortbydate" required="True"/> <field name="soldeinit" invisible="1"/> - + <field name="landscape"/> <field name="amount_currency"/> <newline/> @@ -65,10 +65,10 @@ period_form = '''<?xml version="1.0"?> </group> </group> - - - - + + + + </form>''' period_fields = { @@ -103,10 +103,10 @@ def _check(self, cr, uid, data, context): return 'report' def _check_date(self, cr, uid, data, context): - + sql = """ - SELECT f.id, f.date_start, f.date_stop FROM account_fiscalyear f Where '%s' between f.date_start and f.date_stop """%(data['form']['date_from']) - cr.execute(sql) + SELECT f.id, f.date_start, f.date_stop FROM account_fiscalyear f Where %s between f.date_start and f.date_stop """ + cr.execute(sql,(data['form']['date_from'],)) res = cr.dictfetchall() if res: if (data['form']['date_to'] > res[0]['date_stop'] or data['form']['date_to'] < res[0]['date_start']): @@ -116,14 +116,14 @@ def _check_date(self, cr, uid, data, context): else: raise wizard.except_wizard(_('UserError'),_('Date not in a defined fiscal year')) - + def _check_state(self, cr, uid, data, context): if data['form']['state'] == 'bydate': _check_date(self, cr, uid, data, context) # data['form']['fiscalyear'] = 0 # else : -# +# # data['form']['fiscalyear'] = 1 return data['form'] @@ -137,7 +137,7 @@ class wizard_report(wizard.interface): company_id = pooler.get_pool(cr.dbname).get('res.company').search(cr, uid, [('parent_id', '=', False)])[0] data['form']['company_id'] = company_id fiscalyear_obj = pooler.get_pool(cr.dbname).get('account.fiscalyear') - + data['form']['fiscalyear'] = fiscalyear_obj.find(cr, uid) #periods_obj=pooler.get_pool(cr.dbname).get('account.period') #data['form']['periods'] =periods_obj.search(cr, uid, [('fiscalyear_id','=',data['form']['fiscalyear'])]) diff --git a/addons/account/wizard/wizard_open_closed_fiscalyear.py b/addons/account/wizard/wizard_open_closed_fiscalyear.py index f3c434b5f2d..cbc46316484 100644 --- a/addons/account/wizard/wizard_open_closed_fiscalyear.py +++ b/addons/account/wizard/wizard_open_closed_fiscalyear.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). # @@ -15,7 +15,7 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. +# along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## @@ -43,7 +43,7 @@ def _remove_entries(self, cr, uid, data, context): period_journal = data_fyear.end_journal_period_id ids_move = pool.get('account.move').search(cr,uid,[('journal_id','=',period_journal.journal_id.id),('period_id','=',period_journal.period_id.id)]) if ids_move: - cr.execute('delete from account_move where id in ('+','.join(map(str, ids_move))+')') + cr.execute('delete from account_move where id =ANY(%s)',(ids_move,)) #cr.execute('UPDATE account_journal_period ' \ # 'SET state = %s ' \ # 'WHERE period_id IN (SELECT id FROM account_period WHERE fiscalyear_id = %s)', @@ -60,17 +60,17 @@ class open_closed_fiscal(wizard.interface): 'init' : { 'actions' : [], 'result': { - 'type': 'form', + 'type': 'form', 'arch': form, - 'fields': fields, + 'fields': fields, 'state':[('end','Cancel'),('open','Open')] } }, 'open': { 'actions': [], 'result': { - 'type':'action', - 'action':_remove_entries, + 'type':'action', + 'action':_remove_entries, 'state':'end' }, }, diff --git a/addons/account/wizard/wizard_partner_balance_report.py b/addons/account/wizard/wizard_partner_balance_report.py index 142aeeb682c..f7b049a4f0f 100644 --- a/addons/account/wizard/wizard_partner_balance_report.py +++ b/addons/account/wizard/wizard_partner_balance_report.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). # @@ -15,7 +15,7 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. +# along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## @@ -74,14 +74,14 @@ period_fields = { } class wizard_report(wizard.interface): - + def _get_defaults(self,cr,uid,data,context): user = pooler.get_pool(cr.dbname).get('res.users').browse(cr, uid, uid, context=context) if user.company_id: company_id = user.company_id.id else: company_id = pooler.get_pool(cr.dbname).get('res.company').search(cr, uid, [('parent_id', '=', False)])[0] - + fiscalyear_obj = pooler.get_pool(cr.dbname).get('account.fiscalyear') periods_obj=pooler.get_pool(cr.dbname).get('account.period') data['form']['fiscalyear'] = fiscalyear_obj.find(cr, uid) @@ -91,25 +91,24 @@ class wizard_report(wizard.interface): data['form']['fiscalyear'] = False data['form']['result_selection'] = 'all' return data['form'] - + def _check_state(self, cr, uid, data, context): - + if data['form']['state'] == 'bydate' : self._check_date(cr, uid, data, context) return data['form'] - + def _check_date(self, cr, uid, data, context): - sql = """ - SELECT f.id, f.date_start, f.date_stop FROM account_fiscalyear f Where '%s' between f.date_start and f.date_stop """%(data['form']['date1']) - cr.execute(sql) + SELECT f.id, f.date_start, f.date_stop FROM account_fiscalyear f Where %s between f.date_start and f.date_stop """ + cr.execute(sql,(data['form']['date1'],)) res = cr.dictfetchall() if res: if (data['form']['date2'] > res[0]['date_stop'] or data['form']['date2'] < res[0]['date_start']): raise wizard.except_wizard(_('UserError'),_('Date to must be set between %s and %s') % (str(res[0]['date_start']), str(res[0]['date_stop']))) else: return 'report' - + else: raise wizard.except_wizard(_('UserError'),_('Date not in a defined fiscal year')) @@ -118,7 +117,7 @@ class wizard_report(wizard.interface): 'actions': [_get_defaults], 'result': {'type':'form', 'arch':period_form, 'fields':period_fields, 'state':[('end','Cancel','gtk-cancel'),('report','Print','gtk-print')]} }, - + 'report': { 'actions': [_check_state], 'result': {'type':'print', 'report':'account.partner.balance', 'state':'end'} diff --git a/addons/account/wizard/wizard_refund.py b/addons/account/wizard/wizard_refund.py index 2d603abe4a4..42526f3cc0a 100644 --- a/addons/account/wizard/wizard_refund.py +++ b/addons/account/wizard/wizard_refund.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). # @@ -15,7 +15,7 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. +# along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## @@ -80,17 +80,14 @@ class wiz_refund(wizard.interface): #in multi company mode cr.execute("""SELECT id from account_period where date('%s') - between date_start AND date_stop and company_id = %s limit 1 """%( - form['date'], - pool.get('res.users').browse(cr,uid,uid).company_id.id - )) + between date_start AND date_stop and company_id = %s limit 1 """, + (form['date'],pool.get('res.users').browse(cr,uid,uid).company_id.id,)) else: #in mono company mode cr.execute("""SELECT id from account_period where date('%s') - between date_start AND date_stop limit 1 """%( - form['date'], - )) + between date_start AND date_stop limit 1 """, + (form['date'],)) res = cr.fetchone() if res: period = res[0] @@ -101,10 +98,10 @@ class wiz_refund(wizard.interface): description = form['description'] else: description = inv.name - + if not period: raise wizard.except_wizard(_('Data Insufficient !'), _('No Period found on Invoice!')) - + refund_id = pool.get('account.invoice').refund(cr, uid, [inv.id],date, period, description) refund = pool.get('account.invoice').browse(cr, uid, refund_id[0]) # we compute due date @@ -112,7 +109,7 @@ class wiz_refund(wizard.interface): pool.get('account.invoice').write(cr, uid, [refund.id],{'date_due':date,'check_total':inv.check_total}) # to make the taxes calculated pool.get('account.invoice').button_compute(cr, uid, refund_id) - + created_inv.append(refund_id[0]) #if inv is paid we unreconcile if mode in ('cancel','modify'): diff --git a/addons/account/wizard/wizard_third_party_ledger.py b/addons/account/wizard/wizard_third_party_ledger.py index 43186f309c8..c89f87fd8e0 100755 --- a/addons/account/wizard/wizard_third_party_ledger.py +++ b/addons/account/wizard/wizard_third_party_ledger.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). # @@ -15,7 +15,7 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. +# along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## @@ -113,8 +113,8 @@ class wizard_report(wizard.interface): def _check_date(self, cr, uid, data, context): sql = """ - SELECT f.id, f.date_start, f.date_stop FROM account_fiscalyear f Where '%s' between f.date_start and f.date_stop """%(data['form']['date1']) - cr.execute(sql) + SELECT f.id, f.date_start, f.date_stop FROM account_fiscalyear f Where %s between f.date_start and f.date_stop """ + cr.execute(sql,(data['form']['date1'])) res = cr.dictfetchall() if res: if (data['form']['date2'] > res[0]['date_stop'] or data['form']['date2'] < res[0]['date_start']): diff --git a/addons/account_analytic_analysis/account_analytic_analysis.py b/addons/account_analytic_analysis/account_analytic_analysis.py index 241ad071af1..549d6aa06e1 100644 --- a/addons/account_analytic_analysis/account_analytic_analysis.py +++ b/addons/account_analytic_analysis/account_analytic_analysis.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). # @@ -15,14 +15,14 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. +# along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## import operator from osv import osv, fields from osv.orm import intersect -import tools.sql +import tools.sql from tools.translate import _ @@ -34,14 +34,13 @@ class account_analytic_account(osv.osv): res = {} ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)]) if ids2: - acc_set = ",".join(map(str, ids2)) cr.execute("select account_analytic_line.account_id, COALESCE(sum(amount),0.0) \ from account_analytic_line \ join account_analytic_journal \ on account_analytic_line.journal_id = account_analytic_journal.id \ - where account_analytic_line.account_id IN (%s) \ + where account_analytic_line.account_id =ANY(%s) \ and account_analytic_journal.type = 'sale' \ - group by account_analytic_line.account_id" % acc_set) + group by account_analytic_line.account_id" ,(ids2,)) for account_id, sum in cr.fetchall(): res[account_id] = round(sum,2) for obj_id in ids: @@ -60,7 +59,6 @@ class account_analytic_account(osv.osv): ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)]) if ids2: # Amount uninvoiced hours to invoice at sale price - acc_set = ",".join(map(str, ids2)) cr.execute("""SELECT account_analytic_account.id, \ COALESCE(sum (product_template.list_price * \ account_analytic_line.unit_amount * \ @@ -77,11 +75,11 @@ class account_analytic_account(osv.osv): on account_analytic_account.id = account_analytic_line.account_id \ JOIN hr_timesheet_invoice_factor \ on hr_timesheet_invoice_factor.id = account_analytic_account.to_invoice \ - WHERE account_analytic_account.id IN (%s) \ + WHERE account_analytic_account.id =ANY(%s) \ AND account_analytic_line.invoice_id is null \ AND account_analytic_line.to_invoice IS NOT NULL \ and account_analytic_journal.type in ('purchase','general') \ - GROUP BY account_analytic_account.id;"""%acc_set) + GROUP BY account_analytic_account.id;""",(ids2,)) for account_id, sum in cr.fetchall(): res[account_id] = round(sum,2) @@ -113,16 +111,15 @@ class account_analytic_account(osv.osv): res = {} ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)]) if ids2: - acc_set = ",".join(map(str, ids2)) cr.execute("select account_analytic_line.account_id, COALESCE(sum(unit_amount),0.0) \ from account_analytic_line \ join account_analytic_journal \ on account_analytic_line.journal_id = account_analytic_journal.id \ - where account_analytic_line.account_id IN (%s) \ + where account_analytic_line.account_id =ANY(%s) \ and account_analytic_journal.type='general' \ and invoice_id is null \ AND to_invoice IS NOT NULL \ - GROUP BY account_analytic_line.account_id;"%acc_set) + GROUP BY account_analytic_line.account_id;",(ids2,)) for account_id, sum in cr.fetchall(): res[account_id] = round(sum,2) for obj_id in ids: @@ -139,14 +136,13 @@ class account_analytic_account(osv.osv): res = {} ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)]) if ids2: - acc_set = ",".join(map(str, ids2)) cr.execute("select account_analytic_line.account_id,COALESCE(SUM(unit_amount),0.0) \ from account_analytic_line \ join account_analytic_journal \ on account_analytic_line.journal_id = account_analytic_journal.id \ - where account_analytic_line.account_id IN (%s) \ + where account_analytic_line.account_id =ANY(%s) \ and account_analytic_journal.type='general' \ - GROUP BY account_analytic_line.account_id"%acc_set) + GROUP BY account_analytic_line.account_id",(ids2,)) ff = cr.fetchall() for account_id, sum in ff: res[account_id] = round(sum,2) @@ -164,14 +160,13 @@ class account_analytic_account(osv.osv): res = {} ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)]) if ids2: - acc_set = ",".join(map(str, ids2)) cr.execute("""select account_analytic_line.account_id,COALESCE(sum(amount),0.0) \ from account_analytic_line \ join account_analytic_journal \ on account_analytic_line.journal_id = account_analytic_journal.id \ - where account_analytic_line.account_id IN (%s) \ + where account_analytic_line.account_id =ANY(%s) \ and amount<0 \ - GROUP BY account_analytic_line.account_id"""%acc_set) + GROUP BY account_analytic_line.account_id""",(ids2,)) for account_id, sum in cr.fetchall(): res[account_id] = round(sum,2) for obj_id in ids: @@ -189,7 +184,6 @@ class account_analytic_account(osv.osv): res2 = {} ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)]) if ids2: - acc_set = ",".join(map(str, ids2)) cr.execute("""select account_analytic_line.account_id as account_id, \ COALESCE(sum((account_analytic_line.unit_amount * pt.list_price) \ - (account_analytic_line.unit_amount * pt.list_price \ @@ -205,10 +199,10 @@ class account_analytic_account(osv.osv): on (a.id=account_analytic_line.account_id) \ join hr_timesheet_invoice_factor hr \ on (hr.id=a.to_invoice) \ - where account_analytic_line.account_id IN (%s) \ + where account_analytic_line.account_id =ANY(%s) \ and a.to_invoice IS NOT NULL \ and account_analytic_journal.type in ('purchase','general') - GROUP BY account_analytic_line.account_id"""%acc_set) + GROUP BY account_analytic_line.account_id""",(ids2,)) for account_id, sum in cr.fetchall(): res2[account_id] = round(sum,2) @@ -230,12 +224,11 @@ class account_analytic_account(osv.osv): res = {} ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)]) if ids2: - acc_set = ",".join(map(str, ids2)) cr.execute("select account_analytic_line.account_id, max(date) \ from account_analytic_line \ - where account_id IN (%s) \ + where account_id =ANY(%s) \ and invoice_id is null \ - GROUP BY account_analytic_line.account_id" % acc_set) + GROUP BY account_analytic_line.account_id" ,(ids2,)) for account_id, sum in cr.fetchall(): res[account_id] = sum for obj_id in ids: @@ -252,15 +245,14 @@ class account_analytic_account(osv.osv): res = {} ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)]) if ids2: - acc_set = ",".join(map(str, ids2)) cr.execute ("select account_analytic_line.account_id, \ date(max(account_invoice.date_invoice)) \ from account_analytic_line \ join account_invoice \ on account_analytic_line.invoice_id = account_invoice.id \ - where account_analytic_line.account_id IN (%s) \ + where account_analytic_line.account_id =ANY(%s) \ and account_analytic_line.invoice_id is not null \ - GROUP BY account_analytic_line.account_id"%acc_set) + GROUP BY account_analytic_line.account_id",(ids2,)) for account_id, sum in cr.fetchall(): res[account_id] = sum for obj_id in ids: @@ -277,12 +269,11 @@ class account_analytic_account(osv.osv): res = {} ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)]) if ids2: - acc_set = ",".join(map(str, ids2)) cr.execute("select account_analytic_line.account_id, max(date) \ from account_analytic_line \ - where account_id IN (%s) \ + where account_id =ANY(%s) \ and invoice_id is not null \ - GROUP BY account_analytic_line.account_id;"%acc_set) + GROUP BY account_analytic_line.account_id;",(ids2,)) for account_id, sum in cr.fetchall(): res[account_id] = sum for obj_id in ids: @@ -373,8 +364,7 @@ class account_analytic_account(osv.osv): ids2 = self.search(cr, uid, [('parent_id', 'child_of', [id])]) if ids2: cr.execute('SELECT DISTINCT(month_id) FROM account_analytic_analysis_summary_month ' \ - 'WHERE account_id in (' + ','.join([str(x) for x in ids2]) + ') ' \ - 'AND unit_amount <> 0.0') + 'WHERE account_id =ANY(%s) AND unit_amount <> 0.0',(ids2,)) res[id] = [int(id * 1000000 + int(x[0])) for x in cr.fetchall()] else: res[id] = [] @@ -388,11 +378,10 @@ class account_analytic_account(osv.osv): ids2 = self.search(cr, uid, [('parent_id', 'child_of', [id])]) if ids2: cr.execute('SELECT DISTINCT("user") FROM account_analytic_analysis_summary_user ' \ - 'WHERE account_id in (' + ','.join([str(x) for x in ids2]) + ') ' \ - 'AND unit_amount <> 0.0') + 'WHERE account_id =ANY(%s) AND unit_amount <> 0.0',(ids2,)) res[id] = [int((id * max_user) + x[0]) for x in cr.fetchall()] else: - res[id] = [] + res[id] = [] return res _columns ={ @@ -432,13 +421,11 @@ class account_analytic_account_summary_user(osv.osv): account_ids = [int(str(x/max_user - (x%max_user == 0 and 1 or 0))) for x in ids] user_ids = [int(str(x-((x/max_user - (x%max_user == 0 and 1 or 0)) *max_user))) for x in ids] account_ids2 = account_obj.search(cr, uid, [('parent_id', 'child_of', account_ids)]) - user_set = ','.join([str(x) for x in user_ids]) if account_ids2: - acc_set = ','.join([str(x) for x in account_ids2]) cr.execute('SELECT id, unit_amount ' \ 'FROM account_analytic_analysis_summary_user ' \ - 'WHERE account_id in (%s) ' \ - 'AND "user" in (%s) ' % (acc_set, user_set)) + 'WHERE account_id =ANY(%s) ' \ + 'AND "user" =ANY(%s)',(account_ids2, user_ids,)) for sum_id, unit_amount in cr.fetchall(): res[sum_id] = unit_amount for obj_id in ids: @@ -599,14 +586,11 @@ class account_analytic_account_summary_month(osv.osv): account_ids = [int(str(int(x))[:-6]) for x in ids] month_ids = [int(str(int(x))[-6:]) for x in ids] account_ids2 = account_obj.search(cr, uid, [('parent_id', 'child_of', account_ids)]) - month_set = ','.join([str(x) for x in month_ids]) if account_ids2: - acc_set = ','.join([str(x) for x in account_ids2]) cr.execute('SELECT id, unit_amount ' \ 'FROM account_analytic_analysis_summary_month ' \ - 'WHERE account_id in (%s) ' \ - 'AND month_id in (%s) ' % \ - (acc_set, month_set)) + 'WHERE account_id =ANY(%s) ' \ + 'AND month_id =ANY(%s) ',(account_ids2, month_ids,)) for sum_id, unit_amount in cr.fetchall(): res[sum_id] = unit_amount for obj_id in ids: diff --git a/addons/account_budget/crossovered_budget.py b/addons/account_budget/crossovered_budget.py index 6ac17d59863..0fdb10c89a6 100644 --- a/addons/account_budget/crossovered_budget.py +++ b/addons/account_budget/crossovered_budget.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). # @@ -15,7 +15,7 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. +# along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## @@ -51,7 +51,7 @@ class account_budget_post(osv.osv): 'sequence': lambda *a: 1, 'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'account.budget.post', context=c) } - _order = "sequence, name" + _order = "sequence, name" def spread(self, cr, uid, ids, fiscalyear_id=False, amount=0.0): dobj = self.pool.get('account.budget.post.dotation') @@ -76,8 +76,10 @@ class account_budget_post_dotation(osv.osv): total_days=strToDate(obj_period.date_stop) - strToDate(obj_period.date_start) budget_id=line.post_id and line.post_id.id or False - query="select id from crossovered_budget_lines where general_budget_id= '"+ str(budget_id) + "' AND (date_from >='" +obj_period.date_start +"' and date_from <= '"+obj_period.date_stop + "') OR (date_to >='" +obj_period.date_start +"' and date_to <= '"+obj_period.date_stop + "') OR (date_from <'" +obj_period.date_start +"' and date_to > '"+obj_period.date_stop + "')" - cr.execute(query) + query="select id from crossovered_budget_lines where \ + general_budget_id= %s AND (date_from >=%s and date_from <= %s ) \ + OR (date_to >=%s and date_to <= %s) OR (date_from < %s and date_to > %s)" + cr.execute(query,(budget_id,obj_period.date_start,obj_period.date_stop,obj_period.date_start,obj_period.date_stop,obj_period.date_start,obj_period.date_stop,)) res1=cr.fetchall() tot_planned=0.00 @@ -175,10 +177,9 @@ class crossovered_budget_lines(osv.osv): date_from = context['wizard_date_from'] if context.has_key('wizard_date_to'): date_to = context['wizard_date_to'] - - cr.execute("select sum(amount) from account_analytic_line where account_id=%%s and (date " - "between to_date(%%s,'yyyy-mm-dd') and to_date(%%s,'yyyy-mm-dd')) and " - "general_account_id in (%s)" % ",".join(map(str,acc_ids)), (line.analytic_account_id.id, date_from, date_to )) + cr.execute("select sum(amount) from account_analytic_line where account_id=%s and (date " + "between to_date(%s,'yyyy-mm-dd') and to_date(%s,'yyyy-mm-dd')) and " + "general_account_id=ANY(%s)", (line.analytic_account_id.id, date_from, date_to,acc_ids,)) result = cr.fetchone()[0] if result is None: result = 0.00 @@ -213,7 +214,7 @@ class crossovered_budget_lines(osv.osv): elapsed = min(strToDate(line.date_to),strToDate(date_to)) - max(strToDate(line.date_from),strToDate(date_from)) if strToDate(date_to) < strToDate(line.date_from): elapsed = strToDate(date_to) - strToDate(date_to) - + if total.days: theo_amt = float(elapsed.days/float(total.days))*line.planned_amount else: diff --git a/addons/account_budget/report/analytic_account_budget_report.py b/addons/account_budget/report/analytic_account_budget_report.py index 7be79fc64b5..07e8bb27d12 100644 --- a/addons/account_budget/report/analytic_account_budget_report.py +++ b/addons/account_budget/report/analytic_account_budget_report.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). # @@ -15,7 +15,7 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. +# along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## @@ -65,13 +65,11 @@ class analytic_account_budget_report(report_sxw.rml_parse): if not b_line_ids: return [] - bd_lines_ids = ','.join([str(x) for x in b_line_ids]) - d_from=form['date_from'] d_to=form['date_to'] # bd_ids = ','.join([str(x) for x in budget_lines]) - self.cr.execute('select distinct(crossovered_budget_id) from crossovered_budget_lines where id in (%s)'%(bd_lines_ids)) + self.cr.execute('select distinct(crossovered_budget_id) from crossovered_budget_lines where id =ANY(%s)',(b_line_ids,)) budget_ids=self.cr.fetchall() context={'wizard_date_from':d_from,'wizard_date_to':d_to} diff --git a/addons/account_budget/report/crossovered_budget_report.py b/addons/account_budget/report/crossovered_budget_report.py index c7a95585aa2..54be05e8d72 100644 --- a/addons/account_budget/report/crossovered_budget_report.py +++ b/addons/account_budget/report/crossovered_budget_report.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). # @@ -15,7 +15,7 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. +# along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## @@ -71,10 +71,8 @@ class budget_report(report_sxw.rml_parse): if not budget_ids: return [] - b_line_ids=','.join([str(x) for x in budget_ids]) - # bd_ids = ','.join([str(x) for x in budget_lines]) - self.cr.execute('select distinct(analytic_account_id) from crossovered_budget_lines where id in (%s)'%(b_line_ids)) + self.cr.execute('select distinct(analytic_account_id) from crossovered_budget_lines where id =ANY(%s)',(budget_ids,)) an_ids=self.cr.fetchall() context={'wizard_date_from':d_from,'wizard_date_to':d_to} diff --git a/addons/account_payment/account_move_line.py b/addons/account_payment/account_move_line.py index 0c7f61928c3..07fbcbbb237 100644 --- a/addons/account_payment/account_move_line.py +++ b/addons/account_payment/account_move_line.py @@ -42,7 +42,7 @@ class account_move_line(osv.osv): WHERE move_line_id = ml.id AND po.state != 'cancel') as amount FROM account_move_line ml - WHERE id in (%s)""" % (",".join(map(str,map(int, ids))))) + WHERE id =ANY(%s)""" ,(ids,)) r=dict(cr.fetchall()) return r diff --git a/addons/account_payment/payment.py b/addons/account_payment/payment.py index b52576f5be7..8f68bdaf46f 100644 --- a/addons/account_payment/payment.py +++ b/addons/account_payment/payment.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). # @@ -15,7 +15,7 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. +# along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## @@ -100,7 +100,7 @@ class payment_order(osv.osv): ('draft', 'Draft'), ('open','Confirmed'), ('cancel','Cancelled'), - ('done','Done')], 'State', select=True, + ('done','Done')], 'State', select=True, help='When an order is placed the state is \'Draft\'.\n Once the bank is confirmed the state is set to \'Confirmed\'.\n Then the order is paid the state is \'Done\'.'), 'line_ids': fields.one2many('payment.line','order_id','Payment lines',states={'done':[('readonly',True)]}), 'total': fields.function(_total, string="Total", method=True, @@ -225,8 +225,8 @@ class payment_line(osv.osv): from account_move_line ml inner join payment_line pl on (ml.id = pl.move_line_id) - where pl.id in (%s)"""% - (self.translate(name), ','.join(map(str, ids)))) + where pl.id =ANY(%s)""", + (self.translate(name),ids,)) res = dict(cr.fetchall()) if name == 'partner_id': diff --git a/addons/account_voucher/voucher.py b/addons/account_voucher/voucher.py index 0c6f605c0e2..1b1258b8630 100755 --- a/addons/account_voucher/voucher.py +++ b/addons/account_voucher/voucher.py @@ -406,7 +406,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 IN ('+','.join(map(str, ids))+')') + 'WHERE id =ANY(%s)',(ids,)) for (id, invtype, number, move_id, reference) in cr.fetchall(): if not number: number = self.pool.get('ir.sequence').get(cr, uid, invtype) @@ -417,13 +417,13 @@ class account_voucher(osv.osv): ref = self._convert_ref(cr, uid, number) cr.execute('UPDATE account_voucher SET number=%s ' \ - 'WHERE id=%d', (number, id)) + 'WHERE id=%s', (number, id)) cr.execute('UPDATE account_move_line SET ref=%s ' \ - 'WHERE move_id=%d AND (ref is null OR ref = \'\')', + 'WHERE move_id=%s AND (ref is null OR ref = \'\')', (ref, move_id)) cr.execute('UPDATE account_analytic_line SET ref=%s ' \ 'FROM account_move_line ' \ - 'WHERE account_move_line.move_id = %d ' \ + 'WHERE account_move_line.move_id = %s ' \ 'AND account_analytic_line.move_id = account_move_line.id', (ref, move_id)) return True diff --git a/addons/auction/auction.py b/addons/auction/auction.py index 4ae909240a3..2955d97b501 100644 --- a/addons/auction/auction.py +++ b/addons/auction/auction.py @@ -95,12 +95,12 @@ class auction_dates(osv.osv): RETURN: True """ # objects vendus mais non factures - cr.execute('select count(*) as c from auction_lots where auction_id in ('+','.join(map(str, ids))+') and state=%s and obj_price>0', ('draft',)) + cr.execute('select count(*) as c from auction_lots where auction_id =ANY(%s) and state=%s and obj_price>0', (ids,'draft',)) nbr = cr.fetchone()[0] ach_uids = {} - cr.execute('select id from auction_lots where auction_id in ('+','.join(map(str, ids))+') and state=%s and obj_price>0', ('draft',)) + cr.execute('select id from auction_lots where auction_id =ANY(%s) and state=%s and obj_price>0', (ids,'draft',)) r=self.pool.get('auction.lots').lots_invoice(cr, uid, [x[0] for x in cr.fetchall()],{},None) - cr.execute('select id from auction_lots where auction_id in ('+','.join(map(str, ids))+') and obj_price>0') + cr.execute('select id from auction_lots where auction_id =ANY(%s) and obj_price>0',(ids,)) ids2 = [x[0] for x in cr.fetchall()] # for auction in auction_ids: c=self.pool.get('auction.lots').seller_trans_create(cr, uid, ids2,{}) @@ -113,7 +113,7 @@ auction_dates() # Deposits #---------------------------------------------------------- def _inv_uniq(cr, ids): - cr.execute('select name from auction_deposit where id in ('+','.join(map(lambda x: str(x), ids))+')') + cr.execute('select name from auction_deposit where id =ANY(%s)',(ids,)) for datas in cr.fetchall(): cr.execute('select count(*) from auction_deposit where name=%s', (datas[0],)) if cr.fetchone()[0]>1: @@ -229,7 +229,7 @@ def _type_get(self, cr, uid,ids): # Lots #---------------------------------------------------------- def _inv_constraint(cr, ids): - cr.execute('select id, bord_vnd_id, lot_num from auction_lots where id in ('+','.join(map(lambda x: str(x), ids))+')') + cr.execute('select id, bord_vnd_id, lot_num from auction_lots where id =ANY(%s)', (ids,)) for datas in cr.fetchall(): cr.execute('select count(*) from auction_lots where bord_vnd_id=%s and lot_num=%s', (datas[1],datas[2])) if cr.fetchone()[0]>1: diff --git a/addons/auction/report/auction_total_rml.py b/addons/auction/report/auction_total_rml.py index ea6b6ad72ec..0e207db62bc 100644 --- a/addons/auction/report/auction_total_rml.py +++ b/addons/auction/report/auction_total_rml.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). # @@ -15,7 +15,7 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. +# along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## @@ -54,7 +54,7 @@ class auction_total_rml(report_sxw.rml_parse): for lot_id in objects: auc_lot_ids.append(lot_id.id) self.total_obj=auc_lot_ids - self.cr.execute('select auction_id from auction_lots where id in ('+','.join(map(str,auc_lot_ids))+') group by auction_id') + self.cr.execute('select auction_id from auction_lots where id =ANY(%s) group by auction_id',(auc_lot_ids,)) auc_date_ids = self.cr.fetchall() auct_dat=[] for ad_id in auc_date_ids: @@ -64,52 +64,52 @@ class auction_total_rml(report_sxw.rml_parse): def sum_taxes(self,auction_id): - self.cr.execute("select count(1) from auction_lots where id in ("+",".join(map(str,self.total_obj))+") and auction_id=%s group by auction_id ", (auction_id,)) + self.cr.execute("select count(1) from auction_lots where id =ANY(%s) and auction_id=%s group by auction_id ", (self.total_obj,auction_id,)) res = self.cr.fetchone() return res[0] def sold_item(self, object_id): - self.cr.execute("select count(1) from auction_lots where id in ("+",".join(map(str,self.total_obj))+") and auction_id=%s and state in ('unsold') ", (object_id,)) + self.cr.execute("select count(1) from auction_lots where id =ANY(%s) and auction_id=%s and state in ('unsold') ", (self.total_obj,object_id,)) res = self.cr.fetchone() return str(res[0]) def sum_buyer(self, auction_id): - self.cr.execute("select count(*) from auction_lots where id in ("+",".join(map(str,self.total_obj))+") and auction_id=%s and (ach_uid is not null or ach_login is not null) ", (auction_id,)) + self.cr.execute("select count(*) from auction_lots where id =ANY(%s) and auction_id=%s and (ach_uid is not null or ach_login is not null) ", (self.total_obj,auction_id,)) res = self.cr.fetchone() return str(res[0]) def sum_seller(self, auction_id): - self.cr.execute("select count(distinct bord_vnd_id) from auction_lots where id in ("+",".join(map(str,self.total_obj))+") and auction_id=%s AND bord_vnd_id is not null ", (auction_id,)) + self.cr.execute("select count(distinct bord_vnd_id) from auction_lots where id =ANY(%s) and auction_id=%s AND bord_vnd_id is not null ", (self.total_obj,auction_id,)) res = self.cr.fetchone() return res[0] def sum_adj(self, auction_id): - self.cr.execute("select sum(obj_price) from auction_lots where id in ("+",".join(map(str,self.total_obj))+") and auction_id=%s ", (auction_id,)) + self.cr.execute("select sum(obj_price) from auction_lots where id =ANY(%s) and auction_id=%s ", (self.total_obj,auction_id,)) res = self.cr.fetchone() return str(res[0]) def count_take(self, auction_id): - self.cr.execute("select count(*) from auction_lots where id in ("+",".join(map(str,self.total_obj))+") and auction_id=%s and ach_emp='True' ", (auction_id,)) + self.cr.execute("select count(*) from auction_lots where id =ANY(%s) and auction_id=%s and ach_emp='True' ", (self.total_obj,auction_id,)) res = self.cr.fetchone() return str(res[0]) def chek_paid(self, auction_id): - self.cr.execute("select count(1) from auction_lots where id in ("+",".join(map(str,self.total_obj))+") and auction_id=%s and ((paid_ach='T') or (is_ok='T')) ", (auction_id,)) + self.cr.execute("select count(1) from auction_lots where id =ANY(%s) and auction_id=%s and ((paid_ach='T') or (is_ok='T')) ", (self.total_obj,auction_id,)) res = self.cr.fetchone() return str(res[0]) def check_paid_seller(self,auction_id): - self.cr.execute("select sum(seller_price) from auction_lots where id in ("+",".join(map(str,self.total_obj))+") and auction_id=%s and paid_vnd != 'T' ", (auction_id,)) + self.cr.execute("select sum(seller_price) from auction_lots where id =ANY(%s) and auction_id=%s and paid_vnd != 'T' ", (self.total_obj,auction_id,)) res = self.cr.fetchone() return str(res[0]) or 0.0 def sum_credit(self,auction_id): - self.cr.execute("select sum(buyer_price) from auction_lots where id in ("+",".join(map(str,self.total_obj))+") and auction_id=%s", (auction_id,)) + self.cr.execute("select sum(buyer_price) from auction_lots where id =ANY(%s) and auction_id=%s", (self.total_obj,auction_id,)) res = self.cr.fetchone() return str(res[0]) def sum_debit_buyer(self,auction_id): - self.cr.execute("select sum(buyer_price) from auction_lots where id in ("+",".join(map(str,self.total_obj))+") and auction_id=%s", (auction_id,)) + self.cr.execute("select sum(buyer_price) from auction_lots where id =ANY(%s) and auction_id=%s", (self.total_obj,auction_id,)) res = self.cr.fetchone() return str(res[0] or 0) @@ -121,27 +121,27 @@ class auction_total_rml(report_sxw.rml_parse): def sum_credit_seller(self, object_id): - self.cr.execute("select sum(seller_price) from auction_lots where id in ("+",".join(map(str,self.total_obj))+") and auction_id=%s", (object_id,)) + self.cr.execute("select sum(seller_price) from auction_lots where id =ANY(%s) and auction_id=%s", (self.total_obj,object_id,)) res = self.cr.fetchone() return str(res[0] or 0) def sum_minadj(self, auction_id): - self.cr.execute('select sum(lot_est1) from auction_lots where id in ('+','.join(map(str,self.total_obj))+') and auction_id=%s', (auction_id,)) + self.cr.execute('select sum(lot_est1) from auction_lots where id =ANY(%s) and auction_id=%s', (self.total_obj,auction_id,)) res = self.cr.fetchone() return str(res[0]) or 0 def sum_maxadj(self, auction_id): - self.cr.execute('select sum(lot_est2) from auction_lots where id in ('+','.join(map(str,self.total_obj))+') and auction_id=%s', (auction_id,)) + self.cr.execute('select sum(lot_est2) from auction_lots where id =ANY(%s) and auction_id=%s', (self.total_obj,auction_id,)) res = self.cr.fetchone() return str(res[0]) or 0 def sum_buyer_paid(self, auction_id): - self.cr.execute("select count(*) from auction_lots where id in ("+",".join(map(str,self.total_obj))+") and auction_id=%s and state = 'paid' ", (auction_id,)) + self.cr.execute("select count(*) from auction_lots where id =ANY(%s) and auction_id=%s and state = 'paid' ", (self.total_obj,auction_id,)) res = self.cr.fetchone() return str(res[0]) def count_comm(self, auction_id): - self.cr.execute("select count(*) from auction_lots where id in ("+",".join(map(str,self.total_obj))+") and auction_id=%s and obj_comm is not null ", (auction_id,)) + self.cr.execute("select count(*) from auction_lots where id =ANY(%s) and auction_id=%s and obj_comm is not null ", (self.total_obj,auction_id,)) res = self.cr.fetchone() return str(res[0]) diff --git a/addons/auction/report/buyer_list.py b/addons/auction/report/buyer_list.py index cb35640e8b6..06430efdc85 100644 --- a/addons/auction/report/buyer_list.py +++ b/addons/auction/report/buyer_list.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). # @@ -15,7 +15,7 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. +# along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## @@ -49,7 +49,7 @@ class buyer_list(report_sxw.rml_parse): for lot_id in objects: auc_lot_ids.append(lot_id.id) self.auc_lot_ids=auc_lot_ids - self.cr.execute('select auction_id from auction_lots where id in ('+','.join(map(str,auc_lot_ids))+') group by auction_id') + self.cr.execute('select auction_id from auction_lots where id =ANY(%s) group by auction_id',(auc_lot_ids,)) auc_date_ids = self.cr.fetchall() auct_dat=[] for ad_id in auc_date_ids: @@ -70,7 +70,7 @@ class buyer_list(report_sxw.rml_parse): auc_date_ids = self.pool.get('auction.dates').search(self.cr,self.uid,([('name','like',obj['name'])])) # self.cr.execute('select ach_uid,count(1) as no_lot, sum(obj_price) as adj_price, sum(buyer_price)-sum(obj_price) as buyer_cost ,sum(buyer_price) as to_pay from auction_lots where id in ('+','.join(map(str,self.auc_lot_ids))+') and auction_id=%s and ach_uid is not null group by ach_uid ', (auc_date_ids[0],)) - self.cr.execute('select ach_login as ach_uid,count(1) as no_lot, sum(obj_price) as adj_price, sum(buyer_price)-sum(obj_price) as buyer_cost ,sum(buyer_price) as to_pay from auction_lots where id in ('+','.join(map(str,self.auc_lot_ids))+') and auction_id=%s and ach_login is not null group by ach_login order by ach_login', (auc_date_ids[0],)) + self.cr.execute('select ach_login as ach_uid,count(1) as no_lot, sum(obj_price) as adj_price, sum(buyer_price)-sum(obj_price) as buyer_cost ,sum(buyer_price) as to_pay from auction_lots where id =ANY(%s) and auction_id=%s and ach_login is not null group by ach_login order by ach_login', (self.auc_lot_ids,auc_date_ids[0],)) res = self.cr.dictfetchall() for r in res: # if r['ach_uid']: diff --git a/addons/auction/report/catalog2.py b/addons/auction/report/catalog2.py index 95a72889f97..3eb993c55ce 100644 --- a/addons/auction/report/catalog2.py +++ b/addons/auction/report/catalog2.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). # @@ -15,7 +15,7 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. +# along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## @@ -125,8 +125,8 @@ class auction_catalog(report_rml): auction_ids = [] for test in ab: if test.has_key('auction_id'): - auction_ids.append(str(test['auction_id'][0])) - cr.execute('select * from auction_lots where auction_id in ('+ ','.join(auction_ids)+')') + auction_ids.append(test['auction_id'][0]) + cr.execute('select * from auction_lots where auction_id =ANY(%s)',(auction_ids,)) res = cr.dictfetchall() for cat in res: product =doc.createElement('product') diff --git a/addons/base_module_quality/speed_test/speed_test.py b/addons/base_module_quality/speed_test/speed_test.py index 92b73a1cafa..ab50afe1293 100644 --- a/addons/base_module_quality/speed_test/speed_test.py +++ b/addons/base_module_quality/speed_test/speed_test.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). # @@ -15,7 +15,7 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. +# along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## @@ -45,8 +45,9 @@ This test checks the speed of the module. Note that at least 5 demo data is need # remove osv_memory class becaz it does not have demo data if obj_list: - cr.execute("select w.res_model from ir_actions_todo as t left join ir_act_window as w on t.action_id=w.id where w.res_model in ('%s')"% ("','".join(obj_list))) + cr.execute("select w.res_model from ir_actions_todo as t left join ir_act_window as w on t.action_id=w.id where w.res_model =ANY(%s)",(obj_list,)) res = cr.fetchall() + print res for remove_obj in res: if remove_obj and (remove_obj[0] in obj_list): obj_list.remove(remove_obj[0]) diff --git a/addons/board/board.py b/addons/board/board.py index 7ea9fa9f1dc..29e8a3310b4 100644 --- a/addons/board/board.py +++ b/addons/board/board.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). # @@ -15,7 +15,7 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. +# along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## @@ -24,9 +24,9 @@ from osv import fields,osv class board_board(osv.osv): _name = 'board.board' - + def create_view(self, cr, uid, ids, context): - + board = self.pool.get('board.board').browse(cr, uid, ids, context) left = [] right = [] @@ -52,23 +52,22 @@ class board_board(osv.osv): </child2> </hpaned> </form>""" % ('\n'.join(left), '\n'.join(right)) - + return arch def write(self, cr, uid, ids, vals, context={}): result = super(board_board, self).write(cr, uid, ids, vals, context) cr.commit() - + board = self.pool.get('board.board').browse(cr, uid, ids[0]) - + view = self.create_view(cr, uid, ids[0], context) id = board.view_id.id - - cr.execute("update ir_ui_view set arch='%s' where id=%s" % (view, id)) + cr.execute("update ir_ui_view set arch=%s where id=%s" , (view, id)) cr.commit() - + return result - + def create(self, cr, user, vals, context=None): if not 'name' in vals: return False @@ -84,31 +83,31 @@ class board_board(osv.osv): super(board_board, self).write(cr, user, [id], {'view_id': view_id}, context) return id - + def fields_view_get(self, cr, user, view_id=None, view_type='form', context=None, toolbar=False, submenu=False): res = {} res = super(board_board, self).fields_view_get(cr, user, view_id, view_type, context, toolbar=toolbar, submenu=submenu) - + vids = self.pool.get('ir.ui.view.custom').search(cr, user, [('user_id','=',user), ('ref_id','=',view_id)]) if vids: view_id = vids[0] arch = self.pool.get('ir.ui.view.custom').browse(cr, user, view_id) res['arch'] = arch.arch - + res['toolbar'] = {'print':[],'action':[],'relate':[]} return res - + _columns = { 'name': fields.char('Dashboard', size=64, required=True), 'view_id': fields.many2one('ir.ui.view', 'Board View'), 'line_ids': fields.one2many('board.board.line', 'board_id', 'Action Views') } - + # the following lines added to let the button on dashboard work. _defaults = { 'name': lambda *args: 'Dashboard' } - + board_board() class board_line(osv.osv): diff --git a/addons/crm/crm.py b/addons/crm/crm.py index c84c96e3abc..ed4735a55e8 100644 --- a/addons/crm/crm.py +++ b/addons/crm/crm.py @@ -79,7 +79,7 @@ class crm_case_section(osv.osv): def _check_recursion(self, cr, uid, ids): level = 100 while len(ids): - cr.execute('select distinct parent_id from crm_case_section where id in ('+','.join(map(str, ids))+')') + cr.execute('select distinct parent_id from crm_case_section where id =ANY(%s)',(ids,)) ids = filter(None, map(lambda x:x[0], cr.fetchall())) if not level: return False diff --git a/addons/crm/report/report_businessopp.py b/addons/crm/report/report_businessopp.py index 74022e00c28..240f361770e 100644 --- a/addons/crm/report/report_businessopp.py +++ b/addons/crm/report/report_businessopp.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). # @@ -15,7 +15,7 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. +# along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## @@ -55,9 +55,8 @@ class report_custom(report_int): minbenef = 999999999999999999999 maxbenef = 0 - cr.execute('select probability, planned_revenue, planned_cost, user_id, res_users.name as name from crm_case left join res_users on (crm_case.user_id=res_users.id) where crm_case.id in ('+','.join(map(str, ids))+') order by user_id') + cr.execute('select probability, planned_revenue, planned_cost, user_id, res_users.name as name from crm_case left join res_users on (crm_case.user_id=res_users.id) where crm_case.id =ANY(%s) order by user_id',(ids,)) res = cr.dictfetchall() - for row in res: proba = row['probability'] or 0 / 100.0 cost = row['planned_cost'] or 0 diff --git a/addons/crm_profiling/crm_profiling.py b/addons/crm_profiling/crm_profiling.py index ece1525590d..7e70df3dc4a 100644 --- a/addons/crm_profiling/crm_profiling.py +++ b/addons/crm_profiling/crm_profiling.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). # @@ -15,7 +15,7 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. +# along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## @@ -28,17 +28,17 @@ def _get_answers(cr, uid, ids): query = """ select distinct(answer) from profile_question_yes_rel - where profile in (%s)"""% ','.join([str(i) for i in ids ]) + where profile=ANY(%s)""" - cr.execute(query) + cr.execute(query,(ids,)) ans_yes = [x[0] for x in cr.fetchall()] query = """ select distinct(answer) from profile_question_no_rel - where profile in (%s)"""% ','.join([str(i) for i in ids ]) + where profile=ANY(%s)""" - cr.execute(query) + cr.execute(query,(ids,)) ans_no = [x[0] for x in cr.fetchall()] return [ans_yes, ans_no] @@ -50,7 +50,7 @@ def _get_parents(cr, uid, ids): select distinct(parent_id) from crm_segmentation where parent_id is not null - and id in (%s)""" % ','.join([str(i) for i in ids ])) + and id=ANY(%s)""",(ids,)) parent_ids = [x[0] for x in cr.fetchall()] @@ -88,17 +88,17 @@ def test_prof(cr, uid, seg_id, pid, answers_ids = []): def _recompute_categ(self, cr, uid, pid, answers_ids): ok = [] cr.execute(''' - select r.category_id - from res_partner_category_rel r left join crm_segmentation s on (r.category_id = s.categ_id) + select r.category_id + from res_partner_category_rel r left join crm_segmentation s on (r.category_id = s.categ_id) where r.partner_id = %s and (s.exclusif = false or s.exclusif is null) ''', (pid,)) for x in cr.fetchall(): ok.append(x[0]) query = ''' - select id, categ_id - from crm_segmentation - where profiling_active = true''' + select id, categ_id + from crm_segmentation + where profiling_active = true''' if ok != []: query = query +''' and categ_id not in(%s)'''% ','.join([str(i) for i in ok ]) query = query + ''' order by id ''' @@ -140,7 +140,7 @@ class questionnaire(osv.osv): for name, oid in result: quest_form = quest_form + '<field name="quest_form%d"/><newline/>' % (oid,) quest_fields['quest_form%d' % (oid,)] = {'string': name, 'type': 'many2one', 'relation': 'crm_profiling.answer', 'domain': [('question_id','=',oid)] } - quest_form = quest_form + '''</form>''' + quest_form = quest_form + '''</form>''' return quest_form, quest_fields _columns = { @@ -213,7 +213,7 @@ class crm_segmentation(osv.osv): if categ['exclusif']: cr.execute('delete from res_partner_category_rel where category_id=%s', (categ['categ_id'][0],)) - id = categ['id'] + id = categ['id'] cr.execute('select id from res_partner order by id ') partners = [x[0] for x in cr.fetchall()] diff --git a/addons/document/document.py b/addons/document/document.py index c8308265e4d..5613cc55958 100644 --- a/addons/document/document.py +++ b/addons/document/document.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). # @@ -15,7 +15,7 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. +# along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## @@ -36,6 +36,7 @@ import tools from tools.translate import _ import nodes + class document_file(osv.osv): _inherit = 'ir.attachment' _rec_name = 'datas_fname' @@ -185,7 +186,8 @@ class document_file(osv.osv): import urllib datas=base64.encodestring(urllib.urlopen(vals['link']).read()) else: - datas=vals.get('datas',False) + datas = vals.get('datas',False) + vals['file_size']= datas and len(datas) or 0 if not self._check_duplication(cr,uid,vals): raise osv.except_osv(_('ValidateError'), _('File name must be unique!')) diff --git a/addons/event/event.py b/addons/event/event.py index cad4d7f23d1..c91c6880f39 100644 --- a/addons/event/event.py +++ b/addons/event/event.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). # @@ -15,7 +15,7 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. +# along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## @@ -77,8 +77,8 @@ class event(osv.osv): def _get_register(self, cr, uid, ids, name, args, context=None): res={} for event in self.browse(cr, uid, ids, context): - query = """select sum(nb_register) from crm_case c left join crm_case_section s on (c.section_id=s.id) right join event_event e on (e.section_id=s.id) right join event_registration r on (r.case_id=c.id) where e.section_id = %s and c.state in ('open','done')""" % event.section_id.id - cr.execute(query) + query = """select sum(nb_register) from crm_case c left join crm_case_section s on (c.section_id=s.id) right join event_event e on (e.section_id=s.id) right join event_registration r on (r.case_id=c.id) where e.section_id = %s and c.state in ('open','done')""" + cr.execute(query,(event.section_id.id,)) res2 = cr.fetchone() if res2 and res2[0]: res[event.id] = res2[0] @@ -89,8 +89,8 @@ class event(osv.osv): def _get_prospect(self, cr, uid, ids, name, args, context=None): res={} for event in self.browse(cr, uid, ids, context): - query = """select sum(nb_register) from crm_case c left join crm_case_section s on (c.section_id=s.id) right join event_event e on (e.section_id=s.id) right join event_registration r on (r.case_id=c.id) where e.section_id = %s and c.state = 'draft'""" % event.section_id.id - cr.execute(query) + query = """select sum(nb_register) from crm_case c left join crm_case_section s on (c.section_id=s.id) right join event_event e on (e.section_id=s.id) right join event_registration r on (r.case_id=c.id) where e.section_id = %s and c.state = 'draft'""" + cr.execute(query,(event.section_id.id,)) res2 = cr.fetchone() if res2 and res2[0]: res[event.id] = res2[0] diff --git a/addons/event_project/event.py b/addons/event_project/event.py index 3bc12572867..2d17e7e146a 100644 --- a/addons/event_project/event.py +++ b/addons/event_project/event.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). # @@ -15,7 +15,7 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. +# along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## @@ -36,8 +36,8 @@ class one2many_mod_task(fields.one2many): for id in ids: res[id] = [] for id in ids: - query = "select project_id from event_event where id = %i" %id - cr.execute(query) + query = "select project_id from event_event where id = %s" + cr.execute(query,(id,)) project_ids = [ x[0] for x in cr.fetchall()] ids2 = obj.pool.get(self._obj).search(cr, user, [(self._fields_id,'in',project_ids),('state','<>','done')], limit=self._limit) for r in obj.pool.get(self._obj)._read_flat(cr, user, ids2, [self._fields_id], context=context, load='_classic_write'): diff --git a/addons/hr/hr.py b/addons/hr/hr.py index a49bad405dc..06196c3bd39 100755 --- a/addons/hr/hr.py +++ b/addons/hr/hr.py @@ -39,7 +39,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 in ('+','.join(map(str, ids))+')') + cr.execute('select distinct parent_id from hr_employee_category where id=ANY(%s)',(ids,)) ids = filter(None, map(lambda x:x[0], cr.fetchall())) if not level: return False @@ -84,7 +84,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 in ('+','.join(map(str, ids))+')') + cr.execute('select distinct parent_id from hr_employee where id =ANY(%s)',(ids,)) ids = filter(None, map(lambda x:x[0], cr.fetchall())) if not level: return False diff --git a/addons/hr/hr_department.py b/addons/hr/hr_department.py index 92d1b200d58..d9efe2ce448 100644 --- a/addons/hr/hr_department.py +++ b/addons/hr/hr_department.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). # @@ -15,7 +15,7 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. +# along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## @@ -43,7 +43,7 @@ class hr_department(osv.osv): def _check_recursion(self, cr, uid, ids): level = 100 while len(ids): - cr.execute('select distinct parent_id from hr_department where id in ('+','.join(map(str, ids))+')') + cr.execute('select distinct parent_id from hr_department where id =ANY(%s)',(ids,)) ids = filter(None, map(lambda x:x[0], cr.fetchall())) if not level: return False @@ -117,12 +117,12 @@ class res_users(osv.osv): ids_dept = obj_dept.search(cr, uid, [('id', 'child_of', mgnt_dept_ids)]) if ids_dept: data_dept = obj_dept.read(cr, uid, ids_dept, ['member_ids']) - childs = map(lambda x: x['member_ids'], data_dept) + childs = map(lambda x: x['member_ids'], data_dept) childs = tools.flatten(childs) - childs = obj_user.search(cr, uid, [('id','in',childs),('active','=',True)]) + childs = obj_user.search(cr, uid, [('id','in',childs),('active','=',True)]) if manager_id in childs: childs.remove(manager_id) - + child_ids.extend(tools.flatten(childs)) set = {} map(set.__setitem__, child_ids, []) diff --git a/addons/hr_attendance/hr_attendance.py b/addons/hr_attendance/hr_attendance.py index 8994f96de4a..1262896d17f 100644 --- a/addons/hr_attendance/hr_attendance.py +++ b/addons/hr_attendance/hr_attendance.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). # @@ -15,7 +15,7 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. +# along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## @@ -56,7 +56,7 @@ class hr_attendance(osv.osv): 'name' : lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'), 'employee_id' : _employee_get, } - + def _altern_si_so(self, cr, uid, ids): for id in ids: sql = ''' @@ -66,14 +66,14 @@ class hr_attendance(osv.osv): and action in ('sign_in','sign_out') and name <= (select name from hr_attendance where id=%s) order by name desc - limit 2 - ''' % (id, id) - cr.execute(sql) + limit 2 ''' + + cr.execute(sql,(id,id)) atts = cr.fetchall() if not ((len(atts)==1 and atts[0][0] == 'sign_in') or (atts[0][0] != atts[1][0] and atts[0][1] != atts[1][1])): return False return True - + _constraints = [(_altern_si_so, 'Error: Sign in (resp. Sign out) must follow Sign out (resp. Sign in)', ['action'])] _order = 'name desc' hr_attendance() @@ -81,7 +81,7 @@ hr_attendance() class hr_employee(osv.osv): _inherit = "hr.employee" _description = "Employee" - + def _state(self, cr, uid, ids, name, args, context={}): result = {} for id in ids: @@ -96,16 +96,15 @@ class hr_employee(osv.osv): LEFT JOIN hr_attendance \ ON (hr_attendance.employee_id = foo.employee_id \ AND hr_attendance.name = foo.name) \ - WHERE hr_attendance.employee_id \ - in (' + ','.join([str(x) for x in ids]) + ')') + WHERE hr_attendance.employee_id =ANY(%s)',(ids,)) for res in cr.fetchall(): result[res[1]] = res[0] == 'sign_in' and 'present' or 'absent' return result - + _columns = { 'state': fields.function(_state, method=True, type='selection', selection=[('absent', 'Absent'), ('present', 'Present')], string='Attendance'), } - + def _action_check(self, cr, uid, emp_id, dt=False,context={}): cr.execute('select max(name) from hr_attendance where employee_id=%s', (emp_id,)) res = cr.fetchone() @@ -140,5 +139,5 @@ class hr_employee(osv.osv): return True hr_employee() - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/hr_attendance/wizard/print_attendance_error.py b/addons/hr_attendance/wizard/print_attendance_error.py index cdddcaa0ddb..82503318fbe 100644 --- a/addons/hr_attendance/wizard/print_attendance_error.py +++ b/addons/hr_attendance/wizard/print_attendance_error.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). # @@ -15,7 +15,7 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. +# along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## @@ -42,21 +42,19 @@ _date_fields = { def _check_data(self, cr, uid, data, *args): date_from = data['form']['init_date'] date_to = data['form']['end_date'] - emp_ids = (','.join([str(x) for x in data['ids']])) - - cr.execute("select id from hr_attendance where employee_id in (%s) and to_char(name,'YYYY-mm-dd')<='%s' and to_char(name,'YYYY-mm-dd')>='%s' and action in ('%s','%s') order by name" %(emp_ids, date_to, date_from, 'sign_in', 'sign_out')) + cr.execute("select id from hr_attendance where employee_id =ANY(%s) and to_char(name,'YYYY-mm-dd')<=%s and to_char(name,'YYYY-mm-dd')>=%s and action =ANY(%s) order by name" ,(data['ids'], date_to, date_from, ['sign_in','sign_out'])) attendance_ids = [x[0] for x in cr.fetchall()] if not attendance_ids: - raise wizard.except_wizard(_('No Data Available'), _('No records found for your selection!')) - + raise wizard.except_wizard(_('No Data Available'), _('No records found for your selection!')) + attendance_records = pooler.get_pool(cr.dbname).get('hr.attendance').browse(cr,uid,attendance_ids) emp_ids = [] for rec in attendance_records: if rec.employee_id.id not in emp_ids: emp_ids.append(rec.employee_id.id) - + data['form']['emp_ids'] = emp_ids - + return data['form'] diff --git a/addons/hr_expense/hr_expense.py b/addons/hr_expense/hr_expense.py index f0c566fbf16..6c31e6c3b69 100644 --- a/addons/hr_expense/hr_expense.py +++ b/addons/hr_expense/hr_expense.py @@ -38,8 +38,7 @@ class hr_expense_expense(osv.osv): return super(hr_expense_expense, self).copy(cr, uid, id, default, context) def _amount(self, cr, uid, ids, field_name, arg, context): - id_set = ",".join(map(str, ids)) - cr.execute("SELECT s.id,COALESCE(SUM(l.unit_amount*l.unit_quantity),0) AS amount FROM hr_expense_expense s LEFT OUTER JOIN hr_expense_line l ON (s.id=l.expense_id) WHERE s.id IN ("+id_set+") GROUP BY s.id ") + cr.execute("SELECT s.id,COALESCE(SUM(l.unit_amount*l.unit_quantity),0) AS amount FROM hr_expense_expense s LEFT OUTER JOIN hr_expense_line l ON (s.id=l.expense_id) WHERE s.id =ANY(%s) GROUP BY s.id ",(ids,)) res = dict(cr.fetchall()) return res @@ -188,8 +187,7 @@ class hr_expense_line(osv.osv): def _amount(self, cr, uid, ids, field_name, arg, context): if not len(ids): return {} - id_set = ",".join(map(str, ids)) - cr.execute("SELECT l.id,COALESCE(SUM(l.unit_amount*l.unit_quantity),0) AS amount FROM hr_expense_line l WHERE id IN ("+id_set+") GROUP BY l.id ") + cr.execute("SELECT l.id,COALESCE(SUM(l.unit_amount*l.unit_quantity),0) AS amount FROM hr_expense_line l WHERE id =ANY(%s) GROUP BY l.id ",(ids,)) res = dict(cr.fetchall()) return res diff --git a/addons/hr_timesheet_invoice/report/cost_ledger.py b/addons/hr_timesheet_invoice/report/cost_ledger.py index 9bde3837790..8daf40fded6 100644 --- a/addons/hr_timesheet_invoice/report/cost_ledger.py +++ b/addons/hr_timesheet_invoice/report/cost_ledger.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). # @@ -15,7 +15,7 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. +# along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## @@ -112,7 +112,7 @@ class account_analytic_cost_ledger(report_sxw.rml_parse): return self.cr.fetchone()[0] or 0.0 def _account_sum_balance(self, account_id, date1, date2): - debit = self._account_sum_debit(account_id, date1, date2) + debit = self._account_sum_debit(account_id, date1, date2) credit = self._account_sum_credit(account_id, date1, date2) return (debit-credit) @@ -130,7 +130,7 @@ class account_analytic_cost_ledger(report_sxw.rml_parse): ids = map(lambda x: x.id, accounts) if not len(ids): return 0.0 - self.cr.execute("SELECT sum(amount) FROM account_analytic_line WHERE account_id IN ("+','.join(map(str, ids))+") AND date>=%s AND date<=%s AND amount>0", (date1, date2)) + self.cr.execute("SELECT sum(amount) FROM account_analytic_line WHERE account_id =ANY(%s) AND date>=%s AND date<=%s AND amount>0", (ids,date1, date2)) return self.cr.fetchone()[0] or 0.0 def _sum_credit(self, accounts, date1, date2): @@ -138,7 +138,7 @@ class account_analytic_cost_ledger(report_sxw.rml_parse): if not len(ids): return 0.0 ids = map(lambda x: x.id, accounts) - self.cr.execute("SELECT -sum(amount) FROM account_analytic_line WHERE account_id IN ("+','.join(map(str, ids))+") AND date>=%s AND date<=%s AND amount<0", (date1, date2)) + self.cr.execute("SELECT -sum(amount) FROM account_analytic_line WHERE account_id =ANY(%s) AND date>=%s AND date<=%s AND amount<0", (ids, date1, date2)) return self.cr.fetchone()[0] or 0.0 def _sum_balance(self, accounts, date1, date2): @@ -151,7 +151,7 @@ class account_analytic_cost_ledger(report_sxw.rml_parse): if not len(ids): return 0.0 ids = map(lambda x: x.id, accounts) - self.cr.execute("SELECT sum(unit_amount) FROM account_analytic_line WHERE account_id IN ("+','.join(map(str, ids))+") AND date>=%s AND date<=%s", (date1, date2)) + self.cr.execute("SELECT sum(unit_amount) FROM account_analytic_line WHERE account_id =ANY(%s) AND date>=%s AND date<=%s", (ids,date1, date2)) return self.cr.fetchone()[0] or 0.0 def _sum_revenue(self, accounts): diff --git a/addons/hr_timesheet_invoice/wizard/hr_timesheet_invoice_create.py b/addons/hr_timesheet_invoice/wizard/hr_timesheet_invoice_create.py index a7a0a4b6a51..21c7b3df150 100644 --- a/addons/hr_timesheet_invoice/wizard/hr_timesheet_invoice_create.py +++ b/addons/hr_timesheet_invoice/wizard/hr_timesheet_invoice_create.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). # @@ -15,7 +15,7 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. +# along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## @@ -42,15 +42,15 @@ class invoice_create(wizard.interface): if obj_acc.invoice_id and obj_acc.invoice_id.state !='cancel': raise wizard.except_wizard(_('Warning'),_('The analytic entry "%s" is already invoiced!')%(obj_acc.name,)) - cr.execute("SELECT distinct(account_id) from account_analytic_line where id IN (%s)"% (','.join(map(str,data['ids'])),)) + cr.execute("SELECT distinct(account_id) from account_analytic_line where id =ANY(%s)",(data['ids'],)) account_ids = cr.fetchall() return {'accounts': [x[0] for x in account_ids]} def _do_create(self, cr, uid, data, context): pool = pooler.get_pool(cr.dbname) - mod_obj = pool.get('ir.model.data') + mod_obj = pool.get('ir.model.data') result = mod_obj._get_id(cr, uid, 'account', 'view_account_invoice_filter') - res = mod_obj.read(cr, uid, result, ['res_id']) + res = mod_obj.read(cr, uid, result, ['res_id']) analytic_account_obj = pool.get('account.analytic.account') res_partner_obj = pool.get('res.partner') account_payment_term_obj = pool.get('account.payment.term') @@ -98,9 +98,8 @@ class invoice_create(wizard.interface): cr.execute("SELECT product_id, to_invoice, sum(unit_amount) " \ "FROM account_analytic_line as line " \ "WHERE account_id = %s " \ - "AND id IN (" + ','.join([str(x) for x in data['ids']]) + ") " \ - "AND to_invoice IS NOT NULL " \ - "GROUP BY product_id,to_invoice", (account.id,)) + "AND id =ANY(%s) AND to_invoice IS NOT NULL " \ + "GROUP BY product_id,to_invoice", (account.id,data['ids'],)) for product_id,factor_id,qty in cr.fetchall(): product = pool.get('product.product').browse(cr, uid, product_id, context2) @@ -108,7 +107,7 @@ class invoice_create(wizard.interface): raise wizard.except_wizard(_('Error'), _('At least one line has no product !')) factor_name = '' factor = pool.get('hr_timesheet_invoice.factor').browse(cr, uid, factor_id, context2) - + if not data['form']['product']: if factor.customer_name: factor_name = product.name+' - '+factor.customer_name @@ -116,7 +115,7 @@ class invoice_create(wizard.interface): factor_name = product.name else: factor_name = pool.get('product.product').name_get(cr, uid, [data['form']['product']], context=context)[0][1] - + if account.pricelist_id: pl = account.pricelist_id.id price = pool.get('product.pricelist').price_get(cr,uid,[pl], data['form']['product'] or product_id, qty or 1.0, account.partner_id.id)[pl] @@ -126,7 +125,6 @@ class invoice_create(wizard.interface): taxes = product.taxes_id tax = pool.get('account.fiscal.position').map_tax(cr, uid, account.partner_id.property_account_position, taxes) account_id = product.product_tmpl_id.property_account_income.id or product.categ_id.property_account_income_categ.id - curr_line = { 'price_unit': price, 'quantity': qty, @@ -140,11 +138,12 @@ class invoice_create(wizard.interface): 'account_id': account_id, 'account_analytic_id': account.id, } - + # # 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)) + line_ids = cr.dictfetchall() note = [] for line in line_ids: @@ -165,13 +164,12 @@ class invoice_create(wizard.interface): curr_line['note'] = "\n".join(map(lambda x: unicode(x) or '',note)) pool.get('account.invoice.line').create(cr, uid, curr_line) - strids = ','.join(map(str, data['ids'])) - cr.execute("update account_analytic_line set invoice_id=%%s WHERE account_id = %%s and id IN (%s)" % strids, (last_invoice,account.id,)) - + cr.execute("update account_analytic_line set invoice_id=%s WHERE account_id = %s and id =ANY(%s)" ,(last_invoice,account.id,data['ids'])) + pool.get('account.invoice').button_reset_taxes(cr, uid, [last_invoice], context) - + mod_obj = pooler.get_pool(cr.dbname).get('ir.model.data') - act_obj = pooler.get_pool(cr.dbname).get('ir.actions.act_window') + act_obj = pooler.get_pool(cr.dbname).get('ir.actions.act_window') mod_id = mod_obj.search(cr, uid, [('name', '=', 'action_invoice_tree1')])[0] res_id = mod_obj.read(cr, uid, mod_id, ['res_id'])['res_id'] @@ -179,7 +177,7 @@ class invoice_create(wizard.interface): act_win['domain'] = [('id','in',invoices),('type','=','out_invoice')] act_win['name'] = _('Invoices') return act_win - + # return { # 'domain': "[('id','in', ["+','.join(map(str,invoices))+"])]", # 'name': _('Invoices'), diff --git a/addons/hr_timesheet_sheet/hr_timesheet_sheet.py b/addons/hr_timesheet_sheet/hr_timesheet_sheet.py index 1cf2eba9660..81b5e99d1f5 100644 --- a/addons/hr_timesheet_sheet/hr_timesheet_sheet.py +++ b/addons/hr_timesheet_sheet/hr_timesheet_sheet.py @@ -103,7 +103,7 @@ class hr_timesheet_sheet(osv.osv): LEFT JOIN hr_timesheet_sheet_sheet_day AS day \ ON (sheet.id = day.sheet_id \ AND day.name = sheet.date_current) \ - WHERE sheet.id in (' + ','.join([str(x) for x in ids]) + ')') + WHERE sheet.id =ANY(%s)',(ids,)) for record in cr.fetchall(): res[record[0]] = {} res[record[0]]['total_attendance_day'] = record[1] @@ -117,8 +117,7 @@ class hr_timesheet_sheet(osv.osv): FROM hr_timesheet_sheet_sheet s \ LEFT JOIN hr_timesheet_sheet_sheet_day d \ ON (s.id = d.sheet_id) \ - WHERE s.id in ('+ ','.join(map(str, ids)) + ') \ - GROUP BY s.id') + WHERE s.id =ANY(%s) GROUP BY s.id',(ids,)) for record in cr.fetchall(): res[record[0]] = {} res[record[0]]['total_attendance'] = record[1] @@ -349,8 +348,7 @@ class hr_timesheet_line(osv.osv): ON (s.date_to >= al.date \ AND s.date_from <= al.date \ AND s.user_id = al.user_id) \ - WHERE l.id in (' + ','.join([str(x) for x in ids]) + ') \ - GROUP BY l.id') + WHERE l.id =ANY(%s) GROUP BY l.id',(ids,)) res = dict(cursor.fetchall()) sheet_names = {} for sheet_id, name in sheet_obj.name_get(cursor, user, res.values(), @@ -469,8 +467,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 in (" + ",".join([str(x) for x in ids]) + ") \ - GROUP BY a.id") + WHERE a.id =ANY(%s) GROUP BY a.id",(ids,)) res = dict(cursor.fetchall()) sheet_names = {} for sheet_id, name in sheet_obj.name_get(cursor, user, res.values(), diff --git a/addons/idea/idea.py b/addons/idea/idea.py index 195140e99ba..d487c1875e7 100644 --- a/addons/idea/idea.py +++ b/addons/idea/idea.py @@ -79,7 +79,6 @@ class idea_idea(osv.osv): GROUP BY i.id """ - cr.execute(sql,(ids,)) return dict(cr.fetchall()) diff --git a/addons/l10n_be/wizard/partner_vat_listing.py b/addons/l10n_be/wizard/partner_vat_listing.py index 30b2b792f73..09876a2c31c 100644 --- a/addons/l10n_be/wizard/partner_vat_listing.py +++ b/addons/l10n_be/wizard/partner_vat_listing.py @@ -94,9 +94,7 @@ class wizard_vat(wizard.interface): def _get_partner(self, cr, uid, data, context): pool = pooler.get_pool(cr.dbname) - period_ids = pool.get('account.period').search(cr, uid, [('fiscalyear_id', '=', data['form']['fyear'])]) - period = "("+','.join(map(lambda x: str(x), period_ids)) +")" - + period = pool.get('account.period').search(cr, uid, [('fiscalyear_id', '=', data['form']['fyear'])]) p_id_list = pool.get('res.partner').search(cr,uid,[('vat_subjected','!=',False)]) if not p_id_list: raise wizard.except_wizard(_('Data Insufficient!'),_('No partner has a VAT Number asociated with him.')) @@ -116,8 +114,7 @@ class wizard_vat(wizard.interface): break if not go_ahead: continue - query = 'select b.code,sum(credit)-sum(debit) from account_move_line l left join account_account a on (l.account_id=a.id) left join account_account_type b on (a.user_type=b.id) where b.code in ('"'produit'"','"'tax'"') and l.partner_id='+str(obj_partner.id)+' and l.period_id in '+period+' group by b.code' - cr.execute(query) + cr.execute('select b.code,sum(credit)-sum(debit) from account_move_line l left join account_account a on (l.account_id=a.id) left join account_account_type b on (a.user_type=b.id) where b.code in %s and l.partner_id=%s and l.period_id=ANY(%s) group by b.code',(('produit','tax'),obj_partner.id,period,)) line_info = cr.fetchall() if not line_info: continue diff --git a/addons/l10n_ch/wizard/bvr_import.py b/addons/l10n_ch/wizard/bvr_import.py index 659c0b557bb..55caf5c4162 100755 --- a/addons/l10n_ch/wizard/bvr_import.py +++ b/addons/l10n_ch/wizard/bvr_import.py @@ -57,12 +57,11 @@ def _reconstruct_invoice_ref(cursor, user, reference, context): # we now searhc for company user_obj=pooler.get_pool(cursor.dbname).get('res.users') user_current=user_obj.browse(cursor, user, user) - + ## - - cursor.execute("SELECT inv.id,inv.number from account_invoice AS inv where inv.company_id = " + str(user_current.company_id.id)) + cursor.execute("SELECT inv.id,inv.number from account_invoice AS inv where inv.company_id = %s" ,(user_current.company_id.id,)) result_invoice = cursor.fetchall() - + for inv_id,inv_name in result_invoice: inv_name = re.sub('[^0-9]', '0', str(inv_name)) if inv_name == reference: @@ -72,7 +71,7 @@ def _reconstruct_invoice_ref(cursor, user, reference, context): cursor.execute('SELECT l.id ' \ 'FROM account_move_line l, account_invoice i ' \ 'WHERE l.move_id = i.move_id AND l.reconcile_id is NULL ' \ - 'AND i.id in (' + ','.join([str(x) for x in [id_invoice]]) + ')') + 'AND i.id =ANY(%s)',([id_invoice],)) inv_line = [] for id_line in cursor.fetchall(): inv_line.append(id_line[0]) @@ -181,7 +180,7 @@ def _import(obj, cursor, user, data, context): ], order='date desc', context=context) if not line_ids: line_ids = _reconstruct_invoice_ref(cursor,user,reference,None) - + line2reconcile = False partner_id = False account_id = False diff --git a/addons/l10n_fr/report/base_report.py b/addons/l10n_fr/report/base_report.py index d12a76298cc..1de66123f2c 100644 --- a/addons/l10n_fr/report/base_report.py +++ b/addons/l10n_fr/report/base_report.py @@ -43,19 +43,16 @@ class base_report(report_sxw.rml_parse): def _load(self,name,form): fiscalyear=self.pool.get('account.fiscalyear').browse(self.cr, self.uid, form['fiscalyear']) - periods=self.pool.get('account.period').search(self.cr, self.uid,[('fiscalyear_id','=',form['fiscalyear'])]) - period_query_cond=str(tuple(periods)) + period_query_cond=self.pool.get('account.period').search(self.cr, self.uid,[('fiscalyear_id','=',form['fiscalyear'])]) - query = "SELECT MIN(date_start) AS date_start, MAX(date_stop) AS date_stop FROM account_period WHERE id IN "+str(period_query_cond) - self.cr.execute(query) + self.cr.execute("SELECT MIN(date_start) AS date_start, MAX(date_stop) AS date_stop FROM account_period WHERE id =ANY(%s)",(period_query_cond,)) dates =self.cr.dictfetchall() self._set_variable('date_start', dates[0]['date_start']) self._set_variable('date_stop', dates[0]['date_stop']) - query = "SELECT l10n_fr_line.code,definition FROM l10n_fr_line LEFT JOIN l10n_fr_report ON l10n_fr_report.id=report_id WHERE l10n_fr_report.code='"+name+"'" - self.cr.execute(query) + self.cr.execute("SELECT l10n_fr_line.code,definition FROM l10n_fr_line LEFT JOIN l10n_fr_report ON l10n_fr_report.id=report_id WHERE l10n_fr_report.code=%s",(name,)) datas =self.cr.dictfetchall() - for line in datas: + for line in datas: self._load_accounts(form,line['code'],eval(line['definition']),fiscalyear,period_query_cond) def _set_variable(self,variable,valeur): @@ -86,9 +83,9 @@ class base_report(report_sxw.rml_parse): closed_cond="" if fiscalyear.state=='done': - closed_cond=" AND (aml.move_id NOT IN (SELECT account_move.id as move_id FROM account_move WHERE period_id IN "+str(period_query_cond)+" AND journal_id=(SELECT res_id FROM ir_model_data WHERE name='closing_journal' AND module='l10n_fr')) OR (aa.type != 'income' AND aa.type !='expense'))" + closed_cond=" AND (aml.move_id NOT IN (SELECT account_move.id as move_id FROM account_move WHERE period_id IN "+str(tuple(period_query_cond))+" AND journal_id=(SELECT res_id FROM ir_model_data WHERE name='closing_journal' AND module='l10n_fr')) OR (aa.type != 'income' AND aa.type !='expense'))" - query = "SELECT aa.code AS code, SUM(debit) as debit, SUM(credit) as credit FROM account_move_line aml LEFT JOIN account_account aa ON aa.id=aml.account_id WHERE "+query_cond+closed_cond+" AND aml.state='valid' AND aml.period_id IN "+str(period_query_cond)+" GROUP BY code" + query = "SELECT aa.code AS code, SUM(debit) as debit, SUM(credit) as credit FROM account_move_line aml LEFT JOIN account_account aa ON aa.id=aml.account_id WHERE "+query_cond+closed_cond+" AND aml.state='valid' AND aml.period_id IN "+str(tuple(period_query_cond))+" GROUP BY code" self.cr.execute(query) lines =self.cr.dictfetchall() @@ -102,7 +99,7 @@ class base_report(report_sxw.rml_parse): value=line["debit"]-line["credit"] elif(type=="D"): value=line["debit"]-line["credit"] - if(value<0.001): value=0.0 + if(value<0.001): value=0.0 elif(type=="C"): value=line["credit"]-line["debit"] if(value<0.001): value=0.0 diff --git a/addons/membership/membership.py b/addons/membership/membership.py index 7a67bf6e1e9..a364c0caedc 100644 --- a/addons/membership/membership.py +++ b/addons/membership/membership.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). # @@ -15,7 +15,7 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. +# along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## @@ -147,9 +147,7 @@ class membership_line(osv.osv): ) JOIN account_invoice ai ON ( ai.id = ail.invoice_id) - WHERE ml.id in (%s) - ''' % ','.join([str(id) for id in ids])) - + WHERE ml.id =ANY(%s)''',(ids,)) res = cr.fetchall() for r in res: if r[0] and r[0] < 0: @@ -401,7 +399,7 @@ class Partner(osv.osv): def _check_recursion(self, cr, uid, ids): level = 100 while len(ids): - cr.execute('select distinct associate_member from res_partner where id in ('+','.join(map(str, ids))+')') + cr.execute('select distinct associate_member from res_partner where id =ANY(%s)',(ids,)) ids = filter(None, map(lambda x:x[0], cr.fetchall())) if not level: return False diff --git a/addons/membership/wizard/invoice_membership.py b/addons/membership/wizard/invoice_membership.py index 6fd1e56f831..dc607622140 100644 --- a/addons/membership/wizard/invoice_membership.py +++ b/addons/membership/wizard/invoice_membership.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). # @@ -15,7 +15,7 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. +# along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## @@ -32,9 +32,7 @@ def _invoice_membership(self, cr, uid, data, context): cr.execute(''' SELECT partner_id, id, type FROM res_partner_address - WHERE partner_id IN (%s) - ''' % ','.join([str(id) for id in partner_ids]) - ) + WHERE partner_id =ANY(%s)''',(partner_ids,)) fetchal = cr.fetchall() if not fetchal: raise wizard.except_wizard(_('Error !'), _('No Address defined for this partner')) diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index 1f3be7c0943..8aad4209b9d 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -206,9 +206,9 @@ class mrp_bom(osv.osv): ] def _check_recursion(self, cr, uid, ids): - level = 500 + level = 100 while len(ids): - cr.execute('select distinct bom_id from mrp_bom where id in ('+','.join(map(str, ids))+')') + cr.execute('select distinct bom_id from mrp_bom where id =ANY(%s)',(ids,)) ids = filter(None, map(lambda x:x[0], cr.fetchall())) if not level: return False diff --git a/addons/mrp/report/workcenter_load.py b/addons/mrp/report/workcenter_load.py index 0bbca83a130..a65a51d03f7 100644 --- a/addons/mrp/report/workcenter_load.py +++ b/addons/mrp/report/workcenter_load.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). # @@ -15,11 +15,11 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. +# along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## -from report.render import render +from report.render import render from report.interface import report_int from pychart import * from mx.DateTime import * @@ -42,7 +42,7 @@ class external_pdf(render): render.__init__(self) self.pdf = pdf self.output_type='pdf' - + def _render(self): return self.pdf @@ -98,14 +98,13 @@ class report_custom(report_int): def create(self, cr, uid, ids, datas, context={}): assert len(ids), 'You should provide some ids!' colors = choice_colors(len(ids)) - ids_str = ','.join(map(str, ids)) cr.execute( "SELECT MAX(mrp_production.date_planned) AS stop,MIN(mrp_production.date_planned) AS start "\ "FROM mrp_workcenter, mrp_production, mrp_production_workcenter_line "\ "WHERE mrp_production_workcenter_line.production_id=mrp_production.id "\ "AND mrp_production_workcenter_line.workcenter_id=mrp_workcenter.id "\ "AND mrp_production.state NOT IN ('cancel','done') "\ - "AND mrp_workcenter.id IN (%s)" % ids_str) + "AND mrp_workcenter.id =ANY(%s)",(ids,)) res = cr.dictfetchone() if not res['stop']: res['stop'] = time.strftime('%Y-%m-%d %H:%M:%S') @@ -136,8 +135,8 @@ class report_custom(report_int): # select workcenters cr.execute( "SELECT id, name FROM mrp_workcenter " \ - "WHERE id in (%s) "\ - "ORDER BY mrp_workcenter.id" % ids_str) + "WHERE id=ANY(%s)" \ + "ORDER BY mrp_workcenter.id" ,(ids,)) workcenters = cr.dictfetchall() data = [] @@ -161,7 +160,7 @@ class report_custom(report_int): vals.append(res[0]['cycles'] or 0.0) else: vals.append(res[0]['hours'] or 0.0) - + toto = [dates[date]['name']] for val in vals: toto.append(val) @@ -184,7 +183,7 @@ class report_custom(report_int): self.obj.render() pdf_string.close() return (self.obj.pdf, 'pdf') - + def _empty_graph(self, date): data = [[date, 0]] ar = area.T(x_coord = category_coord.T(data, 0), y_range = (0, None), diff --git a/addons/point_of_sale/pos.py b/addons/point_of_sale/pos.py index 7115495a647..5a6720c8046 100644 --- a/addons/point_of_sale/pos.py +++ b/addons/point_of_sale/pos.py @@ -15,7 +15,7 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # -# You should have received a copy of the GNU General Public License +# You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## @@ -90,7 +90,6 @@ class pos_order(osv.osv): return {'value':{'pricelist_id': pricelist}} def _amount_total(self, cr, uid, ids, field_name, arg, context): - id_set = ",".join(map(str, ids)) cr.execute(""" SELECT p.id, @@ -99,7 +98,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 IN (""" + id_set +""") GROUP BY p.id """) + WHERE p.id =ANY(%s) GROUP BY p.id """,(ids,)) res = dict(cr.fetchall()) for rec in self.browse(cr, uid, ids, context): if rec.partner_id \ @@ -225,8 +224,7 @@ class pos_order(osv.osv): return res def payment_get(self, cr, uid, ids, context=None): - cr.execute("select id from pos_payment where order_id in (%s)" % \ - ','.join([str(i) for i in ids])) + cr.execute("select id from pos_payment where order_id =ANY(%s)",(ids,)) return [i[0] for i in cr.fetchall()] def _sale_journal_get(self, cr, uid, context): diff --git a/addons/point_of_sale/report/pos_lines.py b/addons/point_of_sale/report/pos_lines.py index 1abec66dc80..874c597878e 100644 --- a/addons/point_of_sale/report/pos_lines.py +++ b/addons/point_of_sale/report/pos_lines.py @@ -15,7 +15,7 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # -# You should have received a copy of the GNU General Public License +# You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## @@ -48,7 +48,7 @@ class pos_lines(report_sxw.rml_parse): " LEFT JOIN pos_order_line as pol ON po.id = pol.order_id " \ " LEFT JOIN product_taxes_rel as ptr ON pol.product_id = ptr.prod_id " \ " LEFT JOIN account_tax as acct ON acct.id = ptr.tax_id " \ - " WHERE pol.id = %d" %(obj.id)) + " WHERE pol.id = %s" ,(obj.id,)) res=self.cr.fetchone()[0] return res diff --git a/addons/product/pricelist.py b/addons/product/pricelist.py index 213cc55d953..7e7fcd17790 100644 --- a/addons/product/pricelist.py +++ b/addons/product/pricelist.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). # @@ -15,7 +15,7 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. +# along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## @@ -83,12 +83,12 @@ class product_pricelist(osv.osv): pricelist_type_obj = self.pool.get('product.pricelist.type') pricelist_type_ids = pricelist_type_obj.search(cr, uid, [], order='name') pricelist_types = pricelist_type_obj.read(cr, uid, pricelist_type_ids, ['key','name'], context=context) - + res = [] - + for type in pricelist_types: res.append((type['key'],type['name'])) - + return res # cr.execute('select key,name from product_pricelist_type order by name') # return cr.fetchall() @@ -102,7 +102,7 @@ class product_pricelist(osv.osv): 'currency_id': fields.many2one('res.currency', 'Currency', required=True), 'company_id': fields.many2one('res.company', 'Company'), } - + def name_get(self, cr, uid, ids, context={}): result= [] if not all(ids): @@ -111,7 +111,7 @@ class product_pricelist(osv.osv): name = pl.name + ' ('+ pl.currency_id.name + ')' result.append((pl.id,name)) return result - + def _get_currency(self, cr, uid, ctx): comp = self.pool.get('res.users').browse(cr, uid, uid).company_id @@ -247,6 +247,7 @@ class product_pricelist(osv.osv): if res['price_max_margin']: price = min(price, price_limit+res['price_max_margin']) break + else: # False means no valid line found ! But we may not raise an # exception here because it breaks the search @@ -256,7 +257,7 @@ class product_pricelist(osv.osv): product = product_obj.browse(cr, uid, prod_id) uom = product.uos_id or product.uom_id result[id] = self.pool.get('product.uom')._compute_price(cr, - uid, uom.id, result[id], context['uom']) + uid, uom.id, result[id], context['uom']) return result product_pricelist() @@ -340,16 +341,16 @@ class product_pricelist_item(osv.osv): 'sequence': lambda *a: 5, 'price_discount': lambda *a: 0, } - + def _check_recursion(self, cr, uid, ids): for obj_list in self.browse(cr, uid, ids): if obj_list.base == -1: main_pricelist = obj_list.price_version_id.pricelist_id.id other_pricelist = obj_list.base_pricelist_id.id if main_pricelist == other_pricelist: - return False + return False return True - + _columns = { 'name': fields.char('Rule Name', size=64, help="Explicit rule name for this pricelist line."), 'price_version_id': fields.many2one('product.pricelist.version', 'Price List Version', required=True, select=True), @@ -378,11 +379,11 @@ class product_pricelist_item(osv.osv): 'company_id': fields.related('price_version_id','company_id',type='many2one', readonly=True, relation='res.company', string='Company', store=True) } - + _constraints = [ (_check_recursion, _('Error ! You cannot assign the Main Pricelist as Other Pricelist in PriceList Item!'), ['base_pricelist_id']) ] - + def product_id_change(self, cr, uid, ids, product_id, context={}): if not product_id: return {} diff --git a/addons/product/product.py b/addons/product/product.py index 08729a44d7d..a4a30cba863 100644 --- a/addons/product/product.py +++ b/addons/product/product.py @@ -208,7 +208,7 @@ class product_category(osv.osv): def _check_recursion(self, cr, uid, ids): level = 100 while len(ids): - cr.execute('select distinct parent_id from product_category where id in ('+','.join(map(str, ids))+')') + cr.execute('select distinct parent_id from product_category where id =ANY(%s)',(ids,)) ids = filter(None, map(lambda x:x[0], cr.fetchall())) if not level: return False diff --git a/addons/product_margin/product_margin.py b/addons/product_margin/product_margin.py index 89479095493..1bef9e54047 100644 --- a/addons/product_margin/product_margin.py +++ b/addons/product_margin/product_margin.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). # @@ -15,7 +15,7 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. +# along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## @@ -25,52 +25,48 @@ from tools import config import time class product_product(osv.osv): - _inherit = "product.product" - - + _inherit = "product.product" + + def _product_margin(self, cr, uid, ids, field_names, arg, context): - res = {} + res = {} for val in self.browse(cr, uid, ids,context=context): res[val.id] = {} - date_from=context.get('date_from', time.strftime('%Y-01-01')) - date_to=context.get('date_to', time.strftime('%Y-12-31')) - invoice_state=context.get('invoice_state', 'open_paid') + date_from=context.get('date_from', time.strftime('%Y-01-01')) + date_to=context.get('date_to', time.strftime('%Y-12-31')) + invoice_state=context.get('invoice_state', 'open_paid') if 'date_from' in field_names: res[val.id]['date_from']=date_from if 'date_to' in field_names: res[val.id]['date_to']=date_to if 'invoice_state' in field_names: res[val.id]['invoice_state']=invoice_state - - - invoice_types=[] - states=[] + invoice_types=() + states=() if invoice_state=='paid': - states=['paid'] + states=('paid') elif invoice_state=='open_paid': - states=['open','paid'] + states=('open','paid') elif invoice_state=='draft_open_paid': - states=['draft','open','paid'] - + states=('draft','open','paid') + if 'sale_avg_price' in field_names or 'sale_num_invoiced' in field_names or 'turnover' in field_names or 'sale_expected' in field_names: - invoice_types=['out_invoice','in_refund'] + invoice_types=('out_invoice','in_refund') if 'purchase_avg_price' in field_names or 'purchase_num_invoiced' in field_names or 'total_cost' in field_names or 'normal_cost' in field_names: - invoice_types=['in_invoice','out_refund'] + invoice_types=('in_invoice','out_refund') if len(invoice_types): - sql=""" - select - avg(l.price_unit) as avg_unit_price, - sum(l.quantity) as num_qty, - sum(l.quantity * l.price_unit) as total, - sum(l.quantity * product.list_price) as sale_expected, - sum(l.quantity * product.standard_price) as normal_cost + cr.execute("""select + avg(l.price_unit) as avg_unit_price, + sum(l.quantity) as num_qty, + sum(l.quantity * l.price_unit) as total, + sum(l.quantity * product.list_price) as sale_expected, + sum(l.quantity * product.standard_price) as normal_cost from account_invoice_line l left join account_invoice i on (l.invoice_id = i.id) - left join product_template product on (product.id=l.product_id) - where l.product_id = %s and i.state in ('%s') and i.type in ('%s') and i.date_invoice>='%s' and i.date_invoice<='%s' - """%(val.id,"','".join(states),"','".join(invoice_types),date_from,date_to) - cr.execute(sql) - result=cr.fetchall()[0] + left join product_template product on (product.id=l.product_id) + where l.product_id = %s and i.state in %s and i.type in %s and i.date_invoice>=%s and i.date_invoice<=%s + """,(val.id,states,invoice_types,date_from,date_to)) + result=cr.fetchall()[0] if 'sale_avg_price' in field_names or 'sale_num_invoiced' in field_names or 'turnover' in field_names or 'sale_expected' in field_names: res[val.id]['sale_avg_price']=result[0] and result[0] or 0.0 res[val.id]['sale_num_invoiced']=result[1] and result[1] or 0.0 @@ -82,8 +78,8 @@ class product_product(osv.osv): res[val.id]['purchase_num_invoiced']=result[1] and result[1] or 0.0 res[val.id]['total_cost']=result[2] and result[2] or 0.0 res[val.id]['normal_cost']=result[4] and result[4] or 0.0 - res[val.id]['purchase_gap']=res[val.id]['normal_cost']-res[val.id]['total_cost'] - + res[val.id]['purchase_gap']=res[val.id]['normal_cost']-res[val.id]['total_cost'] + if 'total_margin' in field_names: res[val.id]['total_margin']=val.turnover-val.total_cost if 'expected_margin' in field_names: @@ -91,15 +87,15 @@ class product_product(osv.osv): if 'total_margin_rate' in field_names: res[val.id]['total_margin_rate']=val.turnover and val.total_margin * 100 / val.turnover or 0.0 if 'expected_margin_rate' in field_names: - res[val.id]['expected_margin_rate']=val.sale_expected and val.expected_margin * 100 / val.sale_expected or 0.0 + res[val.id]['expected_margin_rate']=val.sale_expected and val.expected_margin * 100 / val.sale_expected or 0.0 return res - + _columns = { 'date_from': fields.function(_product_margin, method=True, type='date', string='From Date', multi=True), 'date_to': fields.function(_product_margin, method=True, type='date', string='To Date', multi=True), 'invoice_state': fields.function(_product_margin, method=True, type='selection', selection=[ ('paid','Paid'),('open_paid','Open and Paid'),('draft_open_paid','Draft, Open and Paid') - ], string='Invoice State',multi=True, readonly=True), + ], string='Invoice State',multi=True, readonly=True), 'sale_avg_price' : fields.function(_product_margin, method=True, type='float', string='Avg. Unit Price', multi='sale',help="Avg. Price in Customer Invoices)"), 'purchase_avg_price' : fields.function(_product_margin, method=True, type='float', string='Avg. Unit Price', multi='purchase',help="Avg. Price in Supplier Invoices "), 'sale_num_invoiced' : fields.function(_product_margin, method=True, type='float', string='# Invoiced', multi='sale',help="Sum of Quantity in Customer Invoices"), diff --git a/addons/project/project.py b/addons/project/project.py index 36abedd66ba..05a04653d2d 100644 --- a/addons/project/project.py +++ b/addons/project/project.py @@ -76,10 +76,10 @@ class project(osv.osv): FROM project_task WHERE - project_id in ('''+','.join(map(str,ids2))+''') AND + project_id =ANY(%s) AND state<>'cancelled' GROUP BY - project_id''') + project_id''',(ids2,)) progress = dict(map(lambda x: (x[0], (x[1],x[2],x[3])), cr.fetchall())) for project in self.browse(cr, uid, ids, context=context): s = [0.0,0.0,0.0] @@ -173,7 +173,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 in ('+','.join(map(str, ids))+')') + cr.execute('update project_task set active=True where project_id =ANY(%s)',(ids,)) return res def duplicate_template(self, cr, uid, ids,context={}): @@ -222,8 +222,7 @@ class task(osv.osv): # Compute: effective_hours, total_hours, progress def _hours_get(self, cr, uid, ids, field_names, args, context): - task_set = ','.join(map(str, ids)) - cr.execute(("SELECT task_id, COALESCE(SUM(hours),0) FROM project_task_work WHERE task_id in (%s) GROUP BY task_id") % (task_set,)) + cr.execute("SELECT task_id, COALESCE(SUM(hours),0) FROM project_task_work WHERE task_id =ANY(%s) GROUP BY task_id",(ids,)) hours = dict(cr.fetchall()) res = {} for task in self.browse(cr, uid, ids, context=context): diff --git a/addons/purchase/purchase.py b/addons/purchase/purchase.py index c7700a757c1..766c7175201 100644 --- a/addons/purchase/purchase.py +++ b/addons/purchase/purchase.py @@ -111,8 +111,7 @@ class purchase_order(osv.osv): LEFT JOIN stock_picking p on (p.id=m.picking_id) WHERE - p.purchase_id in ('''+','.join(map(str, ids))+''') - GROUP BY m.state, p.purchase_id''') + p.purchase_id = ANY(%s) GROUP BY m.state, p.purchase_id''',(ids,)) for oid,nbr,state in cr.fetchall(): if state=='cancel': continue diff --git a/addons/report_account/report_receivable.py b/addons/report_account/report_receivable.py index 480784c6616..18a8a01bb96 100644 --- a/addons/report_account/report_receivable.py +++ b/addons/report_account/report_receivable.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). # @@ -15,7 +15,7 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. +# along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## @@ -47,7 +47,7 @@ class report_account_receivable(osv.osv): 'credit':fields.float('Credit', readonly=True), } _order = 'name desc' - + def init(self, cr): cr.execute(""" create or replace view report_account_receivable as ( @@ -73,55 +73,54 @@ report_account_receivable() class temp_range(osv.osv): _name = 'temp.range' _description = 'A Temporary table used for Dashboard view' - + _columns = { 'name' : fields.char('Range',size=64) } - -temp_range() - + +temp_range() + class report_aged_receivable(osv.osv): _name = "report.aged.receivable" _description = "Aged Receivable Till Today" _auto = False - + def __init__(self, pool, cr): super(report_aged_receivable, self).__init__(pool, cr) self.called = False - + def fields_view_get(self, cr, user, view_id=None, view_type='form', context=None, toolbar=False, submenu=False): """ To call the init() method timely """ if not self.called: self.init(cr, user) self.called = True # To make sure that init doesn't get called multiple times - + res = super(report_aged_receivable, self).fields_view_get(cr, user, view_id, view_type, context, toolbar=toolbar, submenu=submenu) return res - + def _calc_bal(self, cr, uid, ids, name, args, context): res = {} for period in self.read(cr,uid,ids,['name']): date1,date2 = period['name'].split(' to ') - query = "SELECT SUM(credit-debit) FROM account_move_line AS line, account_account as ac \ + cr.execute("SELECT SUM(credit-debit) FROM account_move_line AS line, account_account as ac \ WHERE (line.account_id=ac.id) AND ac.type='receivable' \ - AND (COALESCE(line.date,date) BETWEEN '%s' AND '%s') \ - AND (reconcile_id IS NULL) AND ac.active"%(str(date2),str(date1)) - cr.execute(query) + AND (COALESCE(line.date,date) BETWEEN %s AND %s) \ + AND (reconcile_id IS NULL) AND ac.active",(str(date2),str(date1),)) amount = cr.fetchone() amount = amount[0] or 0.00 res[period['id']] = amount - + return res - + _columns = { 'name': fields.char('Month Range', size=7, readonly=True), 'balance': fields.function(_calc_bal, method=True, string='Balance', readonly=True), } - + def init(self, cr, uid=1): """ This view will be used in dashboard - The reason writing this code here is, we need to check date range from today to first date of fiscal year. + The reason writing this code here is, we need to check date range from today to first date of fiscal year. """ # ranges = _get_ranges(cr) # Gets the ranges for the x axis of the graph (name column values) pool_obj_fy = pooler.get_pool(cr.dbname).get('account.fiscalyear') @@ -137,18 +136,18 @@ class report_aged_receivable(osv.osv): LIST_RANGES.append(today + " to " + last_month_date.strftime('%Y-%m-%d')) today = (last_month_date- 1).strftime('%Y-%m-%d') last_month_date = mx.DateTime.strptime(today, '%Y-%m-%d') - mx.DateTime.RelativeDateTime(months=1) - + LIST_RANGES.append(today +" to " + fy_start_date.strftime('%Y-%m-%d')) cr.execute('delete from temp_range') - + for range in LIST_RANGES: pooler.get_pool(cr.dbname).get('temp.range').create(cr, uid, {'name':range}) - + cr.execute(""" create or replace view report_aged_receivable as ( select id,name from temp_range )""") - + report_aged_receivable() class report_invoice_created(osv.osv): @@ -183,7 +182,7 @@ class report_invoice_created(osv.osv): 'create_date' : fields.datetime('Create Date', readonly=True) } _order = 'create_date' - + def init(self, cr): cr.execute("""create or replace view report_invoice_created as ( select @@ -213,13 +212,13 @@ class report_account_type_sales(osv.osv): 'product_id': fields.many2one('product.product', 'Product',readonly=True), 'quantity': fields.float('Quantity', readonly=True), 'user_type': fields.many2one('account.account.type', 'Account Type', readonly=True), - 'amount_total': fields.float('Total', readonly=True), + 'amount_total': fields.float('Total', readonly=True), 'currency_id': fields.many2one('res.currency', 'Currency', readonly=True), 'month':fields.selection([('01','January'), ('02','February'), ('03','March'), ('04','April'), ('05','May'), ('06','June'), - ('07','July'), ('08','August'), ('09','September'), ('10','October'), ('11','November'), ('12','December')],'Month',readonly=True), + ('07','July'), ('08','August'), ('09','September'), ('10','October'), ('11','November'), ('12','December')],'Month',readonly=True), } _order = 'name desc,amount_total desc' - + def init(self, cr): tools.drop_view_if_exists(cr, 'report_account_type_sales') cr.execute("""create or replace view report_account_type_sales as ( @@ -227,20 +226,20 @@ class report_account_type_sales(osv.osv): min(inv_line.id) as id, to_char(inv.date_invoice, 'YYYY') as name, to_char(inv.date_invoice,'MM') as month, - sum(inv_line.price_subtotal) as amount_total, - inv.currency_id as currency_id, + sum(inv_line.price_subtotal) as amount_total, + inv.currency_id as currency_id, inv.period_id, - inv_line.product_id, - sum(inv_line.quantity) as quantity, + inv_line.product_id, + sum(inv_line.quantity) as quantity, account.user_type from - account_invoice_line inv_line + account_invoice_line inv_line inner join account_invoice inv on inv.id = inv_line.invoice_id inner join account_account account on account.id = inv_line.account_id where inv.state in ('open','paid') group by - to_char(inv.date_invoice, 'YYYY'),to_char(inv.date_invoice,'MM'),inv.currency_id, inv.period_id, inv_line.product_id, account.user_type + to_char(inv.date_invoice, 'YYYY'),to_char(inv.date_invoice,'MM'),inv.currency_id, inv.period_id, inv_line.product_id, account.user_type )""") report_account_type_sales() @@ -255,34 +254,34 @@ class report_account_sales(osv.osv): 'product_id': fields.many2one('product.product', 'Product',readonly=True), 'quantity': fields.float('Quantity', readonly=True), 'account_id': fields.many2one('account.account', 'Account', readonly=True), - 'amount_total': fields.float('Total', readonly=True), + 'amount_total': fields.float('Total', readonly=True), 'currency_id': fields.many2one('res.currency', 'Currency', readonly=True), 'month':fields.selection([('01','January'), ('02','February'), ('03','March'), ('04','April'), ('05','May'), ('06','June'), - ('07','July'), ('08','August'), ('09','September'), ('10','October'), ('11','November'), ('12','December')],'Month',readonly=True), + ('07','July'), ('08','August'), ('09','September'), ('10','October'), ('11','November'), ('12','December')],'Month',readonly=True), } _order = 'name desc,amount_total desc' - + def init(self, cr): tools.drop_view_if_exists(cr, 'report_account_sales') cr.execute("""create or replace view report_account_sales as ( select min(inv_line.id) as id, to_char(inv.date_invoice, 'YYYY') as name, - to_char(inv.date_invoice,'MM') as month, - sum(inv_line.price_subtotal) as amount_total, - inv.currency_id as currency_id, + to_char(inv.date_invoice,'MM') as month, + sum(inv_line.price_subtotal) as amount_total, + inv.currency_id as currency_id, inv.period_id, - inv_line.product_id, - sum(inv_line.quantity) as quantity, + inv_line.product_id, + sum(inv_line.quantity) as quantity, account.id as account_id from - account_invoice_line inv_line + account_invoice_line inv_line inner join account_invoice inv on inv.id = inv_line.invoice_id inner join account_account account on account.id = inv_line.account_id where inv.state in ('open','paid') group by - to_char(inv.date_invoice, 'YYYY'),to_char(inv.date_invoice,'MM'),inv.currency_id, inv.period_id, inv_line.product_id, account.id + to_char(inv.date_invoice, 'YYYY'),to_char(inv.date_invoice,'MM'),inv.currency_id, inv.period_id, inv_line.product_id, account.id )""") report_account_sales() diff --git a/addons/report_analytic_planning/report_analytic_planning.py b/addons/report_analytic_planning/report_analytic_planning.py index 3f9c77f253b..96e6dd94bca 100644 --- a/addons/report_analytic_planning/report_analytic_planning.py +++ b/addons/report_analytic_planning/report_analytic_planning.py @@ -16,7 +16,7 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. +# along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## @@ -47,7 +47,7 @@ class one2many_mod3(fields.one2many): class report_account_analytic_planning(osv.osv): _name = "report_account_analytic.planning" _description = "Planning" - + def _get_total_planned(self, cr, uid, ids, name, args, context): result = {} for plan in self.browse(cr, uid, ids, context): @@ -58,7 +58,7 @@ class report_account_analytic_planning(osv.osv): plan_hrs = plan_hrs + p.plan_open + p.plan_tasks result[plan.id] = plan_hrs return result - + def _get_total_free(self, cr, uid, ids, name, args, context): result = {} for plan in self.browse(cr, uid, ids, context): @@ -68,15 +68,15 @@ class report_account_analytic_planning(osv.osv): total_free = total_free + p.free result[plan.id] = total_free return result - + def _check_planning_responsible(self, cr, uid, ids, context={}): for obj_plan in self.browse(cr,uid,ids): cr.execute(""" - SELECT id FROM report_account_analytic_planning plan + SELECT id FROM report_account_analytic_planning plan WHERE ( (%(date_from)s BETWEEN date_from AND date_to) OR (%(date_to)s BETWEEN date_from AND date_to) OR (%(date_from)s < date_from AND %(date_to)s > date_to) - ) AND user_id = %(uid)s AND id <> %(id)s""", + ) AND user_id = %(uid)s AND id <> %(id)s""", {"date_from": obj_plan.date_from, "date_to": obj_plan.date_to, "uid": obj_plan.user_id.id, @@ -87,31 +87,31 @@ class report_account_analytic_planning(osv.osv): if res: return False return True - + _columns = { - 'name': fields.char('Planning Name', required=True, size=32, states={'done':[('readonly', True)]}), - 'code': fields.char('Code', size=32, states={'done':[('readonly', True)]}), - 'user_id': fields.many2one('res.users', 'Responsible', required=True, states={'done':[('readonly', True)]}), - 'date_from':fields.date('Start Date', required=True, states={'done':[('readonly', True)]}), - 'date_to':fields.date('End Date', required=True, states={'done':[('readonly', True)]}), - 'line_ids': fields.one2many('report_account_analytic.planning.line', 'planning_id', 'Planning lines', states={'done':[('readonly', True)]}), - 'stat_ids': fields.one2many('report_account_analytic.planning.stat', 'planning_id', 'Planning analysis', readonly=True), - 'state': fields.selection([('draft','Draft'),('open', 'Open'), ('done', 'Done'),('cancel','Cancelled')], 'Status', required=True), + 'name': fields.char('Planning Name', required=True, size=32, states={'done':[('readonly', True)]}), + 'code': fields.char('Code', size=32, states={'done':[('readonly', True)]}), + 'user_id': fields.many2one('res.users', 'Responsible', required=True, states={'done':[('readonly', True)]}), + 'date_from':fields.date('Start Date', required=True, states={'done':[('readonly', True)]}), + 'date_to':fields.date('End Date', required=True, states={'done':[('readonly', True)]}), + 'line_ids': fields.one2many('report_account_analytic.planning.line', 'planning_id', 'Planning lines', states={'done':[('readonly', True)]}), + 'stat_ids': fields.one2many('report_account_analytic.planning.stat', 'planning_id', 'Planning analysis', readonly=True), + 'state': fields.selection([('draft','Draft'),('open', 'Open'), ('done', 'Done'),('cancel','Cancelled')], 'Status', required=True), 'business_days' : fields.integer('Business Days', required=True, states={'done':[('readonly', True)]}, help='Set here the number of working days within this planning for one person full time'), 'planning_user_ids': one2many_mod3('report_account_analytic.planning.user', 'planning_id', 'Planning By User'), - 'planning_account': fields.one2many('report_account_analytic.planning.account', 'planning_id', 'Planning By Account'), - 'total_planned' : fields.function(_get_total_planned, method=True, string='Total Planned'), + 'planning_account': fields.one2many('report_account_analytic.planning.account', 'planning_id', 'Planning By Account'), + 'total_planned' : fields.function(_get_total_planned, method=True, string='Total Planned'), 'total_free' : fields.function(_get_total_free, method=True, string='Total Free'), } _defaults = { - 'date_from': lambda *a: time.strftime('%Y-%m-01'), - 'date_to': lambda *a: (mx.DateTime.now()+mx.DateTime.RelativeDateTime(months=1, day=1, days=-1)).strftime('%Y-%m-%d'), - 'user_id': lambda self, cr, uid, c: uid, - 'state': lambda *args: 'draft', - 'business_days' : lambda *a: 20, + 'date_from': lambda *a: time.strftime('%Y-%m-01'), + 'date_to': lambda *a: (mx.DateTime.now()+mx.DateTime.RelativeDateTime(months=1, day=1, days=-1)).strftime('%Y-%m-%d'), + 'user_id': lambda self, cr, uid, c: uid, + 'state': lambda *args: 'draft', + 'business_days' : lambda *a: 20, } _order = 'date_from desc' - + _constraints = [ (_check_planning_responsible, 'Invalid planning ! Planning dates can\'t overlap for the same responsible. ', ['user_id']) ] @@ -123,15 +123,15 @@ class report_account_analytic_planning(osv.osv): def action_cancel(self, cr, uid, id, context={}): self.write(cr, uid, id, {'state' : 'cancel'}) return True - + def action_draft(self, cr, uid, id, context={}): self.write(cr, uid, id, {'state' : 'draft'}) return True - + def action_done(self, cr, uid, id, context={}): self.write(cr, uid, id, {'state' : 'done'}) return True - + report_account_analytic_planning() class report_account_analytic_planning_line(osv.osv): @@ -167,17 +167,17 @@ class report_account_analytic_planning_line(osv.osv): return result _columns = { - 'account_id':fields.many2one('account.analytic.account', 'Analytic account', required=True), - 'planning_id': fields.many2one('report_account_analytic.planning', 'Planning', required=True, ondelete='cascade'), - 'user_id': fields.many2one('res.users', 'User'), - 'amount': fields.float('Quantity', required=True), - 'amount_unit': fields.many2one('product.uom', 'Qty UoM', required=True), - 'note': fields.text('Note', size=64), + 'account_id':fields.many2one('account.analytic.account', 'Analytic account', required=True), + 'planning_id': fields.many2one('report_account_analytic.planning', 'Planning', required=True, ondelete='cascade'), + 'user_id': fields.many2one('res.users', 'User'), + 'amount': fields.float('Quantity', required=True), + 'amount_unit': fields.many2one('product.uom', 'Qty UoM', required=True), + 'note': fields.text('Note', size=64), 'amount_in_base_uom': fields.function(_amount_base_uom, method=True, string='Quantity in base uom', store=True), - 'task_ids': fields.one2many('project.task', 'planning_line_id', 'Planning Tasks'), + 'task_ids': fields.one2many('project.task', 'planning_line_id', 'Planning Tasks'), } _order = 'user_id,account_id' - + report_account_analytic_planning_line() class account_analytic_account(osv.osv): @@ -187,16 +187,16 @@ class account_analytic_account(osv.osv): _columns = { 'planning_ids': fields.one2many('report_account_analytic.planning.line', 'account_id', 'Plannings'), } - + account_analytic_account() - + class project_task(osv.osv): _name = "project.task" _inherit = "project.task" _columns = { - 'planning_line_id': fields.many2one('report_account_analytic.planning.line', 'Planning', ondelete='cascade'), + 'planning_line_id': fields.many2one('report_account_analytic.planning.line', 'Planning', ondelete='cascade'), } - + def search(self, cr, user, args, offset=0, limit=None, order=None, context=None, count=False): if not context: context = {} @@ -205,10 +205,10 @@ class project_task(osv.osv): cr.execute(" SELECT t.id, t.name \ from project_task t \ join report_account_analytic_planning_line l on (l.id = t.planning_line_id )\ - where l.planning_id=%s" % context.get('planning')) + where l.planning_id=%s",(context.get('planning'),)) ids = map(lambda x: x[0], cr.fetchall()) return ids - + project_task() @@ -217,8 +217,8 @@ class report_account_analytic_planning_user(osv.osv): _description = "Planning by User" _rec_name = 'user_id' _auto = False - - + + def _get_tasks(self, cr, uid, ids, name, args, context): result = {} tm = self.pool.get('res.users').browse(cr, uid, uid, context).company_id.project_time_mode_id @@ -236,7 +236,7 @@ class report_account_analytic_planning_user(osv.osv): cr.execute("""select COALESCE(sum(tasks.remaining_hours),0) from project_task tasks \ where tasks.planning_line_id in (select id from report_account_analytic_planning_line\ where planning_id = %s and user_id=%s)""", (line.planning_id.id, line.user_id.id,)) - + result[line.id] = cr.fetchall()[0][0] / div * div2 else: result[line.id] = 0 @@ -246,11 +246,11 @@ class report_account_analytic_planning_user(osv.osv): result = {} for line in self.browse(cr, uid, ids, context): if line.user_id: - result[line.id] = line.planning_id.business_days - line.plan_tasks - line.plan_open - line.holiday + result[line.id] = line.planning_id.business_days - line.plan_tasks - line.plan_open - line.holiday else: result[line.id] = 0.0 return result - + def _get_timesheets(self, cr, uid, ids, name, args, context): result = {} tm2 = self.pool.get('res.users').browse(cr, uid, uid, context).company_id.planning_time_mode_id @@ -261,7 +261,7 @@ class report_account_analytic_planning_user(osv.osv): for line in self.browse(cr, uid, ids, context): if line.user_id: cr.execute(""" - SELECT sum(unit_amount/uom.factor) FROM account_analytic_line acc + SELECT sum(unit_amount/uom.factor) FROM account_analytic_line acc LEFT JOIN product_uom uom ON (uom.id = acc.product_uom_id) WHERE acc.date>=%s and acc.date<=%s and acc.user_id=%s""", (line.planning_id.date_from, line.planning_id.date_to, line.user_id.id )) res = cr.fetchall() @@ -271,54 +271,54 @@ class report_account_analytic_planning_user(osv.osv): return result _columns = { - 'planning_id': fields.many2one('report_account_analytic.planning', 'Planning'), - 'user_id': fields.many2one('res.users', 'User', readonly=True), - 'tasks' : fields.function(_get_tasks, method=True, string='Remaining Tasks', help='This value is given by the sum of work remaining to do on the task for this planning, expressed in days.'), - 'plan_tasks': fields.float('Time Planned on Tasks', readonly=True, help='This value is given by the sum of time allocation with task(s) linked, expressed in days.'), + 'planning_id': fields.many2one('report_account_analytic.planning', 'Planning'), + 'user_id': fields.many2one('res.users', 'User', readonly=True), + 'tasks' : fields.function(_get_tasks, method=True, string='Remaining Tasks', help='This value is given by the sum of work remaining to do on the task for this planning, expressed in days.'), + 'plan_tasks': fields.float('Time Planned on Tasks', readonly=True, help='This value is given by the sum of time allocation with task(s) linked, expressed in days.'), 'free' : fields.function(_get_free, method=True, string='Unallocated Time', readonly=True,help='Computed as \ -Business Days - (Time Allocation of Tasks + Time Allocation without Tasks + Holiday Leaves)'), - 'plan_open': fields.float('Time Allocation without Tasks', readonly=True,help='This value is given by the sum of time allocation without task(s) linked, expressed in days.'), - 'holiday': fields.float('Leaves',help='This value is given by the total of validated leaves into the \'Date From\' and \'Date To\' of the planning.'), - 'timesheet': fields.function(_get_timesheets, method=True, string='Timesheet', help='This value is given by the sum of all work encoded in the timesheet(s) between the \'Date From\' and \'Date To\' of the planning.'), +Business Days - (Time Allocation of Tasks + Time Allocation without Tasks + Holiday Leaves)'), + 'plan_open': fields.float('Time Allocation without Tasks', readonly=True,help='This value is given by the sum of time allocation without task(s) linked, expressed in days.'), + 'holiday': fields.float('Leaves',help='This value is given by the total of validated leaves into the \'Date From\' and \'Date To\' of the planning.'), + 'timesheet': fields.function(_get_timesheets, method=True, string='Timesheet', help='This value is given by the sum of all work encoded in the timesheet(s) between the \'Date From\' and \'Date To\' of the planning.'), } - + def init(self, cr): cr.execute(""" CREATE OR REPLACE VIEW report_account_analytic_planning_user AS ( - SELECT + SELECT planning.id AS planning_id, planning.id::varchar(32) || '-' || COALESCE(users.id,0)::varchar(32) AS id, planning.business_days, users.id AS user_id, - (SELECT sum(line1.amount_in_base_uom) + (SELECT sum(line1.amount_in_base_uom) FROM report_account_analytic_planning_line line1 WHERE ( - SELECT COUNT(1) - FROM project_task task + SELECT COUNT(1) + FROM project_task task WHERE task.planning_line_id = line1.id - ) > 0 - AND line1.user_id = users.id + ) > 0 + AND line1.user_id = users.id AND line1.planning_id = planning.id )AS plan_tasks, - (SELECT SUM(line1.amount_in_base_uom) + (SELECT SUM(line1.amount_in_base_uom) FROM report_account_analytic_planning_line line1 WHERE ( - SELECT COUNT(1) - FROM project_task task + SELECT COUNT(1) + FROM project_task task WHERE task.planning_line_id = line1.id - ) = 0 - AND line1.user_id = users.id + ) = 0 + AND line1.user_id = users.id AND line1.planning_id = planning.id ) AS plan_open, (SELECT -(SUM(holidays.number_of_days)) - FROM hr_holidays holidays - WHERE holidays.employee_id IN + FROM hr_holidays holidays + WHERE holidays.employee_id IN ( SELECT emp.id FROM hr_employee emp, resource_resource res WHERE emp.resource_id = res.id and res.user_id = users.id ) AND holidays.state IN ('validate') - AND holidays.type = 'remove' - AND holidays.date_from >= planning.date_from + AND holidays.type = 'remove' + AND holidays.date_from >= planning.date_from AND holidays.date_to <= planning.date_to ) AS holiday @@ -333,32 +333,32 @@ Business Days - (Time Allocation of Tasks + Time Allocation without Tasks + Holi planning.id::varchar(32) || '-' || '0' AS id, planning.business_days, line.user_id, - (SELECT SUM(line1.amount_in_base_uom) + (SELECT SUM(line1.amount_in_base_uom) FROM report_account_analytic_planning_line line1 - WHERE (SELECT COUNT(1) FROM project_task task WHERE task.planning_line_id = line1.id) > 0 + WHERE (SELECT COUNT(1) FROM project_task task WHERE task.planning_line_id = line1.id) > 0 AND line1.user_id IS NULL ) AS plan_tasks, - (SELECT SUM(line1.amount_in_base_uom) + (SELECT SUM(line1.amount_in_base_uom) FROM report_account_analytic_planning_line line1 - WHERE (SELECT COUNT(1) FROM project_task task WHERE task.planning_line_id = line1.id) = 0 + WHERE (SELECT COUNT(1) FROM project_task task WHERE task.planning_line_id = line1.id) = 0 AND line1.user_id IS NULL ) AS plan_open, '0' AS holiday - FROM report_account_analytic_planning planning - INNER JOIN report_account_analytic_planning_line line ON line.planning_id = planning.id + FROM report_account_analytic_planning planning + INNER JOIN report_account_analytic_planning_line line ON line.planning_id = planning.id AND line.user_id IS NULL GROUP BY planning.id, planning.business_days, line.user_id, planning.date_from, planning.date_to ) """) report_account_analytic_planning_user() - + class report_account_analytic_planning_account(osv.osv): _name = "report_account_analytic.planning.account" _description = "Planning by Account" _rec_name = 'account_id' _auto = False - + def _get_tasks(self, cr, uid, ids, name, args, context): result = {} tm = self.pool.get('res.users').browse(cr, uid, uid, context).company_id.project_time_mode_id @@ -373,16 +373,16 @@ class report_account_analytic_planning_account(osv.osv): div2 = 1.0 for line in self.browse(cr, uid, ids, context): cr.execute(""" - SELECT COALESCE(sum(tasks.remaining_hours),0) - FROM project_task tasks + SELECT COALESCE(sum(tasks.remaining_hours),0) + FROM project_task tasks WHERE tasks.planning_line_id IN ( - SELECT id + SELECT id FROM report_account_analytic_planning_line WHERE planning_id = %s AND account_id=%s )""", (line.planning_id.id,line.account_id.id )) result[line.id] = cr.fetchall()[0][0] / div *div2 return result - + def _get_timesheets(self, cr, uid, ids, name, args, context): result = {} tm2 = self.pool.get('res.users').browse(cr, uid, uid, context).company_id.planning_time_mode_id @@ -392,7 +392,7 @@ class report_account_analytic_planning_account(osv.osv): div2 = 1.0 for line in self.browse(cr, uid, ids, context): cr.execute(""" - SELECT SUM(unit_amount/uom.factor) FROM account_analytic_line acc + SELECT SUM(unit_amount/uom.factor) FROM account_analytic_line acc LEFT JOIN product_uom uom ON (uom.id = acc.product_uom_id) WHERE acc.date>=%s and acc.date<=%s and acc.account_id=%s""", (line.planning_id.date_from, line.planning_id.date_to, line.account_id.id, )) res = cr.fetchall()[0][0] @@ -403,38 +403,38 @@ class report_account_analytic_planning_account(osv.osv): return result _columns = { - 'planning_id': fields.many2one('report_account_analytic.planning', 'Planning'), - 'account_id': fields.many2one('account.analytic.account', 'Analytic account', readonly=True), - 'tasks' : fields.function(_get_tasks, method=True, string='Remaining Tasks', help='This value is given by the sum of work remaining to do on the task for this planning, expressed in days.'), - 'plan_tasks': fields.float('Time Allocation of Tasks', readonly=True,help='This value is given by the sum of time allocation with the checkbox \'Assigned in Taks\' set to TRUE expressed in days.'), - 'plan_open': fields.float('Time Allocation without Tasks', readonly=True,help='This value is given by the sum of time allocation with the checkbox \'Assigned in Taks\' set to FALSE, expressed in days.'), - 'timesheet': fields.function(_get_timesheets, method=True, string='Timesheet',help='This value is given by the sum of all work encoded in the timesheet(s) between the \'Date From\' and \'Date To\' of the planning.'), + 'planning_id': fields.many2one('report_account_analytic.planning', 'Planning'), + 'account_id': fields.many2one('account.analytic.account', 'Analytic account', readonly=True), + 'tasks' : fields.function(_get_tasks, method=True, string='Remaining Tasks', help='This value is given by the sum of work remaining to do on the task for this planning, expressed in days.'), + 'plan_tasks': fields.float('Time Allocation of Tasks', readonly=True,help='This value is given by the sum of time allocation with the checkbox \'Assigned in Taks\' set to TRUE expressed in days.'), + 'plan_open': fields.float('Time Allocation without Tasks', readonly=True,help='This value is given by the sum of time allocation with the checkbox \'Assigned in Taks\' set to FALSE, expressed in days.'), + 'timesheet': fields.function(_get_timesheets, method=True, string='Timesheet',help='This value is given by the sum of all work encoded in the timesheet(s) between the \'Date From\' and \'Date To\' of the planning.'), } - + def init(self, cr): cr.execute(""" CREATE OR REPLACE VIEW report_account_analytic_planning_account AS ( - SELECT + SELECT MIN(l.id) AS id, l.account_id AS account_id, SUM(l.amount) AS quantity, l.planning_id AS planning_id, - ( SELECT SUM(line1.amount_in_base_uom) + ( SELECT SUM(line1.amount_in_base_uom) FROM report_account_analytic_planning_line line1 - WHERE - ( SELECT COUNT(1) - FROM project_task task + WHERE + ( SELECT COUNT(1) + FROM project_task task WHERE task.planning_line_id = line1.id - ) > 0 + ) > 0 AND l.account_id = line1.account_id AND l.planning_id = line1.planning_id ) AS plan_tasks, - ( SELECT SUM(line1.amount_in_base_uom) + ( SELECT SUM(line1.amount_in_base_uom) FROM report_account_analytic_planning_line line1 - WHERE - ( SELECT COUNT(1) - FROM project_task task + WHERE + ( SELECT COUNT(1) + FROM project_task task WHERE task.planning_line_id = line1.id - ) = 0 + ) = 0 AND l.account_id = line1.account_id AND planning.id = line1.planning_id ) AS plan_open @@ -443,8 +443,8 @@ class report_account_analytic_planning_account(osv.osv): GROUP BY l.account_id, l.planning_id, planning.date_from, planning.date_to, planning.id ) """) - - + + report_account_analytic_planning_account() class report_account_analytic_planning_stat(osv.osv): @@ -454,7 +454,7 @@ class report_account_analytic_planning_stat(osv.osv): _auto = False _log_access = False _order = 'planning_id,user_id' - + def _sum_amount_real(self, cr, uid, ids, name, args, context): result = {} tm2 = self.pool.get('res.users').browse(cr, uid, uid, context).company_id.planning_time_mode_id @@ -471,7 +471,7 @@ where user_id=%s and account_id=%s and date>=%s and date<=%s''', (line.user_id.i cr.execute('select sum(unit_amount) from account_analytic_line where account_id=%s and date>=%s and date<=%s', (line.account_id.id, line.planning_id.date_from, line.planning_id.date_to)) result[line.id] = cr.fetchone()[0] * div2 return result - + def _sum_amount_tasks(self, cr, uid, ids, name, args, context): result = {} tm = self.pool.get('res.users').browse(cr, uid, uid, context).company_id.project_time_mode_id @@ -497,23 +497,23 @@ where user_id=%s and account_id=%s and date>=%s and date<=%s''', (line.user_id.i project_id in (select id from project_project where category_id=%s) and date_close>=%s and date_close<=%s''', ( - line.account_id.id, - line.planning_id.date_from, + line.account_id.id, + line.planning_id.date_from, line.planning_id.date_to) ) result[line.id] = cr.fetchone()[0] /div * div2 return result - + _columns = { - 'planning_id': fields.many2one('report_account_analytic.planning', 'Planning'), - 'user_id': fields.many2one('res.users', 'User'), - 'manager_id': fields.many2one('res.users', 'Manager'), - 'account_id': fields.many2one('account.analytic.account', 'Account', required=True), - 'sum_amount': fields.float('Planned Days', required=True), - 'sum_amount_real': fields.function(_sum_amount_real, method=True, string='Timesheet'), - 'sum_amount_tasks': fields.function(_sum_amount_tasks, method=True, string='Tasks'), + 'planning_id': fields.many2one('report_account_analytic.planning', 'Planning'), + 'user_id': fields.many2one('res.users', 'User'), + 'manager_id': fields.many2one('res.users', 'Manager'), + 'account_id': fields.many2one('account.analytic.account', 'Account', required=True), + 'sum_amount': fields.float('Planned Days', required=True), + 'sum_amount_real': fields.function(_sum_amount_real, method=True, string='Timesheet'), + 'sum_amount_tasks': fields.function(_sum_amount_tasks, method=True, string='Tasks'), } - + def init(self, cr): cr.execute(""" create or replace view report_account_analytic_planning_stat as ( @@ -541,7 +541,7 @@ class res_company(osv.osv): _columns = { 'planning_time_mode_id': fields.many2one('product.uom', 'Planning Time Unit', help='This will set the unit of measure used in plannings.', - + ), } res_company() diff --git a/addons/report_crm/report_crm.py b/addons/report_crm/report_crm.py index b0ab10b82d8..f49d0fe7b28 100644 --- a/addons/report_crm/report_crm.py +++ b/addons/report_crm/report_crm.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). # @@ -15,7 +15,7 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. +# along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## @@ -149,7 +149,7 @@ class report_crm_case_service_dashboard(osv.osv): where (cse.state='done') OR - + ((to_date(to_char(cse.create_date, 'YYYY-MM-dd'),'YYYY-MM-dd') <= CURRENT_DATE) AND (to_date(to_char(cse.create_date, 'YYYY-MM-dd'),'YYYY-MM-dd') > (CURRENT_DATE-15)) diff --git a/addons/report_task/report_task.py b/addons/report_task/report_task.py index ff6590689f8..dd2772b970e 100644 --- a/addons/report_task/report_task.py +++ b/addons/report_task/report_task.py @@ -91,11 +91,11 @@ class report_closed_task(osv.osv): tsk.date_deadline as date_deadline, tsk.planned_hours as planned_hours, tsk.delay_hours as delay_hours, tsk.progress as progress, tsk.priority as priority, tsk.state as state, - tsk.remaining_hours as remaining_hours, tsk.date_close as date_close + tsk.remaining_hours as remaining_hours, tsk.date_end as date_close from project_task tsk where - (tsk.date_close <= CURRENT_DATE AND tsk.date_close > (CURRENT_DATE-15)) + (tsk.date_end <= CURRENT_DATE AND tsk.date_end > (CURRENT_DATE-15)) ) ''') report_closed_task() diff --git a/addons/sale/sale.py b/addons/sale/sale.py index 5f6e0db3448..77768207dbe 100644 --- a/addons/sale/sale.py +++ b/addons/sale/sale.py @@ -99,8 +99,7 @@ class sale_order(osv.osv): LEFT JOIN stock_picking p on (p.id=m.picking_id) WHERE - p.sale_id in ('''+','.join(map(str, ids))+''') - GROUP BY m.state, p.sale_id''') + p.sale_id = ANY(%s) GROUP BY m.state, p.sale_id''',(ids,)) for oid, nbr, state in cr.fetchall(): if state == 'cancel': continue @@ -297,7 +296,7 @@ class sale_order(osv.osv): def action_cancel_draft(self, cr, uid, ids, *args): if not len(ids): return False - cr.execute('select id from sale_order_line where order_id in ('+','.join(map(str, ids))+')', ('draft',)) + cr.execute('select id from sale_order_line where order_id = ANY(%s) and state=%s',(ids,'cancel')) line_ids = map(lambda x: x[0], cr.fetchall()) self.write(cr, uid, ids, {'state': 'draft', 'invoice_ids': [], 'shipped': 0}) self.pool.get('sale.order.line').write(cr, uid, line_ids, {'invoiced': False, 'state': 'draft', 'invoice_lines': [(6, 0, [])]}) diff --git a/addons/scrum/report/_burndown.py b/addons/scrum/report/_burndown.py index a1be43ef993..246a4072ecc 100644 --- a/addons/scrum/report/_burndown.py +++ b/addons/scrum/report/_burndown.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). # @@ -15,7 +15,7 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. +# along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## @@ -26,14 +26,13 @@ import time def compute_burndown(cr, uid, tasks_id, date_start, date_stop): latest = False if len(tasks_id): - cr.execute('select id,create_date,state,planned_hours from project_task where id in ('+','.join(map(str,tasks_id))+') order by create_date') + cr.execute('select id,create_date,state,planned_hours from project_task where id = ANY(%s) order by create_date',(tasks_id,)) tasks = cr.fetchall() - cr.execute('select w.date,w.hours from project_task_work w left join project_task t on (t.id=w.task_id) where t.id in ('+','.join(map(str,tasks_id))+') and t.state in (\'open\',\'progress\') order by date') - + cr.execute('select w.date,w.hours from project_task_work w left join project_task t on (t.id=w.task_id) where t.id = ANY(%s) and t.state in (%s,%s) order by date',(tasks_id,'open','progress',)) tasks2 = cr.fetchall() - cr.execute('select date_close,planned_hours from project_task where id in ('+','.join(map(str,tasks_id))+') and state in (\'cancelled\',\'done\') order by date_close') + cr.execute('select date_close,planned_hours from project_task where id =ANY(%s) and state in (%s,%s) order by date_close' ,(tasks_id,'cancelled','done',)) tasks2 += cr.fetchall() tasks2.sort() else: diff --git a/addons/scrum/report/task_burndown.py b/addons/scrum/report/task_burndown.py index ddb3173c963..fe91c6eed61 100644 --- a/addons/scrum/report/task_burndown.py +++ b/addons/scrum/report/task_burndown.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). # @@ -15,7 +15,7 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. +# along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## @@ -42,9 +42,10 @@ class external_pdf(render): def burndown_chart(cr, uid, tasks_id, date_start, date_stop): latest = False - cr.execute('select id,date_start,state,planned_hours from project_task where id in ('+','.join(map(str,tasks_id))+') order by date_start') + + cr.execute('select id,date_start,state,planned_hours from project_task where id = ANY(%s) order by date_start'(tasks_id,)) tasks = cr.fetchall() - cr.execute('select id,date_close,state,planned_hours*progress/100 from project_task where id in ('+','.join(map(str,tasks_id))+') and state in (%s,%s) order by date_close', ('progress','done')) + cr.execute('select id,date_close,state,planned_hours*progress/100 from project_task where id =ANY(%s) and state in (%s,%s) order by date_close', (tasks_id,'progress','done',)) tasks2 = cr.fetchall() current_date = date_start total = 0 @@ -71,14 +72,14 @@ class report_tasks(report_int): io = StringIO.StringIO() if 'date_start' not in datas: - cr.execute('select min(date_start) from project_task where id in ('+','.join(map(str, ids))+')') + cr.execute('select min(date_start) from project_task where id = ANY(%s)',(ids,)) dt = cr.fetchone()[0] if dt: datas['date_start'] = dt[:10] else: datas['date_start'] = time.strftime('%Y-%m-%d') if 'date_stop' not in datas: - cr.execute('select max(date_start),max(date_close) from project_task where id in ('+','.join(map(str, ids))+')') + cr.execute('select max(date_start),max(date_close) from project_task where id = ANY(%s)',(ids,)) res = cr.fetchone() datas['date_stop'] = (res[0] and res[0][:10]) or time.strftime('%Y-%m-%d') if res[1] and datas['date_stop']<res[1]: diff --git a/addons/stock/product.py b/addons/stock/product.py index 13131583a1c..3e789fa7ecd 100644 --- a/addons/stock/product.py +++ b/addons/stock/product.py @@ -73,16 +73,12 @@ class product_product(osv.osv): else: location_ids= location_ids - states_str = ','.join(map(lambda s: "'%s'" % s, states)) - uoms_o = {} product2uom = {} for product in self.browse(cr, uid, ids, context=context): product2uom[product.id] = product.uom_id.id uoms_o[product.uom_id.id] = product.uom_id - prod_ids_str = ','.join(map(str, ids)) - location_ids_str = ','.join(map(str, location_ids)) results = [] results2 = [] @@ -101,12 +97,11 @@ class product_product(osv.osv): cr.execute( 'select sum(product_qty), product_id, product_uom '\ 'from stock_move '\ - 'where ' +\ - (location_ids_str and 'location_id not in ('+location_ids_str+') ' \ - 'and location_dest_id in ('+location_ids_str+') ' or 'true ') +\ - 'and product_id in ('+prod_ids_str+') '\ - 'and state in ('+states_str+') '+ (date_str and 'and '+date_str+' ' or ' ') +''\ - 'group by product_id,product_uom' + 'where location_id <> ANY(%s)'\ + 'and location_dest_id =ANY(%s)'\ + 'and product_id =ANY(%s)'\ + 'and state in %s' + (date_str and 'and '+date_str+' ' or '') +''\ + 'group by product_id,product_uom',(location_ids,location_ids,ids,tuple(states),) ) results = cr.fetchall() if 'out' in what: @@ -114,12 +109,11 @@ class product_product(osv.osv): cr.execute( 'select sum(product_qty), product_id, product_uom '\ 'from stock_move '\ - 'where ' +\ - (location_ids_str and 'location_id in ('+location_ids_str+') '\ - 'and location_dest_id not in ('+location_ids_str+') ' or 'true ') +\ - 'and product_id in ('+prod_ids_str+') '\ - 'and state in ('+states_str+') '+ (date_str and 'and '+date_str+' ' or '') + ''\ - 'group by product_id,product_uom' + 'where location_id = ANY(%s)'\ + 'and location_dest_id <> ANY(%s) '\ + 'and product_id =ANY(%s)'\ + 'and state in %s' + (date_str and 'and '+date_str+' ' or '') + ''\ + 'group by product_id,product_uom',(location_ids,location_ids,ids,tuple(states),) ) results2 = cr.fetchall() uom_obj = self.pool.get('product.uom') diff --git a/addons/stock/report/product_stock.py b/addons/stock/report/product_stock.py index 79a6c91de22..49c1daef8ed 100644 --- a/addons/stock/report/product_stock.py +++ b/addons/stock/report/product_stock.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). # @@ -15,7 +15,7 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. +# along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## @@ -35,7 +35,7 @@ class external_pdf(render): render.__init__(self) self.pdf = pdf self.output_type='pdf' - + def _render(self): return self.pdf @@ -68,17 +68,12 @@ class report_stock(report_int): if not loc_ids or not product_ids: return (False, 'pdf') - loc_ids_s = ",".join(['%s']*len(loc_ids)) - prod_ids_s = ",".join(['%s']*len(product_ids)) - cr.execute("select sum(r.product_qty * u.factor), r.date_planned, r.product_id " "from stock_move r left join product_uom u on (r.product_uom=u.id) " - "where state in ('confirmed','assigned','waiting') " - "and location_id in (%s) " - "and product_id in (%s) " - "group by date_planned,product_id" % (loc_ids_s, prod_ids_s), - loc_ids + product_ids) - + "where state in %s" + "and location_id=ANY(%s)" + "and product_id=ANY(%s)" + "group by date_planned,product_id",(('confirmed','assigned','waiting'),loc_ids ,product_ids,)) for (qty, dt, prod_id) in cr.fetchall(): if dt<=dt_from: dt= (DateTime.now() + DateTime.RelativeDateTime(days=1)).strftime('%Y-%m-%d') @@ -89,11 +84,10 @@ class report_stock(report_int): cr.execute("select sum(r.product_qty * u.factor), r.date_planned, r.product_id " "from stock_move r left join product_uom u on (r.product_uom=u.id) " - "where state in ('confirmed','assigned','waiting') " - "and location_dest_id in (%s) " - "and product_id in (%s) " - "group by date_planned,product_id" % (loc_ids_s, prod_ids_s), - loc_ids + product_ids) + "where state in %s" + "and location_dest_id=ANY(%s)" + "and product_id=ANY(%s)" + "group by date_planned,product_id",(('confirmed','assigned','waiting'),loc_ids ,product_ids,)) for (qty, dt, prod_id) in cr.fetchall(): if dt<=dt_from: diff --git a/addons/stock/stock.py b/addons/stock/stock.py index 1ea6aa998b2..8e8fed554fc 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -421,9 +421,9 @@ class stock_picking(osv.osv): from stock_move where - picking_id in (""" + ','.join(map(str, ids)) + """) + picking_id=ANY(%s) group by - picking_id""") + picking_id""",(ids,)) for pick, dt1, dt2 in cr.fetchall(): res[pick]['min_date'] = dt1 res[pick]['max_date'] = dt2 @@ -860,7 +860,6 @@ class stock_production_lot(osv.osv): ids = [ids] res = {}.fromkeys(ids, 0.0) - if locations: cr.execute('''select prodlot_id, @@ -868,11 +867,7 @@ class stock_production_lot(osv.osv): from stock_report_prodlots where - location_id in ('''+','.join(map(str, locations))+''') and - prodlot_id in ('''+','.join(map(str, ids))+''') - group by - prodlot_id - ''') + location_id =ANY(%s) and prodlot_id =ANY(%s) group by prodlot_id''',(locations,ids,)) res.update(dict(cr.fetchall())) return res @@ -884,11 +879,8 @@ class stock_production_lot(osv.osv): from stock_report_prodlots where - location_id in ('''+','.join(map(str, locations)) + ''') - group by - prodlot_id - having sum(name) ''' + str(args[0][1]) + ''' ''' + str(args[0][2]) - ) + location_id =ANY(%s) group by prodlot_id + having sum(name) '''+ str(args[0][1]) + str(args[0][2]),(locations,)) res = cr.fetchall() ids = [('id', 'in', map(lambda x: x[0], res))] return ids diff --git a/addons/stock/wizard/inventory_merge_zero.py b/addons/stock/wizard/inventory_merge_zero.py index 890deb786e6..1da7b5e2a61 100644 --- a/addons/stock/wizard/inventory_merge_zero.py +++ b/addons/stock/wizard/inventory_merge_zero.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). # @@ -15,7 +15,7 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. +# along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## @@ -56,7 +56,7 @@ def do_merge(self, cr, uid, data, context): cr.execute('select distinct location_id,product_id from stock_inventory_line where inventory_id=%s', (data['ids'][0],)) inv = cr.fetchall() - cr.execute('select distinct product_id from stock_move where (location_dest_id='+loc+') or (location_id='+loc+')') + cr.execute('select distinct product_id from stock_move where location_dest_id=%s or location_id=%s',(loc,loc,)) stock = cr.fetchall() for s in stock: if (loc,s[0]) not in inv: diff --git a/addons/wiki/wizard/make_index.py b/addons/wiki/wizard/make_index.py index 06d787c2a68..09a3b5de4ac 100644 --- a/addons/wiki/wizard/make_index.py +++ b/addons/wiki/wizard/make_index.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). # @@ -15,7 +15,7 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. +# along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## @@ -34,10 +34,7 @@ def wiki_do_index(self, cr, uid, data, context): ids = data['ids'] pool = pooler.get_pool(cr.dbname) wiki_pool = pool.get('wiki.wiki') - - iid = ','.join([str(x) for x in ids]) - sSQL = "Select id, section from wiki_wiki where id in (%s) order by section " % (iid) - cr.execute(sSQL) + cr.execute("Select id, section from wiki_wiki where id = ANY(%s) order by section " ,(ids,)) lst0 = cr.fetchall() lst = [] ids = {} @@ -52,9 +49,9 @@ def wiki_do_index(self, cr, uid, data, context): return int(x) except: return 1 - + lst = map(lambda x: map(toint, x.split('.')), lst) - + result = [] current = ['0'] current2 = [] @@ -69,7 +66,7 @@ def wiki_do_index(self, cr, uid, data, context): current = current[:pos + 1] if pos == len(l) - 1: break - + key = ('.'.join([str(x) for x in l])) id = ids[key] val = ('.'.join([str(x) for x in current[:]]), id) @@ -77,22 +74,21 @@ def wiki_do_index(self, cr, uid, data, context): if val: result.append(val) current2 = l - + for rs in result: wiki_pool.write(cr, uid, [rs[1]], {'section':rs[0]}) - return {} class make_index(wizard.interface): states = { 'init': { - 'actions': [], + 'actions': [], 'result': {'type':'form', 'arch':section_form, 'fields':{}, 'state':[('end','Cancel'),('yes','Create Index')]} }, 'yes': { - 'actions': [wiki_do_index], + 'actions': [wiki_do_index], 'result': { - 'type':'state', + 'type':'state', 'state':'end' } } |
