Partner balance report completed....(Viral Rami)

bzr revid: patelamit2003@gmail.com-20081103125038-3b6dvg1akj7ngr4o
This commit is contained in:
apa-tiny 2008-11-03 18:20:38 +05:30
parent 90692d975b
commit 695f9329df
1 changed files with 109 additions and 165 deletions

View File

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