[MERGE] use new report API.
[odoo/odoo.git] / addons / account / wizard / account_report_general_ledger.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
6 #
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.
11 #
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.
16 #
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/>.
19 #
20 ##############################################################################
21
22 from openerp.osv import fields, osv
23
24 class account_report_general_ledger(osv.osv_memory):
25     _inherit = "account.common.account.report"
26     _name = "account.report.general.ledger"
27     _description = "General Ledger Report"
28
29     _columns = {
30         'landscape': fields.boolean("Landscape Mode"),
31         'initial_balance': fields.boolean('Include Initial Balances',
32                                     help='If you selected to filter by date or period, this field allow you to add a row to display the amount of debit/credit/balance that precedes the filter you\'ve set.'),
33         'amount_currency': fields.boolean("With Currency", help="It adds the currency column on report if the currency differs from the company currency."),
34         'sortby': fields.selection([('sort_date', 'Date'), ('sort_journal_partner', 'Journal & Partner')], 'Sort by', required=True),
35         'journal_ids': fields.many2many('account.journal', 'account_report_general_ledger_journal_rel', 'account_id', 'journal_id', 'Journals', required=True),
36     }
37     _defaults = {
38         'landscape': True,
39         'amount_currency': True,
40         'sortby': 'sort_date',
41         'initial_balance': False,
42     }
43
44     def onchange_fiscalyear(self, cr, uid, ids, fiscalyear=False, context=None):
45         res = {}
46         if not fiscalyear:
47             res['value'] = {'initial_balance': False}
48         return res
49
50     def _print_report(self, cr, uid, ids, data, context=None):
51         if context is None:
52             context = {}
53         data = self.pre_print_report(cr, uid, ids, data, context=context)
54         data['form'].update(self.read(cr, uid, ids, ['landscape',  'initial_balance', 'amount_currency', 'sortby'])[0])
55         if not data['form']['fiscalyear_id']:# GTK client problem onchange does not consider in save record
56             data['form'].update({'initial_balance': False})
57         if data['form']['landscape']:
58             return { 'type': 'ir.actions.report.xml', 'report_name': 'account.general.ledger_landscape', 'datas': data}
59         return { 'type': 'ir.actions.report.xml', 'report_name': 'account.general.ledger', 'datas': data}
60
61 account_report_general_ledger()
62
63 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: