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 ##############################################################################
22 from openerp.osv import fields, osv
24 class accounting_report(osv.osv_memory):
25 _name = "accounting.report"
26 _inherit = "account.common.report"
27 _description = "Accounting Report"
30 'enable_filter': fields.boolean('Enable Comparison'),
31 'account_report_id': fields.many2one('account.financial.report', 'Account Reports', required=True),
32 'label_filter': fields.char('Column Label', size=32, help="This label will be displayed on report to show the balance computed for the given comparison filter."),
33 'fiscalyear_id_cmp': fields.many2one('account.fiscalyear', 'Fiscal Year', help='Keep empty for all open fiscal year'),
34 'filter_cmp': fields.selection([('filter_no', 'No Filters'), ('filter_date', 'Date'), ('filter_period', 'Periods')], "Filter by", required=True),
35 'period_from_cmp': fields.many2one('account.period', 'Start Period'),
36 'period_to_cmp': fields.many2one('account.period', 'End Period'),
37 'date_from_cmp': fields.date("Start Date"),
38 'date_to_cmp': fields.date("End Date"),
39 'debit_credit': fields.boolean('Display Debit/Credit Columns', help="This option allows you to get more details about the way your balances are computed. Because it is space consuming, we do not allow to use it while doing a comparison."),
42 def _get_account_report(self, cr, uid, context=None):
43 # TODO deprecate this it doesnt work in web
44 menu_obj = self.pool.get('ir.ui.menu')
45 report_obj = self.pool.get('account.financial.report')
47 if context.get('active_id'):
48 menu = menu_obj.browse(cr, uid, context.get('active_id')).name
49 report_ids = report_obj.search(cr, uid, [('name','ilike',menu)])
50 return report_ids and report_ids[0] or False
53 'filter_cmp': 'filter_no',
54 'target_move': 'posted',
55 'account_report_id': _get_account_report,
58 def _build_comparison_context(self, cr, uid, ids, data, context=None):
62 result['fiscalyear'] = 'fiscalyear_id_cmp' in data['form'] and data['form']['fiscalyear_id_cmp'] or False
63 result['journal_ids'] = 'journal_ids' in data['form'] and data['form']['journal_ids'] or False
64 result['chart_account_id'] = 'chart_account_id' in data['form'] and data['form']['chart_account_id'] or False
65 result['state'] = 'target_move' in data['form'] and data['form']['target_move'] or ''
66 if data['form']['filter_cmp'] == 'filter_date':
67 result['date_from'] = data['form']['date_from_cmp']
68 result['date_to'] = data['form']['date_to_cmp']
69 elif data['form']['filter_cmp'] == 'filter_period':
70 if not data['form']['period_from_cmp'] or not data['form']['period_to_cmp']:
71 raise osv.except_osv(_('Error!'),_('Select a starting and an ending period'))
72 result['period_from'] = data['form']['period_from_cmp']
73 result['period_to'] = data['form']['period_to_cmp']
76 def check_report(self, cr, uid, ids, context=None):
79 res = super(accounting_report, self).check_report(cr, uid, ids, context=context)
81 data['form'] = self.read(cr, uid, ids, ['account_report_id', 'date_from_cmp', 'date_to_cmp', 'fiscalyear_id_cmp', 'journal_ids', 'period_from_cmp', 'period_to_cmp', 'filter_cmp', 'chart_account_id', 'target_move'], context=context)[0]
82 for field in ['fiscalyear_id_cmp', 'chart_account_id', 'period_from_cmp', 'period_to_cmp', 'account_report_id']:
83 if isinstance(data['form'][field], tuple):
84 data['form'][field] = data['form'][field][0]
85 comparison_context = self._build_comparison_context(cr, uid, ids, data, context=context)
86 res['datas']['form']['comparison_context'] = comparison_context
89 def _print_report(self, cr, uid, ids, data, context=None):
90 data['form'].update(self.read(cr, uid, ids, ['date_from_cmp', 'debit_credit', 'date_to_cmp', 'fiscalyear_id_cmp', 'period_from_cmp', 'period_to_cmp', 'filter_cmp', 'account_report_id', 'enable_filter', 'label_filter','target_move'], context=context)[0])
92 'type': 'ir.actions.report.xml',
93 'report_name': 'account.financial.report',
99 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: