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"/>
42
'company_id': {'string': 'Company', 'type': 'many2one', 'relation': 'res.company', 'required': True},
43
'period_id': {'string': 'Period', 'type': 'many2one', 'relation':'account.period', 'required': True},
44
'fiscal_statements_id': {'string': 'Fiscal Statement', 'type': 'many2one', 'relation': 'fiscal.statements', 'readonly': True},
46
'string':'Fiscal year', 'type': 'many2one', 'relation': 'account.fiscalyear', 'required': True,
47
'help': 'Keep empty for all open fiscal year',
48
'default': lambda *a:False},
49
'level': {'string': 'Level', 'type': 'integer', 'default': lambda *a:1},
50
'cost_center_id': {'string': 'Cost Center', 'type': 'many2one', 'relation': 'account.cost.center', 'help': 'Keep empty for all cost centers'},
51
'journal_ids': {'string': 'Journal', 'type': 'many2many', 'relation': 'account.journal', 'help': 'Keep empty for all journals'},
54
export_form = '''<?xml version="1.0"?>
55
<form string="Export Report">
56
<separator string="File" colspan="4"/>
61
'file': {'string': 'File', 'type': 'binary', 'help': 'File created for this report', 'readonly':True},
67
def _get_period(self, cr, uid, data, context={}):
68
pool = pooler.get_pool(cr.dbname)
69
fiscalyear_obj = pool.get('account.fiscalyear')
70
ids = pool.get('account.period').find(cr, uid, context=context)
71
user = pooler.get_pool(cr.dbname).get('res.users').browse(cr, uid, uid, context=context)
73
company_id = user.company_id.id
75
company_id = pooler.get_pool(cr.dbname).get('res.company').search(cr, uid, [('parent_id', '=', False)])[0]
76
report_id = pool.get('financial.reports').search(cr, uid, [('company_id','=',company_id)])[0]
77
statement = pool.get('financial.reports').browse(cr, uid, report_id).statement_balance_id.id
82
'fiscalyear': fiscalyear_obj.find(cr, uid),
83
'company_id': company_id,
84
'period_id': period_id,
85
'fiscal_statements_id': statement
89
class wizard_fiscal_statements_balance(wizard.interface):
91
def _check_ouput_csv(self, cr, uid, data, context):
94
result = pooler.get_pool(cr.dbname).get('fiscal.statements').get_result(cr, uid, data, context)
95
buf = StringIO.StringIO()
100
if type(d).__name__ == 'unicode':
101
d = d.encode('utf-8')
102
if type(d)==types.StringType:
103
csvData += (csvData and ',' or '') + '"' + str(d.replace('\n',' ').replace('\t',' ')) + '"'
105
csvData += (csvData and ',' or '') + str(d)
106
buf.write(csvData+'\n')
107
out=base64.encodestring(buf.getvalue())
113
def _check(self, cr, uid, data, context):
114
format = pooler.get_pool(cr.dbname).get('fiscal.statements').browse(cr, uid, data['form']['fiscal_statements_id'], context).format
115
if format == 'balance':
116
return 'report_balance'
118
return 'report_income'
122
'actions': [_get_period],
123
'result': {'type':'form', 'arch':fiscal_form, 'fields':fiscal_fields,
124
'state':[('end','Cancel','gtk-cancel'),('report_csv','Excel','gtk-convert'),('checkreport','Print','gtk-print')]}
127
'actions': [_check_ouput_csv],
128
'result': {'type':'form','arch':export_form,'fields':export_fields,'state':[('end','Ok')]},
132
'result': {'type':'choice','next_state':_check}
136
'result': {'type':'print', 'report':'fiscal_statements_balance', 'state':'end'}
140
'result': {'type':'print', 'report':'fiscal_statements_income', 'state':'end'}
143
wizard_fiscal_statements_balance('fiscal.statements.balance')
146
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: