Launchpad automatic translations update.
[odoo/odoo.git] / addons / account_balance / wizard / wizard_account_balance_report.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 import wizard
23 import ir
24 import pooler
25 import time
26 import netsvc
27 from osv import fields, osv
28 import mx.DateTime
29 from mx.DateTime import RelativeDateTime
30
31 from tools import config
32
33
34 dates_form = '''<?xml version="1.0"?>
35 <form string="Customize Report">
36     <notebook tabpos="up">
37         <page string="Report Options">
38             <separator string="Select Fiscal Year(s)(Maximum Three Years)" colspan="4"/>
39             <label align="0.7" colspan="6" string="(If you do not select Fiscal year it will take all open fiscal years)"/>
40             <field name="fiscalyear" colspan="5" nolabel="1"/>
41             <field name="landscape" colspan="4"/>
42             <field name="show_columns" colspan="4"/>
43             <field name="format_perc" colspan="4"/>
44             <field name="select_account" colspan="4"/>
45             <field name="account_choice" colspan="4"/>
46             <field name="compare_pattern" colspan="4"/>
47
48         </page>
49
50         <page string="Select Period">
51             <field name="period_manner" colspan="4"/>
52             <separator string="Select Period(s)" colspan="4"/>
53             <field name="periods" colspan="4" nolabel="1"/>
54         </page>
55     </notebook>
56 </form>'''
57
58 dates_fields = {
59     'fiscalyear': {'string': 'Fiscal year', 'type': 'many2many', 'relation': 'account.fiscalyear'},
60     'select_account': {'string': 'Select Reference Account(for  % comparision)', 'type': 'many2one', 'relation': 'account.account','help': 'Keep empty for comparision to its parent'},
61     'account_choice': {'string': 'Show Accounts', 'type': 'selection','selection':[('all','All accounts'),('bal_zero','With balance is not equal to 0'),('moves','With movements')]},
62     'show_columns': {'string': 'Show Debit/Credit Information', 'type': 'boolean'},
63     'landscape': {'string': 'Show Report in Landscape Form', 'type': 'boolean'},
64     'format_perc': {'string': 'Show Comparision in %', 'type': 'boolean'},
65     'compare_pattern':{'string':"Compare Selected Years In Terms Of",'type':'selection','selection':[('bal_cash','Cash'),('bal_perc','Percentage'),('none','Don'+ "'" +'t Compare')]},
66     'period_manner':{'string':"Entries Selection Based on",'type':'selection','selection':[('actual','Financial Period'),('created','Creation Date')]},
67     'periods': {'string': 'Periods', 'type': 'many2many', 'relation': 'account.period', 'help': 'All periods if empty'}
68 }
69
70 back_form='''<?xml version="1.0"?>
71 <form string="Notification">
72 <separator string="You might have done following mistakes. Please correct them and try again." colspan="4"/>
73 <separator string="1. You have selected more than 3 years in any case." colspan="4"/>
74 <separator string="2. You have not selected 'Percentage' option, but you have selected more than 2 years." colspan="4"/>
75 <label string="You can select maximum 3 years. Please check again." colspan="4"/>
76 <separator string="3. You have selected 'Percentage' option with more than 2 years, but you have not selected landscape format." colspan="4"/>
77 <label string="You have to select 'Landscape' option. Please Check it." colspan="4"/>
78 </form>'''
79
80 back_fields={
81 }
82
83 zero_form='''<?xml version="1.0"?>
84 <form string="Notification">
85 <separator string="You have to select at least 1 Fiscal Year. Try again." colspan="4"/>
86 <label string="You may have selected the compare options with more than 1 year with credit/debit columns and % option.This can lead contents to be printed out of the paper.Please try again."/>
87 </form>'''
88
89 zero_fields={
90 }
91
92 def _check(self, cr, uid, data, context):
93
94         if (len(data['form']['fiscalyear'][0][2])==0) or (len(data['form']['fiscalyear'][0][2])>1 and (data['form']['compare_pattern']!='none') and (data['form']['format_perc']==1) and (data['form']['show_columns']==1) and (data['form']['landscape']!=1)):
95             return 'zero_years'
96
97         if ((len(data['form']['fiscalyear'][0][2])==3) and (data['form']['format_perc']!=1) and (data['form']['show_columns']!=1)):
98             if data['form']['landscape']==1:
99                 return 'report_landscape'
100             else:
101                 return 'report'
102
103
104         if data['form']['format_perc']==1:
105             if len(data['form']['fiscalyear'][0][2])<=2:
106                 if data['form']['landscape']==1:
107                     return 'report_landscape'
108                 else:
109                     return 'report'
110             else:
111                 if len(data['form']['fiscalyear'][0][2])==3:
112                     if data['form']['landscape']==1:
113                         return 'report_landscape'
114                     else:
115                         return 'backtoinit'
116                 else:
117                     return 'backtoinit'
118
119         else:
120             if len(data['form']['fiscalyear'][0][2])>2:
121                 if data['form']['landscape']==1:
122                     return 'report_landscape'
123                 else:
124                     return 'backtoinit'
125             else:
126                 if data['form']['landscape']==1:
127                     return 'report_landscape'
128                 else:
129                     return 'report'
130
131
132
133
134 class wizard_report(wizard.interface):
135     def _get_defaults(self, cr, uid, data, context={}):
136         data['form']['context'] = context
137         fiscalyear_obj = pooler.get_pool(cr.dbname).get('account.fiscalyear')
138         data['form']['fiscalyear']=[fiscalyear_obj.find(cr, uid)]
139 #       p_ids=pooler.get_pool(cr.dbname).get('account.period').search(cr,uid,[('fiscalyear_id','=',fiscalyear_obj.find(cr, uid))])
140 #       data['form']['periods']=p_ids
141         data['form']['compare_pattern']='none'
142         data['form']['account_choice']='moves'
143         data['form']['period_manner']='actual'
144         return data['form']
145
146
147     states = {
148         'init': {
149             'actions': [_get_defaults],
150             'result': {'type':'form', 'arch':dates_form, 'fields':dates_fields, 'state':[('end','Cancel'),('checkyear','Print')]}
151         },
152         'backtoinit': {
153             'actions': [],
154             'result': {'type':'form','arch':back_form,'fields':back_fields,'state':[('end','Ok')]}
155         },
156         'zero_years': {
157             'actions': [],
158             'result': {'type':'form','arch':zero_form,'fields':zero_fields,'state':[('end','Ok')]}
159         },
160         'checkyear': {
161             'actions': [],
162             'result': {'type':'choice','next_state':_check}
163         },
164         'report_landscape': {
165             'actions': [],
166             'result': {'type':'print', 'report':'account.account.balance.landscape', 'state':'end'}
167         },
168         'report': {
169             'actions': [],
170             'result': {'type':'print', 'report':'account.balance.account.balance', 'state':'end'}
171         }
172     }
173 wizard_report('account.balance.account.balance.report')
174
175 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
176