small changes - (Viral Rami)
bzr revid: patelamit2003@gmail.com-20081104124801-ymm1j43zdj827c0j
This commit is contained in:
parent
4926e9a9d0
commit
7afcbc79ee
|
@ -1,7 +1,7 @@
|
|||
# -*- encoding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved
|
||||
# $Id$
|
||||
#
|
||||
|
@ -61,81 +61,81 @@ class partner_balance(report_sxw.rml_parse):
|
|||
for date in date_array:
|
||||
full_str_date.append(str(date))
|
||||
return full_str_date
|
||||
|
||||
|
||||
#
|
||||
|
||||
|
||||
|
||||
|
||||
def transform_period_into_date_array(self,data):
|
||||
## Get All Period Date
|
||||
#
|
||||
# If we have no period we will take all perdio in the FiscalYear.
|
||||
|
||||
|
||||
|
||||
|
||||
if not data['form']['periods'][0][2] :
|
||||
periods_id = self.pool.get('account.period').search(self.cr, self.uid, [('fiscalyear_id','=',data['form']['fiscalyear'])])
|
||||
else:
|
||||
periods_id = data['form']['periods'][0][2]
|
||||
date_array = []
|
||||
date_array = []
|
||||
for period_id in periods_id:
|
||||
period_obj = self.pool.get('account.period').browse(self.cr, self.uid, period_id)
|
||||
date_array = date_array + self.date_range(period_obj.date_start,period_obj.date_stop)
|
||||
self.date_lst = date_array
|
||||
self.date_lst.sort()
|
||||
|
||||
|
||||
|
||||
|
||||
def transform_date_into_date_array(self,data):
|
||||
return_array = self.date_range(data['form']['date1'],data['form']['date2'])
|
||||
self.date_lst = return_array
|
||||
self.date_lst.sort()
|
||||
|
||||
|
||||
def transform_both_into_date_array(self,data):
|
||||
if not data['form']['periods'][0][2] :
|
||||
periods_id = self.pool.get('account.period').search(self.cr, self.uid, [('fiscalyear_id','=',data['form']['fiscalyear'])])
|
||||
else:
|
||||
periods_id = data['form']['periods'][0][2]
|
||||
date_array = []
|
||||
date_array = []
|
||||
for period_id in periods_id:
|
||||
period_obj = self.pool.get('account.period').browse(self.cr, self.uid, period_id)
|
||||
date_array = date_array + self.date_range(period_obj.date_start,period_obj.date_stop)
|
||||
|
||||
|
||||
period_start_date = date_array[0]
|
||||
date_start_date = data['form']['date1']
|
||||
period_stop_date = date_array[-1]
|
||||
date_stop_date = data['form']['date2']
|
||||
|
||||
|
||||
if period_start_date<date_start_date:
|
||||
start_date = period_start_date
|
||||
else :
|
||||
start_date = date_start_date
|
||||
|
||||
|
||||
if date_stop_date<period_stop_date:
|
||||
stop_date = period_stop_date
|
||||
else :
|
||||
stop_date = date_stop_date
|
||||
|
||||
|
||||
|
||||
|
||||
final_date_array = []
|
||||
final_date_array = final_date_array + self.date_range(start_date,stop_date)
|
||||
self.date_lst = final_date_array
|
||||
self.date_lst.sort()
|
||||
|
||||
|
||||
def transform_none_into_date_array(self,data):
|
||||
|
||||
|
||||
sql = "SELECT min(date) as start_date from account_move_line"
|
||||
self.cr.execute(sql)
|
||||
start_date = self.cr.fetchone()[0]
|
||||
|
||||
|
||||
sql = "SELECT max(date) as start_date from account_move_line"
|
||||
self.cr.execute(sql)
|
||||
stop_date = self.cr.fetchone()[0]
|
||||
|
||||
|
||||
|
||||
|
||||
array = []
|
||||
array = array + self.date_range(start_date,stop_date)
|
||||
self.date_lst = array
|
||||
self.date_lst.sort()
|
||||
|
||||
|
||||
|
||||
|
||||
def comma_me(self,amount):
|
||||
if type(amount) is float :
|
||||
amount = str('%.2f'%amount)
|
||||
|
@ -149,27 +149,27 @@ class partner_balance(report_sxw.rml_parse):
|
|||
return new
|
||||
else:
|
||||
return self.comma_me(new)
|
||||
|
||||
|
||||
def preprocess(self, objects, data, ids):
|
||||
# Transformation des date
|
||||
#
|
||||
#
|
||||
if data['form']['state'] == 'none':
|
||||
|
||||
|
||||
self.transform_none_into_date_array(data)
|
||||
elif data['form']['state'] == 'bydate':
|
||||
|
||||
|
||||
self.transform_date_into_date_array(data)
|
||||
elif data['form']['state'] == 'byperiod':
|
||||
|
||||
|
||||
self.transform_period_into_date_array(data)
|
||||
elif data['form']['state'] == 'all':
|
||||
|
||||
self.transform_both_into_date_array(data)
|
||||
|
||||
|
||||
|
||||
# if data['form']['fiscalyear']:
|
||||
|
||||
self.transform_both_into_date_array(data)
|
||||
|
||||
|
||||
|
||||
# if data['form']['fiscalyear']:
|
||||
# print"data['form']['fiscalyear']=True"
|
||||
# self.transform_period_into_date_array(data)
|
||||
# else:
|
||||
|
@ -195,7 +195,7 @@ class partner_balance(report_sxw.rml_parse):
|
|||
"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()])
|
||||
|
||||
|
||||
super(partner_balance, self).preprocess(objects, data, ids)
|
||||
|
||||
def lines(self,data):
|
||||
|
@ -208,8 +208,8 @@ class partner_balance(report_sxw.rml_parse):
|
|||
#
|
||||
#
|
||||
if data['form']['soldeinit'] :
|
||||
|
||||
|
||||
|
||||
|
||||
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) " \
|
||||
|
@ -234,13 +234,13 @@ class partner_balance(report_sxw.rml_parse):
|
|||
"ORDER BY l.account_id,p.name",
|
||||
(self.date_lst[0],self.date_lst[0]))
|
||||
res = self.cr.dictfetchall()
|
||||
|
||||
|
||||
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) " \
|
||||
|
@ -264,10 +264,10 @@ class partner_balance(report_sxw.rml_parse):
|
|||
"GROUP BY p.id, p.ref, p.name,l.account_id,ac.name,ac.code " \
|
||||
"ORDER BY l.account_id,p.name")
|
||||
res = self.cr.dictfetchall()
|
||||
|
||||
print "============ res",res
|
||||
for r in res:
|
||||
full_account.append(r)
|
||||
|
||||
|
||||
## We will now compute Total
|
||||
return self._add_subtotal(full_account)
|
||||
|
||||
|
@ -303,7 +303,7 @@ class partner_balance(report_sxw.rml_parse):
|
|||
#
|
||||
r['type'] = 1
|
||||
r['balance'] = float(r['sdebit']) - float(r['scredit'])
|
||||
|
||||
|
||||
completearray.append(r)
|
||||
#
|
||||
tot_debit = r['debit']
|
||||
|
@ -319,7 +319,7 @@ class partner_balance(report_sxw.rml_parse):
|
|||
# new_tot['ref'] = 'Total'
|
||||
# new_tot['name'] = cleanarray[i-1]['account_name']
|
||||
# new_tot['code'] = cleanarray[i-1]['code']
|
||||
#
|
||||
#
|
||||
# new_tot['debit'] = tot_debit
|
||||
# new_tot['credit'] = tot_credit
|
||||
# new_tot['scredit'] = tot_scredit
|
||||
|
@ -329,9 +329,9 @@ 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
|
||||
|
@ -339,12 +339,14 @@ 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
|
||||
# we reset the counter
|
||||
# we reset the counter
|
||||
tot_debit = r['debit']
|
||||
tot_credit = r['credit']
|
||||
tot_scredit = r['scredit']
|
||||
tot_sdebit = r['sdebit']
|
||||
tot_enlitige = (r['enlitige'] or 0.0)
|
||||
|
||||
print "========= tot_debit",tot_debit
|
||||
#
|
||||
##
|
||||
new_header = {}
|
||||
|
@ -360,36 +362,54 @@ class partner_balance(report_sxw.rml_parse):
|
|||
new_header['type'] = 3
|
||||
##
|
||||
##
|
||||
|
||||
print "========= new_header['debit']",new_header['debit']
|
||||
completearray.append(new_header)
|
||||
##
|
||||
##
|
||||
#
|
||||
r['type'] = 1
|
||||
#
|
||||
r['balance'] = float(r['sdebit']) - float(r['scredit'])
|
||||
|
||||
|
||||
#
|
||||
|
||||
print "=========r",r
|
||||
completearray.append(r)
|
||||
|
||||
|
||||
if cleanarray[i]['account_id'] == cleanarray[i-1]['account_id']:
|
||||
# we reset the counter
|
||||
|
||||
# we reset the counter
|
||||
|
||||
new_header['debit'] = tot_debit
|
||||
new_header['credit'] = tot_credit
|
||||
new_header['scredit'] = tot_scredit
|
||||
new_header['sdebit'] = tot_sdebit
|
||||
new_header['enlitige'] = tot_enlitige
|
||||
new_header['balance'] = float(tot_sdebit) - float(tot_scredit)
|
||||
new_header['type'] = 3
|
||||
|
||||
tot_debit = tot_debit + r['debit']
|
||||
tot_credit = tot_credit + r['credit']
|
||||
tot_scredit = tot_scredit + r['scredit']
|
||||
tot_sdebit = tot_sdebit + r['sdebit']
|
||||
tot_enlitige = tot_enlitige + (r['enlitige'] or 0.0)
|
||||
|
||||
new_header['debit'] = tot_debit
|
||||
new_header['credit'] = tot_credit
|
||||
new_header['scredit'] = tot_scredit
|
||||
new_header['sdebit'] = tot_sdebit
|
||||
new_header['enlitige'] = tot_enlitige
|
||||
new_header['balance'] = float(tot_sdebit) - float(tot_scredit)
|
||||
|
||||
#
|
||||
r['type'] = 2
|
||||
#
|
||||
r['balance'] = float(r['sdebit']) - float(r['scredit'])
|
||||
#
|
||||
|
||||
print "========= new_header['debit']=====tot_debit",new_header['debit'],tot_debit
|
||||
|
||||
print "RRRRRRRRRRRR 22222222222222",r
|
||||
completearray.append(r)
|
||||
|
||||
|
||||
i = i + 1
|
||||
|
||||
|
||||
return completearray
|
||||
|
||||
|
||||
|
@ -400,7 +420,7 @@ class partner_balance(report_sxw.rml_parse):
|
|||
result_tmp = 0.0
|
||||
#
|
||||
#
|
||||
|
||||
|
||||
if data['form']['soldeinit'] :
|
||||
self.cr.execute(
|
||||
"SELECT sum(debit) " \
|
||||
|
@ -418,14 +438,14 @@ class partner_balance(report_sxw.rml_parse):
|
|||
"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 not self.ids:
|
||||
return 0.0
|
||||
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
|
||||
|
||||
|
||||
result_tmp = 0.0
|
||||
#
|
||||
#
|
||||
|
@ -445,9 +465,9 @@ class partner_balance(report_sxw.rml_parse):
|
|||
"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):
|
||||
|
@ -455,7 +475,7 @@ class partner_balance(report_sxw.rml_parse):
|
|||
return 0.0
|
||||
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
|
||||
result_tmp = 0.0
|
||||
|
||||
|
||||
#
|
||||
#
|
||||
if data['form']['soldeinit'] :
|
||||
|
@ -477,7 +497,7 @@ class partner_balance(report_sxw.rml_parse):
|
|||
"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):
|
||||
|
@ -485,7 +505,7 @@ class partner_balance(report_sxw.rml_parse):
|
|||
return 0.0
|
||||
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
|
||||
result_tmp = 0.0
|
||||
|
||||
|
||||
#
|
||||
#
|
||||
if data['form']['soldeinit'] :
|
||||
|
@ -500,7 +520,7 @@ class partner_balance(report_sxw.rml_parse):
|
|||
"AND l.reconcile_id IS NULL " \
|
||||
"GROUP BY l.partner_id",
|
||||
(self.date_lst[0],))
|
||||
|
||||
|
||||
if self.cr.fetchone() != None:
|
||||
result_tmp = float(self.cr.fetchone()[0])
|
||||
else:
|
||||
|
@ -517,20 +537,20 @@ class partner_balance(report_sxw.rml_parse):
|
|||
"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
|
||||
|
||||
return result_tmp
|
||||
|
||||
return result_tmp
|
||||
|
||||
def _sum_scredit(self,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
|
||||
#
|
||||
#
|
||||
|
@ -546,7 +566,7 @@ class partner_balance(report_sxw.rml_parse):
|
|||
"AND l.reconcile_id IS NULL " \
|
||||
"GROUP BY l.partner_id",
|
||||
(self.date_lst[0],))
|
||||
|
||||
|
||||
if self.cr.fetchone() != None:
|
||||
result_tmp = float(self.cr.fetchone()[0]) or 0.0
|
||||
else:
|
||||
|
@ -565,16 +585,16 @@ class partner_balance(report_sxw.rml_parse):
|
|||
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
|
||||
|
||||
|
||||
return result_tmp
|
||||
|
||||
|
||||
def _solde_balance_debit(self,data):
|
||||
debit, credit = self._sum_debit(data), self._sum_credit(data)
|
||||
return debit > credit and debit - credit
|
||||
|
||||
|
||||
def _solde_balance_credit(self,data):
|
||||
debit, credit = self._sum_debit(data), self._sum_credit(data)
|
||||
return credit > debit and credit - debit
|
||||
|
@ -587,4 +607,4 @@ class partner_balance(report_sxw.rml_parse):
|
|||
|
||||
report_sxw.report_sxw('report.account.partner.balance', 'res.partner',
|
||||
'account/report/partner_balance.rml',parser=partner_balance,
|
||||
header=False)
|
||||
header=False)
|
Loading…
Reference in New Issue