[MERGE] lp:~xrg/openobject-addons/trunk-patch18
[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 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='It adds initial balance row on report which display previous sum amount of debit/credit/balance'),
33         'amount_currency': fields.boolean("With Currency", help="It adds the currency column if the currency is different then the company currency"),
34         'sortby': fields.selection([('sort_date', 'Date'), ('sort_journal_partner', 'Journal & Partner')], 'Sort By', required=True),
35     }
36     _defaults = {
37         'landscape': True,
38         'amount_currency': True,
39         'sortby': 'sort_date',
40         'initial_balance': False,
41     }
42
43     def onchange_fiscalyear(self, cr, uid, ids, fiscalyear=False, context=None):
44         res = {}
45         if not fiscalyear:
46             res['value'] = {'initial_balance': False}
47         return res
48
49     def _print_report(self, cr, uid, ids, data, context=None):
50         if context is None:
51             context = {}
52         data = self.pre_print_report(cr, uid, ids, data, context=context)
53         data['form'].update(self.read(cr, uid, ids, ['landscape',  'initial_balance', 'amount_currency', 'sortby'])[0])
54         if not data['form']['fiscalyear_id']:# GTK client problem onchange does not consider in save record
55             data['form'].update({'initial_balance': False})
56         if data['form']['landscape']:
57             return { 'type': 'ir.actions.report.xml', 'report_name': 'account.general.ledger_landscape', 'datas': data}
58         return { 'type': 'ir.actions.report.xml', 'report_name': 'account.general.ledger', 'datas': data}
59
60 account_report_general_ledger()
61
62 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: