1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
23 from osv import fields,osv
24 import decimal_precision as dp
26 class account_treasury_report(osv.osv):
27 _name = "account.treasury.report"
28 _description = "Treasury Analysis"
31 def _compute_balances(self, cr, uid, ids, field_names, arg=None, context=None,
32 query='', query_params=()):
33 all_treasury_lines = self.search(cr, uid, [], context=context)
34 all_companies = self.pool.get('res.company').search(cr, uid, [], context=context)
35 current_sum = dict((company, 0.0) for company in all_companies)
36 res = dict((id, dict((fn, 0.0) for fn in field_names)) for id in all_treasury_lines)
37 for record in self.browse(cr, uid, all_treasury_lines, context=context):
38 res[record.id]['starting_balance'] = current_sum[record.company_id.id]
39 current_sum[record.company_id.id] += record.balance
40 res[record.id]['ending_balance'] = current_sum[record.company_id.id]
44 'fiscalyear_id': fields.many2one('account.fiscalyear', 'Fiscalyear', readonly=True),
45 'period_id': fields.many2one('account.period', 'Period', readonly=True),
46 'debit': fields.float('Debit', readonly=True),
47 'credit': fields.float('Credit', readonly=True),
48 'balance': fields.float('Balance', readonly=True),
49 'date': fields.date('Beginning of Period Date', readonly=True),
50 'starting_balance': fields.function(_compute_balances, digits_compute=dp.get_precision('Account'), string='Starting Balance', multi='balance'),
51 'ending_balance': fields.function(_compute_balances, digits_compute=dp.get_precision('Account'), string='Ending Balance', multi='balance'),
52 'company_id': fields.many2one('res.company', 'Company', readonly=True),
59 tools.drop_view_if_exists(cr, 'account_treasury_report')
61 create or replace view account_treasury_report as (
64 p.fiscalyear_id as fiscalyear_id,
66 sum(l.debit) as debit,
67 sum(l.credit) as credit,
68 sum(l.debit-l.credit) as balance,
70 am.company_id as company_id
73 left join account_account a on (l.account_id = a.id)
74 left join account_move am on (am.id=l.move_id)
75 left join account_period p on (am.period_id=p.id)
76 where l.state != 'draft'
77 and a.type = 'liquidity'
78 group by p.id, p.fiscalyear_id, p.date_start, am.company_id
81 account_treasury_report()
83 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: