2009-10-13 05:58:37 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2006-12-07 13:41:40 +00:00
|
|
|
##############################################################################
|
2009-10-14 11:15:34 +00:00
|
|
|
#
|
2008-11-04 12:48:01 +00:00
|
|
|
# OpenERP, Open Source Management Solution
|
2009-10-14 11:15:34 +00:00
|
|
|
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
|
2006-12-07 13:41:40 +00:00
|
|
|
#
|
2008-11-03 19:18:56 +00:00
|
|
|
# This program is free software: you can redistribute it and/or modify
|
2009-10-14 11:15:34 +00:00
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
# License, or (at your option) any later version.
|
2006-12-07 13:41:40 +00:00
|
|
|
#
|
2008-11-03 19:18:56 +00:00
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2009-10-14 11:15:34 +00:00
|
|
|
# GNU Affero General Public License for more details.
|
2006-12-07 13:41:40 +00:00
|
|
|
#
|
2009-10-14 11:15:34 +00:00
|
|
|
# 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/>.
|
2006-12-07 13:41:40 +00:00
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
import pooler
|
|
|
|
import time
|
2008-10-06 09:46:37 +00:00
|
|
|
import re
|
|
|
|
import datetime
|
2006-12-07 13:41:40 +00:00
|
|
|
from report import report_sxw
|
|
|
|
|
|
|
|
class partner_balance(report_sxw.rml_parse):
|
2008-07-22 15:11:28 +00:00
|
|
|
def __init__(self, cr, uid, name, context):
|
2009-10-09 11:49:00 +00:00
|
|
|
super(partner_balance, self).__init__(cr, uid, name, context=context)
|
2008-10-06 09:46:37 +00:00
|
|
|
self.date_lst = []
|
|
|
|
self.date_lst_string = ''
|
2008-11-03 12:50:38 +00:00
|
|
|
self.account_ids = ''
|
2008-07-22 15:11:28 +00:00
|
|
|
self.localcontext.update( {
|
|
|
|
'time': time,
|
|
|
|
'lines': self.lines,
|
|
|
|
'sum_debit': self._sum_debit,
|
|
|
|
'sum_credit': self._sum_credit,
|
|
|
|
'sum_litige': self._sum_litige,
|
|
|
|
'sum_sdebit': self._sum_sdebit,
|
|
|
|
'sum_scredit': self._sum_scredit,
|
|
|
|
'solde_debit': self._solde_balance_debit,
|
|
|
|
'solde_credit': self._solde_balance_credit,
|
|
|
|
'get_company': self._get_company,
|
|
|
|
'get_currency': self._get_currency,
|
2008-10-06 09:46:37 +00:00
|
|
|
'comma_me' : self.comma_me,
|
2008-07-22 15:11:28 +00:00
|
|
|
})
|
2008-10-06 09:46:37 +00:00
|
|
|
## Compute account list one time
|
|
|
|
#
|
|
|
|
# Date Management
|
|
|
|
#
|
|
|
|
def date_range(self,start,end):
|
2009-01-13 05:47:41 +00:00
|
|
|
if not start or not end:
|
|
|
|
return []
|
2008-10-06 09:46:37 +00:00
|
|
|
start = datetime.date.fromtimestamp(time.mktime(time.strptime(start,"%Y-%m-%d")))
|
|
|
|
end = datetime.date.fromtimestamp(time.mktime(time.strptime(end,"%Y-%m-%d")))
|
|
|
|
full_str_date = []
|
|
|
|
#
|
|
|
|
r = (end+datetime.timedelta(days=1)-start).days
|
|
|
|
#
|
|
|
|
date_array = [start+datetime.timedelta(days=i) for i in range(r)]
|
|
|
|
for date in date_array:
|
|
|
|
full_str_date.append(str(date))
|
|
|
|
return full_str_date
|
2008-11-04 12:48:01 +00:00
|
|
|
|
2008-10-06 09:46:37 +00:00
|
|
|
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]
|
2008-11-04 12:48:01 +00:00
|
|
|
date_array = []
|
2008-10-06 09:46:37 +00:00
|
|
|
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()
|
2008-11-04 12:48:01 +00:00
|
|
|
|
|
|
|
|
2008-10-06 09:46:37 +00:00
|
|
|
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()
|
2008-11-04 12:48:01 +00:00
|
|
|
|
2008-10-17 13:04:39 +00:00
|
|
|
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]
|
2008-11-04 12:48:01 +00:00
|
|
|
date_array = []
|
2008-10-17 13:04:39 +00:00
|
|
|
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)
|
2008-11-04 12:48:01 +00:00
|
|
|
|
2008-10-17 13:04:39 +00:00
|
|
|
period_start_date = date_array[0]
|
|
|
|
date_start_date = data['form']['date1']
|
|
|
|
period_stop_date = date_array[-1]
|
|
|
|
date_stop_date = data['form']['date2']
|
2008-11-04 12:48:01 +00:00
|
|
|
|
2008-10-17 13:04:39 +00:00
|
|
|
if period_start_date<date_start_date:
|
|
|
|
start_date = period_start_date
|
|
|
|
else :
|
|
|
|
start_date = date_start_date
|
2008-11-04 12:48:01 +00:00
|
|
|
|
2008-10-17 13:04:39 +00:00
|
|
|
if date_stop_date<period_stop_date:
|
|
|
|
stop_date = period_stop_date
|
|
|
|
else :
|
|
|
|
stop_date = date_stop_date
|
2008-11-04 12:48:01 +00:00
|
|
|
|
|
|
|
|
2008-10-17 13:04:39 +00:00
|
|
|
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()
|
2008-11-04 12:48:01 +00:00
|
|
|
|
2008-10-17 13:04:39 +00:00
|
|
|
def transform_none_into_date_array(self,data):
|
2008-11-04 12:48:01 +00:00
|
|
|
|
2008-10-17 13:04:39 +00:00
|
|
|
sql = "SELECT min(date) as start_date from account_move_line"
|
|
|
|
self.cr.execute(sql)
|
|
|
|
start_date = self.cr.fetchone()[0]
|
2008-11-04 12:48:01 +00:00
|
|
|
|
2008-10-17 13:04:39 +00:00
|
|
|
sql = "SELECT max(date) as start_date from account_move_line"
|
|
|
|
self.cr.execute(sql)
|
|
|
|
stop_date = self.cr.fetchone()[0]
|
2008-11-04 12:48:01 +00:00
|
|
|
|
|
|
|
|
2008-10-17 13:04:39 +00:00
|
|
|
array = []
|
|
|
|
array = array + self.date_range(start_date,stop_date)
|
|
|
|
self.date_lst = array
|
|
|
|
self.date_lst.sort()
|
2008-11-04 12:48:01 +00:00
|
|
|
|
|
|
|
|
2008-10-06 09:46:37 +00:00
|
|
|
def comma_me(self,amount):
|
|
|
|
if type(amount) is float :
|
|
|
|
amount = str('%.2f'%amount)
|
|
|
|
else :
|
|
|
|
amount = str(amount)
|
|
|
|
if (amount == '0'):
|
|
|
|
return ' '
|
|
|
|
orig = amount
|
|
|
|
new = re.sub("^(-?\d+)(\d{3})", "\g<1>'\g<2>", amount)
|
|
|
|
if orig == new:
|
|
|
|
return new
|
|
|
|
else:
|
|
|
|
return self.comma_me(new)
|
2008-11-04 12:48:01 +00:00
|
|
|
|
2009-05-04 12:12:54 +00:00
|
|
|
def set_context(self, objects, data, ids, report_type = None):
|
2008-10-06 09:46:37 +00:00
|
|
|
# Transformation des date
|
|
|
|
#
|
|
|
|
#
|
2008-10-17 13:04:39 +00:00
|
|
|
if data['form']['state'] == 'none':
|
2008-11-04 12:48:01 +00:00
|
|
|
|
2008-10-17 13:04:39 +00:00
|
|
|
self.transform_none_into_date_array(data)
|
2008-10-20 11:14:38 +00:00
|
|
|
elif data['form']['state'] == 'bydate':
|
2008-11-04 12:48:01 +00:00
|
|
|
|
2008-10-06 09:46:37 +00:00
|
|
|
self.transform_date_into_date_array(data)
|
2008-10-20 11:14:38 +00:00
|
|
|
elif data['form']['state'] == 'byperiod':
|
2008-11-04 12:48:01 +00:00
|
|
|
|
2008-10-17 13:04:39 +00:00
|
|
|
self.transform_period_into_date_array(data)
|
2008-10-20 11:14:38 +00:00
|
|
|
elif data['form']['state'] == 'all':
|
2008-11-04 12:48:01 +00:00
|
|
|
|
|
|
|
self.transform_both_into_date_array(data)
|
|
|
|
|
2008-10-06 09:46:37 +00:00
|
|
|
##
|
2009-01-13 05:47:41 +00:00
|
|
|
self.date_lst_string =''
|
|
|
|
if self.date_lst:
|
2009-10-21 07:24:49 +00:00
|
|
|
self.date_lst_string = '\'' + '\',\''.join(map(str, self.date_lst)) + '\''
|
2009-05-04 12:12:54 +00:00
|
|
|
|
2009-03-17 10:58:22 +00:00
|
|
|
|
2008-10-06 09:46:37 +00:00
|
|
|
## Compute Code
|
2008-07-22 15:11:28 +00:00
|
|
|
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
|
2008-10-06 09:46:37 +00:00
|
|
|
#
|
|
|
|
if (data['form']['result_selection'] == 'customer' ):
|
|
|
|
self.ACCOUNT_TYPE = "('receivable')"
|
|
|
|
elif (data['form']['result_selection'] == 'supplier'):
|
|
|
|
self.ACCOUNT_TYPE = "('payable')"
|
|
|
|
else:
|
|
|
|
self.ACCOUNT_TYPE = "('payable','receivable')"
|
|
|
|
#
|
2008-11-03 12:50:38 +00:00
|
|
|
self.cr.execute("SELECT a.id " \
|
|
|
|
"FROM account_account a " \
|
|
|
|
"LEFT JOIN account_account_type t " \
|
|
|
|
"ON (a.type = t.code) " \
|
2008-12-10 14:29:55 +00:00
|
|
|
"WHERE a.company_id = %s " \
|
2008-11-03 12:50:38 +00:00
|
|
|
"AND a.type IN " + self.ACCOUNT_TYPE + " " \
|
|
|
|
"AND a.active", (data['form']['company_id'],))
|
2008-07-22 15:11:28 +00:00
|
|
|
self.account_ids = ','.join([str(a) for (a,) in self.cr.fetchall()])
|
2008-11-04 12:48:01 +00:00
|
|
|
|
2009-05-04 12:12:54 +00:00
|
|
|
super(partner_balance, self).set_context(objects, data, ids, report_type)
|
2008-10-06 09:46:37 +00:00
|
|
|
|
|
|
|
def lines(self,data):
|
2006-12-07 13:41:40 +00:00
|
|
|
|
2008-07-22 15:11:28 +00:00
|
|
|
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
|
2008-10-06 09:46:37 +00:00
|
|
|
full_account = []
|
|
|
|
result_tmp = 0.0
|
2009-01-13 05:47:41 +00:00
|
|
|
if self.date_lst_string:
|
|
|
|
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) " \
|
|
|
|
"THEN sum(debit) - sum(credit) " \
|
|
|
|
"ELSE 0 " \
|
|
|
|
"END AS sdebit, " \
|
|
|
|
"CASE WHEN sum(debit) < sum(credit) " \
|
|
|
|
"THEN sum(credit) - sum(debit) " \
|
|
|
|
"ELSE 0 " \
|
|
|
|
"END AS scredit, " \
|
|
|
|
"(SELECT sum(debit-credit) " \
|
|
|
|
"FROM account_move_line l " \
|
|
|
|
"WHERE partner_id = p.id " \
|
|
|
|
"AND l.date IN (" + self.date_lst_string + ") " \
|
|
|
|
"AND blocked = TRUE " \
|
|
|
|
") AS enlitige " \
|
|
|
|
"FROM account_move_line l LEFT JOIN res_partner p ON (l.partner_id=p.id) " \
|
|
|
|
"JOIN account_account ac ON (l.account_id = ac.id)" \
|
|
|
|
"WHERE ac.type IN " + self.ACCOUNT_TYPE + " " \
|
|
|
|
"AND l.date IN (" + self.date_lst_string + ") " \
|
2009-09-24 12:41:04 +00:00
|
|
|
"AND ac.company_id = "+ str(data['form']['company_id']) +" " \
|
2009-01-13 05:47:41 +00:00
|
|
|
"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()
|
|
|
|
for r in res:
|
|
|
|
full_account.append(r)
|
2008-11-04 12:48:01 +00:00
|
|
|
|
2008-10-06 09:46:37 +00:00
|
|
|
## We will now compute Total
|
|
|
|
return self._add_subtotal(full_account)
|
2008-01-11 14:46:53 +00:00
|
|
|
|
2008-10-06 09:46:37 +00:00
|
|
|
def _add_subtotal(self,cleanarray):
|
|
|
|
i=0
|
|
|
|
completearray = []
|
|
|
|
tot_debit = 0.0
|
|
|
|
tot_credit = 0.0
|
|
|
|
tot_scredit = 0.0
|
|
|
|
tot_sdebit = 0.0
|
|
|
|
tot_enlitige = 0.0
|
|
|
|
for r in cleanarray:
|
|
|
|
# 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
|
|
|
|
if i==0:
|
|
|
|
# We add the first as the header
|
|
|
|
#
|
|
|
|
##
|
|
|
|
new_header = {}
|
|
|
|
new_header['ref'] = ''
|
|
|
|
new_header['name'] = r['account_name']
|
|
|
|
new_header['code'] = r['code']
|
2008-10-15 13:15:46 +00:00
|
|
|
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)
|
2008-10-06 09:46:37 +00:00
|
|
|
new_header['type'] = 3
|
|
|
|
##
|
|
|
|
completearray.append(new_header)
|
|
|
|
#
|
|
|
|
r['type'] = 1
|
|
|
|
r['balance'] = float(r['sdebit']) - float(r['scredit'])
|
2008-11-04 12:48:01 +00:00
|
|
|
|
2008-10-06 09:46:37 +00:00
|
|
|
completearray.append(r)
|
|
|
|
#
|
|
|
|
tot_debit = r['debit']
|
|
|
|
tot_credit = r['credit']
|
|
|
|
tot_scredit = r['scredit']
|
|
|
|
tot_sdebit = r['sdebit']
|
|
|
|
tot_enlitige = (r['enlitige'] or 0.0)
|
|
|
|
#
|
|
|
|
else:
|
|
|
|
if cleanarray[i]['account_id'] <> cleanarray[i-1]['account_id']:
|
2008-11-04 12:48:01 +00:00
|
|
|
|
2008-10-15 13:15:46 +00:00
|
|
|
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
|
2008-11-04 12:48:01 +00:00
|
|
|
# we reset the counter
|
2008-10-06 09:46:37 +00:00
|
|
|
tot_debit = r['debit']
|
|
|
|
tot_credit = r['credit']
|
|
|
|
tot_scredit = r['scredit']
|
|
|
|
tot_sdebit = r['sdebit']
|
|
|
|
tot_enlitige = (r['enlitige'] or 0.0)
|
|
|
|
#
|
|
|
|
##
|
|
|
|
new_header = {}
|
|
|
|
new_header['ref'] = ''
|
|
|
|
new_header['name'] = r['account_name']
|
|
|
|
new_header['code'] = r['code']
|
2008-10-15 13:15:46 +00:00
|
|
|
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)
|
2008-10-06 09:46:37 +00:00
|
|
|
new_header['type'] = 3
|
|
|
|
##
|
|
|
|
##
|
2008-11-06 11:22:44 +00:00
|
|
|
|
2008-10-06 09:46:37 +00:00
|
|
|
completearray.append(new_header)
|
2008-11-04 12:48:01 +00:00
|
|
|
##
|
2008-10-06 09:46:37 +00:00
|
|
|
#
|
|
|
|
r['type'] = 1
|
|
|
|
#
|
|
|
|
r['balance'] = float(r['sdebit']) - float(r['scredit'])
|
2008-11-04 12:48:01 +00:00
|
|
|
|
2008-10-06 09:46:37 +00:00
|
|
|
completearray.append(r)
|
2008-11-04 12:48:01 +00:00
|
|
|
|
2008-10-06 09:46:37 +00:00
|
|
|
if cleanarray[i]['account_id'] == cleanarray[i-1]['account_id']:
|
2008-11-04 12:48:01 +00:00
|
|
|
# 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
|
|
|
|
|
2008-10-06 09:46:37 +00:00
|
|
|
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)
|
2008-11-04 12:48:01 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
2008-10-06 09:46:37 +00:00
|
|
|
#
|
|
|
|
r['type'] = 2
|
|
|
|
#
|
|
|
|
r['balance'] = float(r['sdebit']) - float(r['scredit'])
|
|
|
|
#
|
2008-11-06 11:22:44 +00:00
|
|
|
|
2008-10-06 09:46:37 +00:00
|
|
|
completearray.append(r)
|
2008-11-04 12:48:01 +00:00
|
|
|
|
2008-10-06 09:46:37 +00:00
|
|
|
i = i + 1
|
2008-11-04 12:48:01 +00:00
|
|
|
|
2008-10-06 09:46:37 +00:00
|
|
|
return completearray
|
|
|
|
|
|
|
|
|
|
|
|
def _sum_debit(self,data):
|
2008-07-22 15:11:28 +00:00
|
|
|
if not self.ids:
|
|
|
|
return 0.0
|
|
|
|
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
|
2008-10-06 09:46:37 +00:00
|
|
|
result_tmp = 0.0
|
2009-01-13 05:47:41 +00:00
|
|
|
temp_res = 0.0
|
|
|
|
if self.date_lst_string:
|
|
|
|
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 + ") " )
|
|
|
|
temp_res = float(self.cr.fetchone()[0] or 0.0)
|
|
|
|
result_tmp = result_tmp + temp_res
|
2008-11-04 12:48:01 +00:00
|
|
|
|
2008-10-06 09:46:37 +00:00
|
|
|
return result_tmp
|
2008-01-11 14:46:53 +00:00
|
|
|
|
2008-10-06 09:46:37 +00:00
|
|
|
def _sum_credit(self,data):
|
2008-07-22 15:11:28 +00:00
|
|
|
if not self.ids:
|
|
|
|
return 0.0
|
|
|
|
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
|
2008-11-04 12:48:01 +00:00
|
|
|
|
2008-10-06 09:46:37 +00:00
|
|
|
result_tmp = 0.0
|
2009-01-13 05:47:41 +00:00
|
|
|
temp_res = 0.0
|
|
|
|
if self.date_lst_string:
|
|
|
|
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 + ") " )
|
|
|
|
temp_res = float(self.cr.fetchone()[0] or 0.0)
|
|
|
|
result_tmp = result_tmp + temp_res
|
2008-11-04 12:48:01 +00:00
|
|
|
|
2008-10-06 09:46:37 +00:00
|
|
|
return result_tmp
|
2006-12-07 13:41:40 +00:00
|
|
|
|
2008-10-06 09:46:37 +00:00
|
|
|
def _sum_litige(self,data):
|
2008-07-22 15:11:28 +00:00
|
|
|
if not self.ids:
|
|
|
|
return 0.0
|
|
|
|
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
|
2008-10-06 09:46:37 +00:00
|
|
|
result_tmp = 0.0
|
2009-01-13 05:47:41 +00:00
|
|
|
temp_res = 0.0
|
|
|
|
if self.date_lst_string:
|
|
|
|
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 " )
|
|
|
|
temp_res = float(self.cr.fetchone()[0] or 0.0)
|
|
|
|
result_tmp = result_tmp + temp_res
|
2008-11-04 12:48:01 +00:00
|
|
|
|
2008-10-06 09:46:37 +00:00
|
|
|
return result_tmp
|
2008-01-11 14:46:53 +00:00
|
|
|
|
2008-10-06 09:46:37 +00:00
|
|
|
def _sum_sdebit(self,data):
|
2008-07-22 15:11:28 +00:00
|
|
|
if not self.ids:
|
|
|
|
return 0.0
|
|
|
|
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
|
2008-10-06 09:46:37 +00:00
|
|
|
result_tmp = 0.0
|
2009-01-13 05:47:41 +00:00
|
|
|
a = 0.0
|
|
|
|
if self.date_lst_string:
|
|
|
|
self.cr.execute(
|
|
|
|
"SELECT CASE WHEN sum(debit) > sum(credit) " \
|
|
|
|
"THEN sum(debit) - sum(credit) " \
|
|
|
|
"ELSE 0 " \
|
|
|
|
"END " \
|
|
|
|
"FROM account_move_line AS l " \
|
|
|
|
"WHERE l.account_id IN (" + self.account_ids + ") " \
|
|
|
|
"AND l.date IN (" + self.date_lst_string + ") " \
|
|
|
|
"GROUP BY l.partner_id")
|
|
|
|
a = self.cr.fetchone()[0]
|
2008-11-04 12:48:01 +00:00
|
|
|
|
2009-01-13 05:47:41 +00:00
|
|
|
if self.cr.fetchone() != None:
|
|
|
|
result_tmp = result_tmp + (a or 0.0)
|
|
|
|
else:
|
|
|
|
result_tmp = 0.0
|
2008-11-04 12:48:01 +00:00
|
|
|
|
|
|
|
return result_tmp
|
2008-01-11 14:46:53 +00:00
|
|
|
|
2008-10-06 09:46:37 +00:00
|
|
|
def _sum_scredit(self,data):
|
2008-11-04 12:48:01 +00:00
|
|
|
|
2008-07-22 15:11:28 +00:00
|
|
|
if not self.ids:
|
|
|
|
return 0.0
|
|
|
|
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
|
2008-11-04 12:48:01 +00:00
|
|
|
|
2008-10-06 09:46:37 +00:00
|
|
|
result_tmp = 0.0
|
2009-01-13 05:47:41 +00:00
|
|
|
a = 0.0
|
|
|
|
if self.date_lst_string:
|
|
|
|
self.cr.execute(
|
|
|
|
"SELECT CASE WHEN sum(debit) < sum(credit) " \
|
|
|
|
"THEN sum(credit) - sum(debit) " \
|
|
|
|
"ELSE 0 " \
|
|
|
|
"END " \
|
|
|
|
"FROM account_move_line AS l " \
|
|
|
|
"WHERE l.account_id 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
|
2009-03-17 10:58:22 +00:00
|
|
|
|
2009-01-13 05:47:41 +00:00
|
|
|
if self.cr.fetchone() != None:
|
|
|
|
result_tmp = result_tmp + (a or 0.0)
|
2009-03-17 10:58:22 +00:00
|
|
|
|
2009-01-13 05:47:41 +00:00
|
|
|
else:
|
|
|
|
result_tmp = 0.0
|
2008-11-04 12:48:01 +00:00
|
|
|
|
2008-10-06 09:46:37 +00:00
|
|
|
return result_tmp
|
2008-11-04 12:48:01 +00:00
|
|
|
|
2008-10-06 09:46:37 +00:00
|
|
|
def _solde_balance_debit(self,data):
|
|
|
|
debit, credit = self._sum_debit(data), self._sum_credit(data)
|
2008-07-22 15:11:28 +00:00
|
|
|
return debit > credit and debit - credit
|
2008-11-04 12:48:01 +00:00
|
|
|
|
2008-10-06 09:46:37 +00:00
|
|
|
def _solde_balance_credit(self,data):
|
|
|
|
debit, credit = self._sum_debit(data), self._sum_credit(data)
|
2008-07-22 15:11:28 +00:00
|
|
|
return credit > debit and credit - debit
|
2007-07-10 15:24:54 +00:00
|
|
|
|
2008-07-22 15:11:28 +00:00
|
|
|
def _get_company(self, form):
|
|
|
|
return pooler.get_pool(self.cr.dbname).get('res.company').browse(self.cr, self.uid, form['company_id']).name
|
2007-07-10 15:24:54 +00:00
|
|
|
|
2008-07-22 15:11:28 +00:00
|
|
|
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
|
2007-07-10 15:24:54 +00:00
|
|
|
|
2007-07-26 08:30:14 +00:00
|
|
|
report_sxw.report_sxw('report.account.partner.balance', 'res.partner',
|
2008-10-06 09:46:37 +00:00
|
|
|
'account/report/partner_balance.rml',parser=partner_balance,
|
2008-11-06 11:22:44 +00:00
|
|
|
header=False)
|
2009-04-09 10:02:19 +00:00
|
|
|
|
2009-03-06 22:18:24 +00:00
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|