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
##############################################################################
24
from osv import fields, osv
25
from tools.translate import _
29
class ifrs_report_wizard(osv.osv_memory):
31
""" Wizard que permite al usuario elegir que periodo quiere imprimir del año fiscal """
33
_name = 'ifrs.report.wizard'
34
_description = 'IFRS Report'
36
def onchange_company_id(self, cr, uid, ids, company_id, context=None):
37
context = context or {}
38
context['company_id'] = company_id
44
cur_id = self.pool.get('res.company').browse(
45
cr, uid, company_id, context=context).currency_id.id
46
fy_id = self.pool.get('account.fiscalyear').find(
47
cr, uid, context=context)
49
res['value'].update({'fiscalyear_id': fy_id})
50
res['value'].update({'currency_id': cur_id})
54
'period': fields.many2one('account.period', 'Force period', help='Fiscal period to assign to the invoice. Keep empty to use the period of the current date.'),
55
'fiscalyear_id': fields.many2one('account.fiscalyear', 'Fiscal Year', help='Fiscal Year'),
56
'company_id': fields.many2one('res.company', string='Company', ondelete='cascade', required=True, help='Company name'),
57
'currency_id': fields.many2one('res.currency', 'Currency', help="Currency at which this report will be expressed. If not selected will be used the one set in the company"),
58
'exchange_date': fields.date('Exchange Date', help='Date of change that will be printed in the report, with respect to the currency of the company'),
59
'report_type': fields.selection([
60
('all', 'All Fiscalyear'),
61
('per', 'Force Period')],
62
string='Type', required=True, help='Indicates if the report it will be printed for the entire fiscal year, or for a particular period'),
63
'columns': fields.selection([
64
('ifrs', 'Two Columns'),
65
('webkitaccount.ifrs_12', 'Twelve Columns'),
66
#('ifrs_12_partner_detail', 'With Partner Detail')
68
string='Number of Columns',
69
help='Number of columns that will be printed in the report:'
70
" -Two Colums(02),-Twelve Columns(12)"),
71
'target_move': fields.selection([('posted', 'All Posted Entries'),
72
('all', 'All Entries'),
73
], 'Target Moves', help='Print All Accounting Entries or just Posted Accounting Entries'),
79
'company_id': lambda self, cr, uid, c: self.pool.get('ifrs.ifrs').browse(cr, uid, c.get('active_id')).company_id.id,
80
'fiscalyear_id': lambda self, cr, uid, c: self.pool.get('ifrs.ifrs').browse(cr, uid, c.get('active_id')).fiscalyear_id.id,
81
'exchange_date': fields.date.today,
85
def default_get(self, cr, uid, fields, context=None):
88
res = super(ifrs_report_wizard, self).default_get(
89
cr, uid, fields, context=context)
90
# res.update({'uid_country':
91
# self._get_country_code(cr,uid,context=context)})
94
def _get_period(self, cr, uid, context={}):
96
""" Return the current period id """
98
account_period_obj = self.pool.get('account.period')
99
ids = account_period_obj.find(
100
cr, uid, time.strftime('%Y-%m-%d'), context=context)
104
def _get_fiscalyear(self, cr, uid, context={}, period_id=False):
106
""" Return fiscalyear id for the period_id given.
107
If period_id is nor given then return the current fiscalyear """
110
period_obj = self.pool.get(
111
'account.period').browse(cr, uid, period_id)
112
fiscalyear_id = period_obj.fiscalyear_id.id
114
fiscalyear_obj = self.pool.get('account.fiscalyear')
115
ids = fiscalyear_obj.find(cr, uid, time.strftime(
116
'%Y-%m-%d'), context=context)
120
def print_report(self, cr, uid, ids, context={}):
121
datas = {'ids': context.get('active_ids', [])}
122
wizard_ifrs = self.browse(cr, uid, ids, context=context)[0]
123
datas['report_type'] = str(wizard_ifrs.report_type)
124
datas['company'] = wizard_ifrs.company_id.id
125
datas['columns'] = str(wizard_ifrs.columns)
126
datas['target_move'] = wizard_ifrs.target_move
127
datas['exchange_date'] = wizard_ifrs.exchange_date
128
datas['currency_wizard'] = wizard_ifrs.currency_id.id
129
datas['currency_wizard_name'] = wizard_ifrs.currency_id.name
131
if datas['report_type'] == 'all':
132
datas['fiscalyear'] = wizard_ifrs.fiscalyear_id.id or self._get_fiscalyear(
133
cr, uid, context=context)
134
datas['period'] = False
136
datas['columns'] = 'ifrs'
137
datas['period'] = wizard_ifrs.period.id or self._get_period(
138
cr, uid, context=context)
139
datas['fiscalyear'] = self._get_fiscalyear(
140
cr, uid, context=context, period_id=datas['period'])
143
'type': 'ir.actions.report.xml',
144
'report_name': datas['columns'],
150
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: