1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2012 ISA s.r.l. (<http://www.isa.it>).
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
##############################################################################
23
from datetime import datetime, date, timedelta
24
from osv import osv, fields
25
from tools.translate import _
27
class central_journal_report(osv.osv_memory):
29
_name = 'wizard.central.journal.report'
30
_description = 'Printing parameters of the Center Journal'
32
def _get_fiscal_years(self, cr, uid, context=None):
33
fiscalyear_obj = self.pool.get('account.fiscalyear')
34
fiscalyear_ids = fiscalyear_obj.search(cr, uid, [], order="id desc")
36
for account_fiscalyear in fiscalyear_obj.browse(cr,uid,fiscalyear_ids) :
37
fiscalyears.append((account_fiscalyear.id, account_fiscalyear.name))
40
def _get_account_fiscalyear_data(self, cr, uid, ids, fiscalyear_id):
41
fiscalyear_obj = self.pool.get('account.fiscalyear')
42
fiscalyear_ids=fiscalyear_obj.search(cr,uid,[('id','=',fiscalyear_id),])
43
fiscalyear_data=fiscalyear_obj.browse(cr,uid,fiscalyear_ids)[0]
44
return fiscalyear_data
46
def _dates_control(self, str_date_start, str_date_end):
47
today_date = date.today()
48
date_start = datetime.strptime(str_date_start,"%Y-%m-%d").date()
49
date_stop = datetime.strptime(str_date_end,"%Y-%m-%d").date()
50
if date_start > date_stop:
51
raise osv.except_osv(_('Wrong dates !'), _("The end date must be greater than the initial date."))
53
if date_stop > today_date:
54
raise osv.except_osv(_('Wrong dates !'), _("The end date can not be greater than today's date."))
58
def _get_report_datas(self, cr, uid, ids, context={}):
59
wizard_form_datas = self.read(cr, uid, ids)[0]
62
'model': 'account.move.line',
63
'form': wizard_form_datas,
68
'date_move_line_from': fields.date('From date', required=True,),
69
'date_move_line_from_view': fields.date('From date'),
70
'date_move_line_to': fields.date('to date', required=True),
71
'fiscalyear': fields.selection(_get_fiscal_years, 'Fiscal Year', required=True),
72
'print_state': fields.selection([('draft','Draft'),('print','Ready for printing'),('printed','Printed')],'State',readonly=True),
75
def onchange_fiscalyear(self, cr, uid, ids, fiscalyear_id=False, context=None):
77
date_move_line_from = date_move_line_from_view = False
78
date_move_line_to = False
81
fiscalyear_data = self._get_account_fiscalyear_data(cr, uid, ids, fiscalyear_id)
83
today_date = date.today()
84
date_start = datetime.strptime(fiscalyear_data.date_start,"%Y-%m-%d").date()
85
date_stop = datetime.strptime(fiscalyear_data.date_stop,"%Y-%m-%d").date()
86
#set date_move_line_from
87
if fiscalyear_data.date_last_print:
88
date_last_print = datetime.strptime(fiscalyear_data.date_last_print,"%Y-%m-%d").date()
89
date_move_line_from = date_move_line_from_view = (date_last_print+timedelta(days=1)).__str__()
90
if date_last_print == date_stop:
91
date_move_line_from = date_move_line_from_view = date_start.__str__()
92
print_state = 'printed'
94
date_move_line_from = date_move_line_from_view = date_start.__str__()
95
#set date_move_line_to
96
if today_date > date_stop:
97
date_move_line_to = date_stop.__str__()
99
date_move_line_to = (today_date-timedelta(days=1)).__str__()
102
'date_move_line_from': date_move_line_from,
103
'date_move_line_from_view': date_move_line_from_view,
104
'date_move_line_to': date_move_line_to,
105
'print_state': print_state,
109
def print_report(self, cr, uid, ids, context={}):
110
datas = self._get_report_datas(cr, uid, ids, context)
111
if self._dates_control(datas['form']['date_move_line_from'],datas['form']['date_move_line_to']) == False:
113
datas['print_final'] = False
115
'type': 'ir.actions.report.xml',
116
'report_name': 'central_journal_report',
120
def print_report_final(self, cr, uid, ids, context={}):
121
datas = self._get_report_datas(cr, uid, ids, context)
122
if self._dates_control(datas['form']['date_move_line_from'],datas['form']['date_move_line_to']) == False:
124
datas['print_final'] = True
126
'type': 'ir.actions.report.xml',
127
'report_name': 'central_journal_report',
132
'print_state': 'draft',
135
central_journal_report()