1 ##############################################################################
3 # OpenERP, Open Source Management Solution
4 # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU Affero General Public License as
8 # published by the Free Software Foundation, either version 3 of the
9 # License, or (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU Affero General Public License for more details.
16 # You should have received a copy of the GNU Affero General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 ##############################################################################
23 from report import report_sxw
24 from common_report_header import common_report_header
25 from tools.translate import _
27 class report_account_common(report_sxw.rml_parse, common_report_header):
29 def __init__(self, cr, uid, name, context=None):
30 super(report_account_common, self).__init__(cr, uid, name, context=context)
31 self.localcontext.update( {
32 'get_lines': self.get_lines,
34 'get_fiscalyear': self._get_fiscalyear,
35 'get_account': self._get_account,
36 'get_start_period': self.get_start_period,
37 'get_end_period': self.get_end_period,
38 'get_filter': self._get_filter,
39 'get_start_date':self._get_start_date,
40 'get_end_date':self._get_end_date,
42 self.context = context
44 def set_context(self, objects, data, ids, report_type=None):
46 if (data['model'] == 'ir.ui.menu'):
47 new_ids = 'chart_account_id' in data['form'] and [data['form']['chart_account_id']] or []
48 objects = self.pool.get('account.account').browse(self.cr, self.uid, new_ids)
49 return super(report_account_common, self).set_context(objects, data, new_ids, report_type=report_type)
51 def get_lines(self, data):
53 account_obj = self.pool.get('account.account')
54 currency_obj = self.pool.get('res.currency')
55 ids2 = self.pool.get('account.financial.report')._get_children_by_order(self.cr, self.uid, [data['form']['account_report_id'][0]], context=data['form']['used_context'])
56 for report in self.pool.get('account.financial.report').browse(self.cr, self.uid, ids2, context=data['form']['used_context']):
59 'balance': report.balance,
61 'level': bool(report.style_overwrite) and report.style_overwrite or report.level,
62 'account_type': report.type =='sum' and 'view' or False, #used to underline the financial report balances
64 if data['form']['debit_credit']:
65 vals['debit'] = report.debit
66 vals['credit'] = report.credit
67 if data['form']['enable_filter']:
68 vals['balance_cmp'] = self.pool.get('account.financial.report').browse(self.cr, self.uid, report.id, context=data['form']['comparison_context']).balance
71 if report.display_detail == 'no_detail':
72 #the rest of the loop is used to display the details of the financial report, so it's not needed here.
74 if report.type == 'accounts' and report.account_ids:
75 account_ids = account_obj._get_children_and_consol(self.cr, self.uid, [x.id for x in report.account_ids])
76 elif report.type == 'account_type' and report.account_type_ids:
77 account_ids = account_obj.search(self.cr, self.uid, [('user_type','in', [x.id for x in report.account_type_ids])])
79 for account in account_obj.browse(self.cr, self.uid, account_ids, context=data['form']['used_context']):
80 #if there are accounts to display, we add them to the lines with a level equals to their level in
81 #the COA + 1 (to avoid having them with a too low level that would conflicts with the level of data
82 #financial reports for Assets, liabilities...)
83 if report.display_detail == 'detail_flat' and account.type == 'view':
87 'name': account.code + ' ' + account.name,
88 'balance': account.balance != 0 and account.balance * report.sign or account.balance,
90 'level': report.display_detail == 'detail_with_hierarchy' and min(account.level + 1,6) or 6, #account.level + 1
91 'account_type': account.type,
94 if data['form']['debit_credit']:
95 vals['debit'] = account.debit
96 vals['credit'] = account.credit
97 if not currency_obj.is_zero(self.cr, self.uid, account.company_id.currency_id, vals['balance']):
99 if data['form']['enable_filter']:
100 vals['balance_cmp'] = account_obj.browse(self.cr, self.uid, account.id, context=data['form']['comparison_context']).balance
101 if not currency_obj.is_zero(self.cr, self.uid, account.company_id.currency_id, vals['balance_cmp']):
107 report_sxw.report_sxw('report.account.financial.report', 'account.financial.report',
108 'addons/account/report/account_financial_report.rml', parser=report_account_common, header='internal')
111 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: