1
# -*- encoding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
6
# Copyright (c) 2009 Zikzakmedia S.L. (http://zikzakmedia.com) All Rights Reserved.
7
# Jordi Esteve <jesteve@zikzakmedia.com>
10
# This program is free software: you can redistribute it and/or modify
11
# it under the terms of the GNU General Public License as published by
12
# the Free Software Foundation, either version 3 of the License, or
13
# (at your option) any later version.
15
# This program is distributed in the hope that it will be useful,
16
# but WITHOUT ANY WARRANTY; without even the implied warranty of
17
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
# GNU General Public License for more details.
20
# You should have received a copy of the GNU General Public License
21
# along with this program. If not, see <http://www.gnu.org/licenses/>.
23
##############################################################################
28
from tools.translate import _
30
period_form = '''<?xml version="1.0"?>
31
<form string="Select period">
32
<field name="company_id"/>
33
<field name="display_account" required = "True"/>
35
<field name="fiscalyear"/>
36
<label colspan="2" string="(Keep empty for all open fiscal years)" align="0.0"/>
38
<separator string="Filters" colspan="4"/>
39
<field name="state" required="True"/>
41
<group attrs="{'invisible':[('state','=','none')]}" colspan="4">
42
<group attrs="{'invisible':[('state','=','byperiod')]}" colspan="4">
43
<separator string="Date Filter" colspan="4"/>
44
<field name="date_from"/>
45
<field name="date_to"/>
47
<group attrs="{'invisible':[('state','=','bydate')]}" colspan="4">
48
<separator string="Filter on Periods" colspan="4"/>
49
<field name="periods" colspan="4" nolabel="1"/>
55
'company_id': {'string': 'Company', 'type': 'many2one', 'relation': 'res.company', 'required': True},
57
'string':"Date/Period Filter",
59
'selection':[('bydate','By Date'),('byperiod','By Period'),('all','By Date and Period'),('none','No Filter')],
60
'default': lambda *a:'none'
63
'string':'Fiscal year',
65
'relation':'account.fiscalyear',
66
'help':'Keep empty for all open fiscal year'
68
'periods': {'string': 'Periods', 'type': 'many2many', 'relation': 'account.period', 'help': 'All periods if empty'},
69
'display_account':{'string':"Display accounts ", 'type':'selection', 'selection':[('bal_mouvement','With movements'),('bal_all','All'),('bal_solde', 'With balance is not equal to 0')]},
70
'date_from': {'string':"Start date", 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-01-01')},
71
'date_to': {'string':"End date", 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-%m-%d')},
74
account_form = '''<?xml version="1.0"?>
75
<form string="Select parent account">
76
<field name="Account_list" colspan="4"/>
80
'Account_list': {'string':'Account', 'type':'many2many', 'relation':'account.account', 'required':True ,'domain':[]},
84
class wizard_report(wizard.interface):
85
def _get_defaults(self, cr, uid, data, context={}):
86
user = pooler.get_pool(cr.dbname).get('res.users').browse(cr, uid, uid, context=context)
88
company_id = user.company_id.id
90
company_id = pooler.get_pool(cr.dbname).get('res.company').search(cr, uid, [('parent_id', '=', False)])[0]
91
data['form']['company_id'] = company_id
92
fiscalyear_obj = pooler.get_pool(cr.dbname).get('account.fiscalyear')
93
data['form']['fiscalyear'] = fiscalyear_obj.find(cr, uid)
94
# Better allow users to set theirs defaults
95
#periods_obj=pooler.get_pool(cr.dbname).get('account.period')
96
#data['form']['periods'] = periods_obj.search(cr, uid, [('fiscalyear_id','=',data['form']['fiscalyear'])])
97
#data['form']['display_account'] = 'bal_all'
98
data['form']['context'] = context
102
def _check_path(self, cr, uid, data, context):
103
if data['model'] == 'account.account':
106
return 'account_selection'
109
def _check_state(self, cr, uid, data, context):
110
if data['form']['state'] == 'bydate':
111
self._check_date(cr, uid, data, context)
115
def _check_date(self, cr, uid, data, context):
116
sql = """SELECT f.id, f.date_start, f.date_stop
117
FROM account_fiscalyear f
118
WHERE '%s' between f.date_start and f.date_stop """%(data['form']['date_from'])
120
res = cr.dictfetchall()
122
if (data['form']['date_to'] > res[0]['date_stop'] or data['form']['date_to'] < res[0]['date_start']):
123
raise wizard.except_wizard(_('UserError'),_('Date to must be set between %s and %s') % (res[0]['date_start'], res[0]['date_stop']))
127
raise wizard.except_wizard(_('UserError'),_('Date not in a defined fiscal year'))
134
'result': {'type':'choice','next_state':_check_path}
136
'account_selection': {
138
'result': {'type':'form', 'arch':account_form,'fields':account_fields, 'state':[('end','Cancel','gtk-cancel'),('checktype','Next','gtk-go-forward')]}
141
'actions': [_get_defaults],
142
'result': {'type':'form', 'arch':period_form, 'fields':period_fields, 'state':[('end','Cancel','gtk-cancel'),('report','Print','gtk-print')]}
145
'actions': [_check_state],
146
'result': {'type':'print', 'report':'account.balance.full', 'state':'end'}
149
wizard_report('account.balance.full.report')
150
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: