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 ##############################################################################
27 from osv import fields, osv
29 from mx.DateTime import RelativeDateTime
31 from tools import config
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"/>
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"/>
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'}
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"/>
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."/>
92 def _check(self, cr, uid, data, context):
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)):
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'
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'
111 if len(data['form']['fiscalyear'][0][2])==3:
112 if data['form']['landscape']==1:
113 return 'report_landscape'
120 if len(data['form']['fiscalyear'][0][2])>2:
121 if data['form']['landscape']==1:
122 return 'report_landscape'
126 if data['form']['landscape']==1:
127 return 'report_landscape'
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'
149 'actions': [_get_defaults],
150 'result': {'type':'form', 'arch':dates_form, 'fields':dates_fields, 'state':[('end','Cancel'),('checkyear','Print')]}
154 'result': {'type':'form','arch':back_form,'fields':back_fields,'state':[('end','Ok')]}
158 'result': {'type':'form','arch':zero_form,'fields':zero_fields,'state':[('end','Ok')]}
162 'result': {'type':'choice','next_state':_check}
164 'report_landscape': {
166 'result': {'type':'print', 'report':'account.account.balance.landscape', 'state':'end'}
170 'result': {'type':'print', 'report':'account.balance.account.balance', 'state':'end'}
173 wizard_report('account.balance.account.balance.report')
175 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: