1 # -*- encoding: utf-8 -*-
2 ##############################################################################
4 # Author: Nicolas Bessi, Guewen Baconnier
5 # Copyright Camptocamp SA 2011
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 openerp
.osv
import fields
, orm
27 class AccountReportGeneralLedgerWizard(orm
.TransientModel
):
28 """Will launch general ledger report and pass required args"""
30 _inherit
= "account.common.account.report"
31 _name
= "general.ledger.webkit"
32 _description
= "General Ledger Report"
34 def _get_account_ids(self
, cr
, uid
, context
=None):
36 if context
.get('active_model', False) == 'account.account' and context
.get('active_ids', False):
37 res
= context
['active_ids']
41 'amount_currency': fields
.boolean("With Currency",
42 help="It adds the currency column"),
44 'display_account': fields
.selection([('bal_all', 'All'),
45 ('bal_mix', 'With transactions or non zero balance')],
48 'account_ids': fields
.many2many('account.account', string
='Filter on accounts',
49 help="""Only selected accounts will be printed. Leave empty to print all accounts."""),
50 'centralize': fields
.boolean('Activate Centralization', help='Uncheck to display all the details of centralized accounts.')
53 'amount_currency': False,
54 'display_account': 'bal_mix',
55 'account_ids': _get_account_ids
,
59 def _check_fiscalyear(self
, cr
, uid
, ids
, context
=None):
60 obj
= self
.read(cr
, uid
, ids
[0], ['fiscalyear_id', 'filter'], context
=context
)
61 if not obj
['fiscalyear_id'] and obj
['filter'] == 'filter_no':
66 (_check_fiscalyear
, 'When no Fiscal year is selected, you must choose to filter by periods or by date.', ['filter']),
69 def pre_print_report(self
, cr
, uid
, ids
, data
, context
=None):
70 data
= super(AccountReportGeneralLedgerWizard
, self
).pre_print_report(cr
, uid
, ids
, data
, context
)
71 # will be used to attach the report on the main account
72 data
['ids'] = [data
['form']['chart_account_id']]
73 vals
= self
.read(cr
, uid
, ids
,
79 data
['form'].update(vals
)
82 def onchange_filter(self
, cr
, uid
, ids
, filter='filter_no', fiscalyear_id
=False, context
=None):
84 if filter == 'filter_no':
91 if filter == 'filter_date':
93 fyear
= self
.pool
.get('account.fiscalyear').browse(cr
, uid
, fiscalyear_id
, context
=context
)
94 date_from
= fyear
.date_start
95 date_to
= fyear
.date_stop
> time
.strftime('%Y-%m-%d') and time
.strftime('%Y-%m-%d') or fyear
.date_stop
97 date_from
, date_to
= time
.strftime('%Y-01-01'), time
.strftime('%Y-%m-%d')
101 'date_from': date_from
,
104 if filter == 'filter_period' and fiscalyear_id
:
105 start_period
= end_period
= False
107 SELECT * FROM (SELECT p.id
108 FROM account_period p
109 LEFT JOIN account_fiscalyear f ON (p.fiscalyear_id = f.id)
111 AND COALESCE(p.special, FALSE) = FALSE
112 ORDER BY p.date_start ASC
113 LIMIT 1) AS period_start
115 SELECT * FROM (SELECT p.id
116 FROM account_period p
117 LEFT JOIN account_fiscalyear f ON (p.fiscalyear_id = f.id)
119 AND p.date_start < NOW()
120 AND COALESCE(p.special, FALSE) = FALSE
121 ORDER BY p.date_stop DESC
122 LIMIT 1) AS period_stop''', (fiscalyear_id
, fiscalyear_id
))
123 periods
= [i
[0] for i
in cr
.fetchall()]
125 start_period
= end_period
= periods
[0]
127 end_period
= periods
[1]
128 res
['value'] = {'period_from': start_period
, 'period_to': end_period
, 'date_from': False, 'date_to': False}
131 def _print_report(self
, cursor
, uid
, ids
, data
, context
=None):
132 # we update form with display account value
133 data
= self
.pre_print_report(cursor
, uid
, ids
, data
, context
=context
)
134 return {'type': 'ir.actions.report.xml',
135 'report_name': 'account.account_report_general_ledger_webkit',