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 ##############################################################################
23 from osv import osv, fields
24 from tools.translate import _
26 class account_balance_report(osv.osv_memory):
28 This wizard will provide the account balance report by periods, between any two dates.
30 _name = 'account.balance.report'
31 _description = 'Account Balance Report'
33 'Account_list': fields.many2one('account.account', 'Chart account',
34 required=True, domain = [('parent_id','=',False)]),
35 'company_id': fields.many2one('res.company', 'Company', required=True),
36 'display_account': fields.selection([('bal_mouvement','With movements'),
38 ('bal_solde','With balance is not equal to 0'),
39 ],'Display accounts'),
40 'fiscalyear': fields.many2one('account.fiscalyear', 'Fiscal year', help='Keep empty for all open fiscal year'),
41 'state': fields.selection([('bydate','By Date'),
42 ('byperiod','By Period'),
43 ('all','By Date and Period'),
45 ],'Date/Period Filter'),
46 'periods': fields.many2many('account.period', 'period_account_balance_rel',
47 'report_id', 'period_id', 'Periods',
48 help='Keep empty for all open fiscal year'),
49 'date_from': fields.date('Start date', required=True),
50 'date_to': fields.date('End date', required=True),
53 def _get_company(self, cr, uid, context=None):
54 user_obj = self.pool.get('res.users')
55 company_obj = self.pool.get('res.company')
56 user = user_obj.browse(cr, uid, uid, context=context)
58 return user.company_id.id
60 return company_obj.search(cr, uid, [('parent_id', '=', False)])[0]
64 'date_from' : time.strftime('%Y-01-01'),
65 'date_to' : time.strftime('%Y-%m-%d'),
66 'company_id' : _get_company,
68 'display_account': 'bal_all',
71 def next_view(self, cr, uid, ids, context=None):
72 obj_model = self.pool.get('ir.model.data')
75 data = self.read(cr, uid, ids, [])[0]
76 context.update({'Account_list': data['Account_list']})
77 model_data_ids = obj_model.search(cr,uid,[('model','=','ir.ui.view'),('name','=','account_balance_report_view')])
78 resource_id = obj_model.read(cr, uid, model_data_ids, fields=['res_id'])[0]['res_id']
82 'res_model': 'account.balance.report',
83 'views': [(resource_id,'form')],
84 'type': 'ir.actions.act_window',
89 def check_state(self, cr, uid, ids, context=None):
93 data['ids'] = context['active_ids']
94 data['form'] = self.read(cr, uid, ids, ['date_from', 'company_id', 'state', 'periods', 'date_to', 'display_account', 'fiscalyear'])[0]
95 data['form']['Account_list'] = context.get('Account_list',[])
96 data['form']['context'] = context
97 if data['form']['Account_list']:
98 data['model'] = 'ir.ui.menu'
100 data['model'] = 'account.account'
102 if data['form']['state'] == 'bydate' :
103 return self._check_date(cr, uid, data, context)
104 elif data['form']['state'] == 'byperiod':
105 if not data['form']['periods']:
106 raise osv.except_osv(_('Warning'),_('Please Enter Periods ! '))
109 'type': 'ir.actions.report.xml',
110 'report_name': 'account.account.balance',
115 def _check_date(self, cr, uid, data, context=None):
119 SELECT f.id, f.date_start, f.date_stop FROM account_fiscalyear f Where %s between f.date_start and f.date_stop """
120 cr.execute(sql, (data['form']['date_from'],))
121 res = cr.dictfetchall()
124 if (data['form']['date_to'] > res[0]['date_stop'] or data['form']['date_to'] < res[0]['date_start']):
125 raise osv.except_osv(_('UserError'),_('Date to must be set between %s and %s') % (res[0]['date_start'], res[0]['date_stop']))
128 'type': 'ir.actions.report.xml',
129 'report_name': 'account.account.balance',
134 raise osv.except_osv(_('UserError'),_('Date not in a defined fiscal year'))
136 account_balance_report()
138 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: