~technofluid-team/openobject-addons/technofluid_multiple_installations

« back to all changes in this revision

Viewing changes to account/report/account_balance.py

  • Committer: pinky
  • Date: 2006-12-07 13:41:40 UTC
  • Revision ID: pinky-dedd7f8a42bd4557112a0513082691b8590ad6cc
New trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
##############################################################################
 
2
#
 
3
# Copyright (c) 2004-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
 
4
#
 
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
 
10
# Service Company
 
11
#
 
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.
 
16
#
 
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.
 
21
#
 
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.
 
25
#
 
26
##############################################################################
 
27
 
 
28
import pooler
 
29
import time
 
30
from report import report_sxw
 
31
 
 
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({
 
36
                        'time': time,
 
37
                        'lines': self.lines,
 
38
                        'sum_debit': self._sum_debit,
 
39
                        'sum_credit': self._sum_credit,
 
40
                        'sum_sdebit': self._sum_sdebit,
 
41
                        'sum_scredit': self._sum_scredit
 
42
                })
 
43
                self.context = context
 
44
 
 
45
        def lines(self, ids=None, done=None, level=0):
 
46
                ids = ids or self.ids
 
47
                done = done or {}
 
48
                if not self.ids:
 
49
                        return []
 
50
                result = []
 
51
                for account in self.pool.get('account.account').browse(self.cr, self.uid, ids, self.context):
 
52
                        if account.id in done:
 
53
                                continue
 
54
                        done[account.id] = 1
 
55
                        res = {
 
56
                                'code': account.code,
 
57
                                'name': account.name,
 
58
                                'debit': account.debit,
 
59
                                'credit': account.credit,
 
60
                                'level': level,
 
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
 
64
                        }
 
65
                        if not (res['credit'] or res['debit']) and not account.child_id:
 
66
                                continue
 
67
                        result.append(res)
 
68
                        ids2 = [(x.code,x.id) for x in account.child_id]
 
69
                        ids2.sort()
 
70
                        result += self.lines([x[1] for x in ids2], done, level+1)
 
71
                self.ids = done
 
72
                return result
 
73
 
 
74
        def _sum_debit(self):
 
75
                if not self.ids:
 
76
                        return 0.0
 
77
 
 
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
 
80
 
 
81
        def _sum_credit(self):
 
82
                if not self.ids:
 
83
                        return 0.0
 
84
 
 
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
 
87
        
 
88
        def _sum_sdebit(self):
 
89
                debit, credit = self._sum_debit(), self._sum_credit()
 
90
                return debit > credit and debit - credit
 
91
                
 
92
        def _sum_scredit(self):
 
93
                debit, credit = self._sum_debit(), self._sum_credit()
 
94
                return credit > debit and credit - debit
 
95
        
 
96
report_sxw.report_sxw('report.account.account.balance', 'account.account', 'addons/account/report/account_balance.rml', parser=account_balance)
 
97