1
# -*- encoding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
8
# This program is free software: you can redistribute it and/or modify
9
# it under the terms of the GNU General Public License as published by
10
# the Free Software Foundation, either version 3 of the License, or
11
# (at your option) any later version.
13
# This program is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU General Public License for more details.
18
# You should have received a copy of the GNU General Public License
19
# along with this program. If not, see <http://www.gnu.org/licenses/>.
21
##############################################################################
26
from tools.translate import _
31
fiscal_form = '''<?xml version="1.0"?>
32
<form string="Fiscal Statements">
33
<field name="company_id" colspan="4"/>
35
<field name="fiscalyear"/>
36
<field domain="[('fiscalyear_id','=',fiscalyear)]" name="period_id"/>
38
<field name="cost_center_id"/>
39
<field name="filter"/>
43
'company_id': {'string': 'Company', 'type': 'many2one', 'relation': 'res.company', 'required': True},
44
'period_id': {'string': 'Period', 'type': 'many2one', 'relation':'account.period', 'required': True},
45
'fiscal_statements_id': {'string': 'Fiscal Statement', 'type': 'many2one', 'relation': 'fiscal.statements', 'readonly': True},
47
'string':'Fiscal year', 'type': 'many2one', 'relation': 'account.fiscalyear', 'required': True,
48
'help': 'Keep empty for all open fiscal year',
49
'default': lambda *a:False},
50
'level': {'string': 'Level', 'type': 'integer', 'default': lambda *a:1},
51
'cost_center_id': {'string': 'Cost Center', 'type': 'many2one', 'relation': 'account.cost.center', 'help': 'Keep empty for all cost centers'},
52
'journal_ids': {'string': 'Journal', 'type': 'many2many', 'relation': 'account.journal', 'help': 'Keep empty for all journals'},
53
'filter':{'string':"Date/Period Filter", 'type':'selection', 'selection':[('bydate','By Date'),('byperiod','By Period')], 'default': lambda *a:'bydate'},
56
export_form = '''<?xml version="1.0"?>
57
<form string="Export Report">
58
<separator string="File" colspan="4"/>
59
<field name="file.csv"/>
63
'file.csv': {'string': 'File', 'type': 'binary', 'help': 'File created for this report', 'readonly':True},
69
def _get_period(self, cr, uid, data, context={}):
70
pool = pooler.get_pool(cr.dbname)
71
fiscalyear_obj = pool.get('account.fiscalyear')
72
ids = pool.get('account.period').find(cr, uid, context=context)
73
user = pooler.get_pool(cr.dbname).get('res.users').browse(cr, uid, uid, context=context)
75
company_id = user.company_id.id
77
company_id = pooler.get_pool(cr.dbname).get('res.company').search(cr, uid, [('parent_id', '=', False)])[0]
78
report_id = pool.get('financial.reports').search(cr, uid, [('company_id','=',company_id)])[0]
79
statement = pool.get('financial.reports').browse(cr, uid, report_id).statement_balance_id.id
84
'fiscalyear': fiscalyear_obj.find(cr, uid),
85
'company_id': company_id,
86
'period_id': period_id,
87
'fiscal_statements_id': statement
91
class wizard_fiscal_statements_balance(wizard.interface):
93
def _check_ouput_csv(self, cr, uid, data, context):
96
result = pooler.get_pool(cr.dbname).get('fiscal.statements').get_result(cr, uid, data, context)
97
buf = StringIO.StringIO()
102
if type(d).__name__ == 'unicode':
103
d = d.encode('utf-8')
104
if type(d)==types.StringType:
105
csvData += (csvData and ',' or '') + '"' + str(d.replace('\n',' ').replace('\t',' ')) + '"'
107
csvData += (csvData and ',' or '') + str(d)
108
buf.write(csvData+'\n')
109
out=base64.encodestring(buf.getvalue())
112
res['file.csv'] = out
115
def _check(self, cr, uid, data, context):
116
format = pooler.get_pool(cr.dbname).get('fiscal.statements').browse(cr, uid, data['form']['fiscal_statements_id'], context).format
117
if format == 'balance':
118
return 'report_balance'
120
return 'report_income'
124
'actions': [_get_period],
125
'result': {'type':'form', 'arch':fiscal_form, 'fields':fiscal_fields,
126
'state':[('end','Cancel','gtk-cancel'),('report_csv','Excel','gtk-convert'),('checkreport','Print','gtk-print')]}
129
'actions': [_check_ouput_csv],
130
'result': {'type':'form','arch':export_form,'fields':export_fields,'state':[('end','Ok')]},
134
'result': {'type':'choice','next_state':_check}
138
'result': {'type':'print', 'report':'fiscal_statements_balance', 'state':'end'}
142
'result': {'type':'print', 'report':'fiscal_statements_income', 'state':'end'}
145
wizard_fiscal_statements_balance('fiscal.statements.balance')
148
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: