1 ##############################################################################
3 # Copyright (c) 2005-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 ##############################################################################
29 from report import report_sxw
31 class general_ledger(report_sxw.rml_parse):
32 def __init__(self, cr, uid, name, context):
33 super(general_ledger, self).__init__(cr, uid, name, context)
34 self.localcontext.update( {
37 'sum_debit_account': self._sum_debit_account,
38 'sum_credit_account': self._sum_credit_account,
39 'sum_debit': self._sum_debit,
40 'sum_credit': self._sum_credit,
42 self.context = context
44 def lines(self, account, form):
45 ctx = self.context.copy()
46 ctx['fiscalyear'] = form['fiscalyear']
47 ctx['periods'] = form['periods'][0][2]
48 query = self.pool.get('account.move.line')._query_get(self.cr, self.uid, context=ctx)
49 self.cr.execute("SELECT l.date, j.code, l.ref, l.name, l.debit, l.credit "\
50 "FROM account_move_line l, account_journal j "\
51 "WHERE l.journal_id = j.id "\
52 "AND account_id = %d AND "+query+" "\
53 "ORDER by l.id", (account.id,))
54 res = self.cr.dictfetchall()
57 sum += l['debit'] - l ['credit']
61 def _sum_debit_account(self, account, form):
62 ctx = self.context.copy()
63 ctx['fiscalyear'] = form['fiscalyear']
64 ctx['periods'] = form['periods'][0][2]
65 query = self.pool.get('account.move.line')._query_get(self.cr, self.uid, context=ctx)
66 self.cr.execute("SELECT sum(debit) "\
67 "FROM account_move_line l "\
68 "WHERE l.account_id = %d AND "+query, (account.id,))
69 return self.cr.fetchone()[0] or 0.0
71 def _sum_credit_account(self, account, form):
72 ctx = self.context.copy()
73 ctx['fiscalyear'] = form['fiscalyear']
74 ctx['periods'] = form['periods'][0][2]
75 query = self.pool.get('account.move.line')._query_get(self.cr, self.uid, context=ctx)
76 self.cr.execute("SELECT sum(credit) "\
77 "FROM account_move_line l "\
78 "WHERE l.account_id = %d AND "+query, (account.id,))
79 return self.cr.fetchone()[0] or 0.0
81 def _sum_debit(self, form):
84 ctx = self.context.copy()
85 ctx['fiscalyear'] = form['fiscalyear']
86 ctx['periods'] = form['periods'][0][2]
87 query = self.pool.get('account.move.line')._query_get(self.cr, self.uid, context=ctx)
88 self.cr.execute("SELECT sum(debit) "\
89 "FROM account_move_line l "\
90 "WHERE l.account_id in ("+','.join(map(str, self.ids))+") AND "+query)
91 return self.cr.fetchone()[0] or 0.0
93 def _sum_credit(self, form):
96 ctx = self.context.copy()
97 ctx['fiscalyear'] = form['fiscalyear']
98 ctx['periods'] = form['periods'][0][2]
99 query = self.pool.get('account.move.line')._query_get(self.cr, self.uid, context=ctx)
100 self.cr.execute("SELECT sum(credit) "\
101 "FROM account_move_line l "\
102 "WHERE l.account_id in ("+','.join(map(str, self.ids))+") AND "+query)
103 return self.cr.fetchone()[0] or 0.0
105 report_sxw.report_sxw('report.account.general.ledger', 'account.account', 'addons/account/report/general_ledger.rml', parser=general_ledger, header=False)