1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # account_financial_report_webkit module for OpenERP
5 # Copyright (C) 2012 SYLEAM Info Services (<http://www.syleam.fr/>)
6 # Sebastien LANGE <sebastien.lange@syleam.fr>
8 # This file is a part of account_financial_report_webkit
10 # account_financial_report_webkit is free software: you can redistribute it and/or modify
11 # it under the terms of the GNU Affero General Public License as published by
12 # the Free Software Foundation, either version 3 of the License, or
13 # (at your option) any later version.
15 # account_financial_report_webkit is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU Affero General Public License for more details.
20 # You should have received a copy of the GNU Affero General Public License
21 # along with this program. If not, see <http://www.gnu.org/licenses/>.
23 ##############################################################################
25 from openerp
.osv
import fields
, orm
27 from lxml
import etree
30 class AccountReportPrintJournalWizard(orm
.TransientModel
):
31 """Will launch print journal report and pass requiered args"""
33 _inherit
= "account.common.account.report"
34 _name
= "print.journal.webkit"
35 _description
= "Journals Report"
38 'amount_currency': fields
.boolean("With Currency", help="It adds the currency column"),
42 'amount_currency': False,
44 'filter': 'filter_period',
47 def _check_fiscalyear(self
, cr
, uid
, ids
, context
=None):
48 obj
= self
.read(cr
, uid
, ids
[0], ['fiscalyear_id', 'filter'], context
=context
)
49 if not obj
['fiscalyear_id'] and obj
['filter'] == 'filter_no':
54 (_check_fiscalyear
, 'When no Fiscal year is selected, you must choose to filter by periods or by date.', ['filter']),
57 def pre_print_report(self
, cr
, uid
, ids
, data
, context
=None):
58 data
= super(AccountReportPrintJournalWizard
, self
).pre_print_report(cr
, uid
, ids
, data
, context
)
59 # will be used to attach the report on the main account
60 data
['ids'] = [data
['form']['chart_account_id']]
61 vals
= self
.read(cr
, uid
, ids
,
66 data
['form'].update(vals
)
69 def onchange_filter(self
, cr
, uid
, ids
, filter='filter_no', fiscalyear_id
=False, context
=None):
71 if filter == 'filter_no':
72 res
['value'] = {'period_from': False, 'period_to': False, 'date_from': False, 'date_to': False}
73 if filter == 'filter_date':
75 fyear
= self
.pool
.get('account.fiscalyear').browse(cr
, uid
, fiscalyear_id
, context
=context
)
76 date_from
= fyear
.date_start
77 date_to
= fyear
.date_stop
> time
.strftime('%Y-%m-%d') and time
.strftime('%Y-%m-%d') or fyear
.date_stop
79 date_from
, date_to
= time
.strftime('%Y-01-01'), time
.strftime('%Y-%m-%d')
80 res
['value'] = {'period_from': False, 'period_to': False, 'date_from': date_from
, 'date_to': date_to
}
81 if filter == 'filter_period' and fiscalyear_id
:
82 start_period
= end_period
= False
84 SELECT * FROM (SELECT p.id
86 LEFT JOIN account_fiscalyear f ON (p.fiscalyear_id = f.id)
88 AND COALESCE(p.special, FALSE) = FALSE
89 ORDER BY p.date_start ASC
90 LIMIT 1) AS period_start
92 SELECT * FROM (SELECT p.id
94 LEFT JOIN account_fiscalyear f ON (p.fiscalyear_id = f.id)
96 AND p.date_start < NOW()
97 AND COALESCE(p.special, FALSE) = FALSE
98 ORDER BY p.date_stop DESC
99 LIMIT 1) AS period_stop''', (fiscalyear_id
, fiscalyear_id
))
100 periods
= [i
[0] for i
in cr
.fetchall()]
102 start_period
= end_period
= periods
[0]
104 end_period
= periods
[1]
105 res
['value'] = {'period_from': start_period
, 'period_to': end_period
, 'date_from': False, 'date_to': False}
108 def _print_report(self
, cursor
, uid
, ids
, data
, context
=None):
109 context
= context
or {}
110 # we update form with display account value
111 data
= self
.pre_print_report(cursor
, uid
, ids
, data
, context
=context
)
112 return {'type': 'ir.actions.report.xml',
113 'report_name': 'account.account_report_print_journal_webkit',
116 AccountReportPrintJournalWizard()
118 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: