diff --git a/addons/account/report/partner_balance.py b/addons/account/report/partner_balance.py index cf55c5f153f..b1fa9ae24b0 100644 --- a/addons/account/report/partner_balance.py +++ b/addons/account/report/partner_balance.py @@ -36,6 +36,7 @@ class partner_balance(report_sxw.rml_parse): super(partner_balance, self).__init__(cr, uid, name, context) self.date_lst = [] self.date_lst_string = '' + self.account_ids = '' self.localcontext.update( { 'time': time, 'lines': self.lines, @@ -191,16 +192,15 @@ class partner_balance(report_sxw.rml_parse): else: 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 t.partner_account = TRUE ' \ - 'AND a.company_id = %d ' \ - 'AND a.type IN ' + self.ACCOUNT_TYPE + " " \ - 'AND a.active', (data['form']['company_id'],)) + 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 = %d " \ + "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()]) - + print"self.account_ids",self.account_ids super(partner_balance, self).preprocess(objects, data, ids) def lines(self,data): @@ -208,16 +208,13 @@ class partner_balance(report_sxw.rml_parse): account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line') full_account = [] result_tmp = 0.0 - if data['form']['result_selection']=='all': - a1=('receivable','payable') - elif data['form']['result_selection']=='customer': - a1=('receivable','') - elif data['form']['result_selection']=='supplier': - a1=('payable','') + # # # if data['form']['soldeinit'] : + print"=====self.account_ids======",self.account_ids + self.cr.execute( "SELECT p.ref, p.name,l.account_id,ac.name as account_name,ac.code as code , sum(debit) as debit, sum(credit) as credit, " \ "CASE WHEN sum(debit) > sum(credit) " \ @@ -236,20 +233,19 @@ 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 %s " \ + "WHERE ac.type IN " + self.ACCOUNT_TYPE + " " \ "AND l.date < %s AND l.reconcile_id IS NULL " \ "GROUP BY p.id, p.ref, p.name,l.account_id,ac.name,ac.code " \ "ORDER BY l.account_id,p.name", - (self.date_lst[0],a1,self.date_lst[0])) + (self.date_lst[0],self.date_lst[0])) res = self.cr.dictfetchall() - + print":::::::::::::::::::::res",res for r in res: full_account.append(r) # # # - +# self.cr.execute( "SELECT p.ref,l.account_id,ac.name as account_name,ac.code as code ,p.name, sum(debit) as debit, sum(credit) as credit, " \ "CASE WHEN sum(debit) > sum(credit) " \ @@ -268,13 +264,12 @@ 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 %s " \ + "WHERE ac.type IN " + self.ACCOUNT_TYPE + " " \ "AND l.date IN (" + self.date_lst_string + ") " \ "GROUP BY p.id, p.ref, p.name,l.account_id,ac.name,ac.code " \ - "ORDER BY l.account_id,p.name",(a1,)) + "ORDER BY l.account_id,p.name") res = self.cr.dictfetchall() - + print"==========res",res for r in res: full_account.append(r) @@ -289,10 +284,7 @@ class partner_balance(report_sxw.rml_parse): tot_scredit = 0.0 tot_sdebit = 0.0 tot_enlitige = 0.0 - tot_d=0.0 - print "WWW",cleanarray for r in cleanarray: - print "r",r # For the first element we always add the line # type = 1 is the line is the first of the account # type = 2 is an other line of the account @@ -312,12 +304,10 @@ class partner_balance(report_sxw.rml_parse): new_header['balance'] = float(tot_sdebit) - float(tot_scredit) new_header['type'] = 3 ## - print "33", new_header completearray.append(new_header) # r['type'] = 1 r['balance'] = float(r['sdebit']) - float(r['scredit']) - print "LEVEL1", r completearray.append(r) # @@ -344,6 +334,8 @@ class partner_balance(report_sxw.rml_parse): # new_tot['type'] = 3 # ## # completearray.append(new_tot) + + new_header['debit'] = tot_debit new_header['credit'] = tot_credit new_header['scredit'] = tot_scredit @@ -370,16 +362,20 @@ class partner_balance(report_sxw.rml_parse): new_header['enlitige'] = tot_enlitige new_header['balance'] = float(tot_sdebit) - float(tot_scredit) new_header['type'] = 3 - print "NEW GEA", new_header ## ## + completearray.append(new_header) ## # r['type'] = 1 # r['balance'] = float(r['sdebit']) - float(r['scredit']) - print "RR LEVEEL1",r + tot_debit = r['debit'] + tot_credit = r['credit'] + tot_scredit = r['scredit'] + tot_sdebit = r['sdebit'] + tot_enlitige = (r['enlitige'] or 0.0) # completearray.append(r) @@ -395,67 +391,44 @@ class partner_balance(report_sxw.rml_parse): r['type'] = 2 # r['balance'] = float(r['sdebit']) - float(r['scredit']) - print "LEVELE2",i,r # completearray.append(r) - print "fin",i + i = i + 1 return completearray def _sum_debit(self,data): - print "daa",data if not self.ids: return 0.0 account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line') result_tmp = 0.0 # # - if data['form']['result_selection']=='all': - a1=('receivable','payable') - elif data['form']['result_selection']=='customer': - a1=('receivable','') - elif data['form']['result_selection']=='supplier': - a1=('payable','') - + if data['form']['soldeinit'] : self.cr.execute( - 'SELECT sum(debit) ' \ - 'FROM account_move_line AS l left join account_account ac ON (l.account_id = ac.id)' \ - 'WHERE ' \ - ' ac.type IN %s ' \ - 'AND l.reconcile_id IS NULL ' \ - 'AND date < %s ', - (a1,self.date_lst[0],)) - - v_res = self.cr.fetchone() - if v_res and v_res != None: - result_tmp = float(v_res[0] or 0.0) - else: - result_tmp = 0.0 + "SELECT sum(debit) " \ + "FROM account_move_line AS l " \ + "WHERE l.account_id IN (" + self.account_ids + ") " \ + "AND l.reconcile_id IS NULL " \ + "AND date < %s ", + (self.date_lst[0],)) + result_tmp = float(self.cr.fetchone()[0] or 0.0) # # self.cr.execute( - 'SELECT sum(debit) ' \ - 'FROM account_move_line AS l left join account_account ac ON (l.account_id = ac.id)' \ - 'WHERE ' \ -# ' account_id IN (' + self.account_ids + ') ' \ - ' ac.type IN %s ' \ - 'AND l.date IN (' + self.date_lst_string + ') ',(a1,) ) + "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 + ") " ) result_tmp = result_tmp + float(self.cr.fetchone()[0] or 0.0) return result_tmp def _sum_credit(self,data): - if data['form']['result_selection']=='all': - a1=('receivable','payable') - elif data['form']['result_selection']=='customer': - a1=('receivable','') - elif data['form']['result_selection']=='supplier': - a1=('payable','') - if not self.ids: return 0.0 account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line') @@ -465,35 +438,26 @@ class partner_balance(report_sxw.rml_parse): # if data['form']['soldeinit'] : self.cr.execute( - 'SELECT sum(credit) ' \ - 'FROM account_move_line AS l left join account_account ac ON (l.account_id = ac.id)' \ - 'WHERE ' \ - ' ac.type IN %s ' \ - 'AND l.reconcile_id IS NULL ' \ - 'AND date < %s ' , - (a1,self.date_lst[0],)) + "SELECT sum(credit) " \ + "FROM account_move_line AS l " \ + "WHERE l.account_id IN (" + self.account_ids + ") " \ + "AND l.reconcile_id IS NULL " \ + "AND l.date < %s " , + (self.date_lst[0],)) result_tmp = float(self.cr.fetchone()[0] or 0.0) # # self.cr.execute( - 'SELECT sum(credit) ' \ - 'FROM account_move_line AS l left join account_account ac ON (l.account_id = ac.id)' \ - 'WHERE ' \ -# ' account_id IN (' + self.account_ids + ') ' \ - ' ac.type IN %s ' \ - 'AND l.date IN (' + self.date_lst_string + ') ',(a1,) ) + "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 + ") " ) result_tmp = result_tmp + float(self.cr.fetchone()[0] or 0.0) return result_tmp def _sum_litige(self,data): - if data['form']['result_selection']=='all': - a1=('receivable','payable') - elif data['form']['result_selection']=='customer': - a1=('receivable','') - elif data['form']['result_selection']=='supplier': - a1=('payable','') if not self.ids: return 0.0 account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line') @@ -503,36 +467,27 @@ class partner_balance(report_sxw.rml_parse): # if data['form']['soldeinit'] : self.cr.execute( - 'SELECT sum(debit-credit) ' \ - 'FROM account_move_line AS l left join account_account ac ON (l.account_id = ac.id)' \ - 'WHERE ' \ -# ' account_id IN (' + self.account_ids + ') ' \ - ' l.reconcile_id IS NULL ' \ - 'AND ac.type IN %s ' \ - 'AND date < %s ' \ - 'AND blocked=TRUE ' , - (a1,self.date_lst[0],)) + "SELECT sum(debit-credit) " \ + "FROM account_move_line AS l " \ + "WHERE l.account_id IN (" + self.account_ids + ") " \ + "AND l.reconcile_id IS NULL " \ + "AND l.date < %s " \ + "AND l.blocked=TRUE " , + (self.date_lst[0],)) result_tmp = float(self.cr.fetchone()[0] or 0.0) # # self.cr.execute( - 'SELECT sum(debit-credit) ' \ - 'FROM account_move_line AS l left join account_account ac ON (l.account_id = ac.id)' \ - 'WHERE ' \ - 'ac.type IN %s ' \ - 'AND l.date IN (' + self.date_lst_string + ') ' \ - 'AND blocked=TRUE ',(a1,) ) + "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 " ) result_tmp = result_tmp + float(self.cr.fetchone()[0] or 0.0) return result_tmp def _sum_sdebit(self,data): - if data['form']['result_selection']=='all': - a1=('receivable','payable') - elif data['form']['result_selection']=='customer': - a1=('receivable','') - elif data['form']['result_selection']=='supplier': - a1=('payable','') if not self.ids: return 0.0 account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line') @@ -542,38 +497,36 @@ class partner_balance(report_sxw.rml_parse): # if data['form']['soldeinit'] : self.cr.execute( - 'SELECT CASE WHEN sum(debit) > sum(credit) ' \ - 'THEN sum(debit) - sum(credit) ' \ - 'ELSE 0 ' \ - 'END ' \ - 'FROM account_move_line AS l left join account_account ac ON (l.account_id = ac.id)' \ - 'WHERE ' \ - 'ac.type IN %s ' \ - 'AND date < %s ' \ - 'AND reconcile_id IS NULL ' \ - 'GROUP BY partner_id', - (a1,self.date_lst[0],)) + "SELECT CASE WHEN sum(debit) > sum(credit) " \ + "THEN sum(debit) - sum(credit) " \ + "ELSE 0 " \ + "END " \ + "FROM account_move_line AS l " \ + "WHERE l.account_id IN (" + self.account_ids + ") " \ + "AND l.date < %s " \ + "AND l.reconcile_id IS NULL " \ + "GROUP BY l.partner_id", + (self.date_lst[0],)) - v_res = self.cr.fetchone() - if v_res != None : - result_tmp = float(v_res[0]) or 0.0 + if self.cr.fetchone() != None: + result_tmp = float(self.cr.fetchone()[0]) else: result_tmp = 0.0 # # self.cr.execute( - 'SELECT CASE WHEN sum(debit) > sum(credit) ' \ - 'THEN sum(debit) - sum(credit) ' \ - 'ELSE 0 ' \ - 'END ' \ - 'FROM account_move_line AS l left join account_account ac ON (l.account_id = ac.id)' \ - 'WHERE ' \ - ' ac.type IN %s ' \ - 'AND l.date IN (' + self.date_lst_string + ') ' \ - 'GROUP BY partner_id',(a1,)) - v_res = self.cr.fetchone() - if v_res != None: - result_tmp = result_tmp + ( v_res[0] or 0.0) + "SELECT CASE WHEN sum(debit) > sum(credit) " \ + "THEN sum(debit) - sum(credit) " \ + "ELSE 0 " \ + "END " \ + "FROM account_move_line AS l " \ + "WHERE l.account_id IN (" + self.account_ids + ") " \ + "AND l.date IN (" + self.date_lst_string + ") " \ + "GROUP BY l.partner_id") + a = self.cr.fetchone()[0] + + if self.cr.fetchone() != None: + result_tmp = result_tmp + (a or 0.0) else: result_tmp = 0.0 @@ -581,12 +534,6 @@ class partner_balance(report_sxw.rml_parse): def _sum_scredit(self,data): - if data['form']['result_selection']=='all': - a1=('receivable','payable') - elif data['form']['result_selection']=='customer': - a1=('receivable','') - elif data['form']['result_selection']=='supplier': - a1=('payable','') if not self.ids: return 0.0 account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line') @@ -596,38 +543,35 @@ class partner_balance(report_sxw.rml_parse): # if data['form']['soldeinit'] : self.cr.execute( - 'SELECT CASE WHEN sum(debit) < sum(credit) ' \ - 'THEN sum(credit) - sum(debit) ' \ - 'ELSE 0 ' \ - 'END ' \ - 'FROM account_move_line AS l left join account_account ac ON (l.account_id = ac.id)' \ - 'WHERE ' \ - ' ac.type IN %s ' \ - 'AND date <= %s ' \ - 'AND l.reconcile_id IS NULL ' \ - 'GROUP BY partner_id', - (a1,self.date_lst[0],)) + "SELECT CASE WHEN sum(debit) < sum(credit) " \ + "THEN sum(credit) - sum(debit) " \ + "ELSE 0 " \ + "END " \ + "FROM account_move_line AS l " \ + "WHERE l.account_id IN (" + self.account_ids + ") " \ + "AND l.date <= %s " \ + "AND l.reconcile_id IS NULL " \ + "GROUP BY l.partner_id", + (self.date_lst[0],)) - v_res = self.cr.fetchone() - if v_res != None: - result_tmp = float(v_res[0]) or 0.0 + if self.cr.fetchone() != None: + result_tmp = float(self.cr.fetchone()[0]) or 0.0 else: result_tmp = 0.0 # # self.cr.execute( - 'SELECT CASE WHEN sum(debit) < sum(credit) ' \ - 'THEN sum(credit) - sum(debit) ' \ - 'ELSE 0 ' \ - 'END ' \ - 'FROM account_move_line AS l left join account_account ac ON (l.account_id = ac.id)' \ - 'WHERE ' \ - ' ac.type IN %s ' \ - ' AND l.date IN (' + self.date_lst_string + ') ' \ - 'GROUP BY partner_id',(a1,)) - a = self.cr.fetchone() - if a != None : - result_tmp = result_tmp + (a[0] or 0.0) + "SELECT CASE WHEN sum(debit) < sum(credit) " \ + "THEN sum(credit) - sum(debit) " \ + "ELSE 0 " \ + "END " \ + "FROM account_move_line AS l " \ + "WHERE l.account_id IN (" + self.account_ids + ") " \ + "AND l.date IN (" + self.date_lst_string + ") " \ + "GROUP BY l.partner_id") + a = self.cr.fetchone()[0] or 0.0 + if self.cr.fetchone() != None: + result_tmp = result_tmp + (a or 0.0) else: result_tmp = 0.0