[MERGE] lp:~xrg/openobject-addons/trunk-patch18
[odoo/odoo.git] / addons / account / wizard / account_report_balance_sheet.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 osv, fields
23 from tools.translate import _
24
25 class account_bs_report(osv.osv_memory):
26     """
27     This wizard will provide the account balance sheet report by periods, between any two dates.
28     """
29     _name = 'account.bs.report'
30     _inherit = "account.common.account.report"
31     _description = 'Account Balance Sheet Report'
32
33     def _get_def_reserve_account(self, cr, uid, context=None):
34         chart_id = self._get_account(cr, uid, context=context)
35         res = self.onchange_chart_id(cr, uid, [], chart_id, context=context)
36         if not res:
37             return False
38         return res['value']['reserve_account_id']
39
40     _columns = {
41         'display_type': fields.boolean("Landscape Mode"),
42         'reserve_account_id': fields.many2one('account.account', 'Reserve & Profit/Loss Account',
43                                       required=True,
44                                       help='This Account is used for transfering Profit/Loss ' \
45                                            '(Profit: Amount will be added, Loss: Amount will be duducted), ' \
46                                            'which is calculated from Profilt & Loss Report',
47                                       domain = [('type','=','payable')]),
48     }
49
50     _defaults={
51         'display_type': True,
52         'journal_ids': [],
53         'reserve_account_id': _get_def_reserve_account,
54     }
55
56     def onchange_chart_id(self, cr, uid, ids, chart_id, context=None):
57         if not chart_id:
58             return {}
59         account = self.pool.get('account.account').browse(cr, uid, chart_id , context=context)
60         if not account.company_id.property_reserve_and_surplus_account:
61             return {'value': {'reserve_account_id': False}}
62         return {'value': {'reserve_account_id': account.company_id.property_reserve_and_surplus_account.id}}
63
64
65     def _print_report(self, cr, uid, ids, data, context=None):
66         if context is None:
67             context = {}
68         data['form'].update(self.read(cr, uid, ids, ['display_type','reserve_account_id'])[0])
69         if not data['form']['reserve_account_id']:
70             raise osv.except_osv(_('Warning'),_('Please define the Reserve and Profit/Loss account for current user company !'))
71         data = self.pre_print_report(cr, uid, ids, data, context=context)
72         if data['form']['display_type']:
73             return {
74                 'type': 'ir.actions.report.xml',
75                 'report_name': 'account.balancesheet.horizontal',
76                 'datas': data,
77             }
78         else:
79             return {
80                 'type': 'ir.actions.report.xml',
81                 'report_name': 'account.balancesheet',
82                 'datas': data,
83             }
84
85 account_bs_report()
86
87 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: