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
##############################################################################
29
from tools.translate import _
31
account_form = '''<?xml version="1.0"?>
32
<form string="Select parent account">
33
<field name="Account_list" colspan="4"/>
37
'Account_list': {'string':'Account', 'type':'many2many', 'relation':'account.account', 'required':True ,'domain':[]},
40
period_form = '''<?xml version="1.0"?>
41
<form string="Select Date-Period">
42
<field name="company_id" colspan="4"/>
44
<field name="fiscalyear"/>
45
<label colspan="2" string="(Keep empty for all open fiscal years)" align="0.0"/>
48
<field name="display_account" required="True"/>
49
<field name="sortbydate" required="True"/>
50
<field name="landscape"/>
51
<field name="amount_currency"/>
52
<field name="initial_balance"/>
54
<separator string="Filters" colspan="4"/>
55
<field name="state" required="True"/>
57
<group attrs="{'invisible':[('state','=','none')]}" colspan="4">
58
<group attrs="{'invisible':[('state','=','byperiod')]}" colspan="4">
59
<separator string="Date Filter" colspan="4"/>
60
<field name="date_from"/>
61
<field name="date_to"/>
63
<group attrs="{'invisible':[('state','=','bydate')]}" colspan="4">
64
<separator string="Filter on Periods" colspan="4"/>
65
<field name="periods" colspan="4" nolabel="1"/>
71
'company_id': {'string': 'Company', 'type': 'many2one', 'relation': 'res.company', 'required': True},
73
'string':"Date/Period Filter",
75
'selection':[('bydate','By Date'),('byperiod','By Period'),('all','By Date and Period'),('none','No Filter')],
76
'default': lambda *a:'none'
78
'fiscalyear': {'string': 'Fiscal year', 'type': 'many2one', 'relation': 'account.fiscalyear',
79
'help': 'Keep empty for all open fiscal year'},
80
'periods': {'string': 'Periods', 'type': 'many2many', 'relation': 'account.period', 'help': 'All periods if empty'},
81
'sortbydate':{'string':"Sort by:", 'type':'selection', 'selection':[('sort_date','Date'),('sort_mvt','Movement')]},
82
'display_account':{'string':"Display accounts ", 'type':'selection', 'selection':[('bal_mouvement','With movements'),('bal_all','All'),('bal_solde','With balance is not equal to 0')]},
83
'landscape':{'string':"Landscape Mode", 'type':'boolean'},
84
'initial_balance':{'string':"Show initial balances", 'type':'boolean'},
85
'amount_currency':{'string':"With Currency", 'type':'boolean'},
86
'date_from': {'string':"Start date", 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-01-01')},
87
'date_to': {'string':"End date", 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-%m-%d')},
91
class wizard_report(wizard.interface):
92
def _get_defaults(self, cr, uid, data, context={}):
93
user = pooler.get_pool(cr.dbname).get('res.users').browse(cr, uid, uid, context=context)
95
company_id = user.company_id.id
97
company_id = pooler.get_pool(cr.dbname).get('res.company').search(cr, uid, [('parent_id', '=', False)])[0]
98
data['form']['company_id'] = company_id
99
fiscalyear_obj = pooler.get_pool(cr.dbname).get('account.fiscalyear')
100
data['form']['fiscalyear'] = fiscalyear_obj.find(cr, uid)
101
# Better allow users to set theirs defaults
102
#periods_obj=pooler.get_pool(cr.dbname).get('account.period')
103
#data['form']['periods'] =periods_obj.search(cr, uid, [('fiscalyear_id','=',data['form']['fiscalyear'])])
104
#data['form']['display_account']='bal_all'
105
#data['form']['sortbydate'] = 'sort_date'
106
#data['form']['landscape']=True
107
#data['form']['amount_currency'] = True
108
data['form']['context'] = context
112
def _check_path(self, cr, uid, data, context):
113
if data['model'] == 'account.account':
116
return 'account_selection'
119
def _check(self, cr, uid, data, context):
120
if data['form']['landscape']==True:
121
return 'report_landscape'
126
def _check_date(self, cr, uid, data, context):
127
sql = """SELECT f.id, f.date_start, f.date_stop
128
FROM account_fiscalyear f
129
WHERE '%s' between f.date_start and f.date_stop """ % (data['form']['date_from'])
131
res = cr.dictfetchall()
133
if (data['form']['date_to'] > res[0]['date_stop'] or data['form']['date_to'] < res[0]['date_start']):
134
raise wizard.except_wizard(_('UserError'),_('Date to must be set between %s and %s') % (str(res[0]['date_start']), str(res[0]['date_stop'])))
138
raise wizard.except_wizard(_('UserError'),_('Date not in a defined fiscal year'))
141
def _check_state(self, cr, uid, data, context):
142
if data['form']['state'] == 'bydate':
143
self._check_date(cr, uid, data, context)
144
# data['form']['fiscalyear'] = 0
146
# data['form']['fiscalyear'] = 1
153
'result': {'type':'choice','next_state':_check_path}
155
'account_selection': {
157
'result': {'type':'form', 'arch':account_form,'fields':account_fields, 'state':[('end','Cancel','gtk-cancel'),('checktype','Next','gtk-go-forward')]}
160
'actions': [_get_defaults],
161
'result': {'type':'form', 'arch':period_form, 'fields':period_fields, 'state':[('end','Cancel','gtk-cancel'),('checkreport','Print','gtk-print')]}
165
'result': {'type':'choice','next_state':_check}
167
'report_landscape': {
168
'actions': [_check_state],
169
'result': {'type':'print', 'report':'account.general.ledger.cumulative.landscape', 'state':'end'}
172
'actions': [_check_state],
173
'result': {'type':'print', 'report':'account.general.ledger.cumulative', 'state':'end'}
176
wizard_report('account.general.ledger.cumulative.report')
177
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: