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 ##############################################################################
23 from openerp
.osv
import fields
, orm
26 class AccountReportPartnersLedgerWizard(orm
.TransientModel
):
27 """Will launch partner ledger report and pass required args"""
29 _inherit
= "account.common.partner.report"
30 _name
= "partners.ledger.webkit"
31 _description
= "Partner Ledger Report"
34 'amount_currency': fields
.boolean("With Currency",
35 help="It adds the currency column"),
36 'partner_ids': fields
.many2many('res.partner', string
='Filter on partner',
37 help="Only selected partners will be printed. "
38 "Leave empty to print all partners."),
39 'filter': fields
.selection([('filter_no', 'No Filters'),
40 ('filter_date', 'Date'),
41 ('filter_period', 'Periods')], "Filter by", required
=True,
42 help='Filter by date: no opening balance will be displayed. '
43 '(opening balance can only be computed based on period to be correct).'),
46 'amount_currency': False,
47 'result_selection': 'customer_supplier',
50 def _check_fiscalyear(self
, cr
, uid
, ids
, context
=None):
51 obj
= self
.read(cr
, uid
, ids
[0], ['fiscalyear_id', 'filter'], context
=context
)
52 if not obj
['fiscalyear_id'] and obj
['filter'] == 'filter_no':
58 'When no Fiscal year is selected, you must choose to '
59 'filter by periods or by date.',
63 def onchange_filter(self
, cr
, uid
, ids
, filter='filter_no', fiscalyear_id
=False, context
=None):
65 if filter == 'filter_no':
66 res
['value'] = {'period_from': False, 'period_to': False, 'date_from': False, 'date_to': False}
68 if filter == 'filter_date':
70 fyear
= self
.pool
.get('account.fiscalyear').browse(cr
, uid
, fiscalyear_id
, context
=context
)
71 date_from
= fyear
.date_start
72 date_to
= fyear
.date_stop
> time
.strftime('%Y-%m-%d') and time
.strftime('%Y-%m-%d') or fyear
.date_stop
74 date_from
, date_to
= time
.strftime('%Y-01-01'), time
.strftime('%Y-%m-%d')
75 res
['value'] = {'period_from': False, 'period_to': False, 'date_from': date_from
, 'date_to': date_to
}
76 if filter == 'filter_period' and fiscalyear_id
:
77 start_period
= end_period
= False
79 SELECT * FROM (SELECT p.id
81 LEFT JOIN account_fiscalyear f ON (p.fiscalyear_id = f.id)
83 AND COALESCE(p.special, FALSE) = FALSE
84 ORDER BY p.date_start ASC
85 LIMIT 1) AS period_start
87 SELECT * FROM (SELECT p.id
89 LEFT JOIN account_fiscalyear f ON (p.fiscalyear_id = f.id)
91 AND p.date_start < NOW()
92 AND COALESCE(p.special, FALSE) = FALSE
93 ORDER BY p.date_stop DESC
94 LIMIT 1) AS period_stop''', (fiscalyear_id
, fiscalyear_id
))
95 periods
= [i
[0] for i
in cr
.fetchall()]
97 start_period
= end_period
= periods
[0]
99 end_period
= periods
[1]
100 res
['value'] = {'period_from': start_period
, 'period_to': end_period
, 'date_from': False, 'date_to': False}
103 def pre_print_report(self
, cr
, uid
, ids
, data
, context
=None):
104 data
= super(AccountReportPartnersLedgerWizard
, self
).pre_print_report(cr
, uid
, ids
, data
, context
)
107 # will be used to attach the report on the main account
108 data
['ids'] = [data
['form']['chart_account_id']]
109 vals
= self
.read(cr
, uid
, ids
,
110 ['amount_currency', 'partner_ids'],
112 data
['form'].update(vals
)
115 def _print_report(self
, cursor
, uid
, ids
, data
, context
=None):
116 # we update form with display account value
117 data
= self
.pre_print_report(cursor
, uid
, ids
, data
, context
=context
)
118 return {'type': 'ir.actions.report.xml',
119 'report_name': 'account.account_report_partners_ledger_webkit',