1
##############################################################################
3
# Copyright (c) 2004-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
5
# WARNING: This program as such is intended to be used by professional
6
# programmers who take the whole responsability of assessing all potential
7
# consequences resulting from its eventual inadequacies and bugs
8
# End users who are looking for a ready-to-use solution with commercial
9
# garantees and support are strongly adviced to contract a Free Software
12
# This program is Free Software; you can redistribute it and/or
13
# modify it under the terms of the GNU General Public License
14
# as published by the Free Software Foundation; either version 2
15
# of the License, or (at your option) any later version.
17
# This program is distributed in the hope that it will be useful,
18
# but WITHOUT ANY WARRANTY; without even the implied warranty of
19
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
# GNU General Public License for more details.
22
# You should have received a copy of the GNU General Public License
23
# along with this program; if not, write to the Free Software
24
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
##############################################################################
30
from report import report_sxw
32
class account_balance(report_sxw.rml_parse):
33
def __init__(self, cr, uid, name, context):
34
super(account_balance, self).__init__(cr, uid, name, context)
35
self.localcontext.update({
38
'sum_debit': self._sum_debit,
39
'sum_credit': self._sum_credit,
40
'sum_sdebit': self._sum_sdebit,
41
'sum_scredit': self._sum_scredit
43
self.context = context
45
def lines(self, ids=None, done=None, level=0):
51
for account in self.pool.get('account.account').browse(self.cr, self.uid, ids, self.context):
52
if account.id in done:
58
'debit': account.debit,
59
'credit': account.credit,
61
'sdebit': account.debit > account.credit and account.debit - account.credit,
62
'scredit': account.debit < account.credit and account.credit - account.debit,
63
'balance': account.balance
65
if not (res['credit'] or res['debit']) and not account.child_id:
68
ids2 = [(x.code,x.id) for x in account.child_id]
70
result += self.lines([x[1] for x in ids2], done, level+1)
78
self.cr.execute('select sum(debit) from account_move_line where account_id in (' + ','.join(map(str, self.ids)) + ') and date>=%s and date<=%s and state<>\'draft\'', (self.datas['form']['date1'], self.datas['form']['date2']))
79
return self.cr.fetchone()[0] or 0.0
81
def _sum_credit(self):
85
self.cr.execute('select sum(credit) from account_move_line where account_id in (' + ','.join(map(str, self.ids)) + ') and date>=%s and date<=%s and state<>\'draft\'', (self.datas['form']['date1'], self.datas['form']['date2']))
86
return self.cr.fetchone()[0] or 0.0
88
def _sum_sdebit(self):
89
debit, credit = self._sum_debit(), self._sum_credit()
90
return debit > credit and debit - credit
92
def _sum_scredit(self):
93
debit, credit = self._sum_debit(), self._sum_credit()
94
return credit > debit and credit - debit
96
report_sxw.report_sxw('report.account.account.balance', 'account.account', 'addons/account/report/account_balance.rml', parser=account_balance)