1 # -*- encoding: utf-8 -*-
2 ##############################################################################
4 # Author: Guewen Baconnier
5 # Copyright Camptocamp SA 2012
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 ##############################################################################
21 from openerp
.osv
import fields
, orm
24 class AccountReportOpenInvoicesWizard(orm
.TransientModel
):
25 """Will launch partner ledger report and pass required args"""
27 _inherit
= "partners.ledger.webkit"
28 _name
= "open.invoices.webkit"
29 _description
= "Open Invoices Report"
32 'group_by_currency': fields
.boolean('Group Partner by currency'),
33 'until_date': fields
.date("Clearance date",
35 help="""The clearance date is essentially a tool used for debtors provisionning calculation.
37 By default, this date is equal to the the end date (ie: 31/12/2011 if you select fy 2011).
39 By amending the clearance date, you will be, for instance, able to answer the question : 'based on my last year end debtors open invoices, which invoices are still unpaid today (today is my clearance date)?'
42 def _check_until_date(self
, cr
, uid
, ids
, context
=None):
43 def get_key_id(obj
, field
):
44 return obj
.get(field
) and obj
[field
][0] or False
46 obj
= self
.read(cr
, uid
, ids
[0], ['fiscalyear_id', 'period_to', 'date_to', 'until_date'], context
=context
)
47 min_date
= self
.default_until_date(cr
, uid
, ids
,
48 get_key_id(obj
, 'fiscalyear_id'),
49 get_key_id(obj
, 'period_to'),
52 if min_date
and obj
['until_date'] < min_date
:
57 (_check_until_date
, 'Clearance date must be the very last date of the last period or later.', ['until_date']),
60 def default_until_date(self
, cr
, uid
, ids
, fiscalyear_id
=False, period_id
=False, date_to
=False, context
=None):
62 # first priority: period or date filters
64 res_date
= self
.pool
.get('account.period').read(cr
, uid
, period_id
, ['date_stop'], context
=context
)['date_stop']
68 res_date
= self
.pool
.get('account.fiscalyear').read(cr
, uid
, fiscalyear_id
, ['date_stop'], context
=context
)['date_stop']
71 def onchange_fiscalyear(self
, cr
, uid
, ids
, fiscalyear
=False, period_id
=False, date_to
=False, until_date
=False, context
=None):
73 res
['value']['until_date'] = self
.default_until_date(cr
, uid
, ids
,
74 fiscalyear_id
=fiscalyear
,
80 def onchange_date_to(self
, cr
, uid
, ids
, fiscalyear
=False, period_id
=False, date_to
=False, until_date
=False, context
=None):
82 res
['value']['until_date'] = self
.default_until_date(cr
, uid
, ids
,
83 fiscalyear_id
=fiscalyear
,
89 def onchange_period_to(self
, cr
, uid
, ids
, fiscalyear
=False, period_id
=False, date_to
=False, until_date
=False, context
=None):
91 res
['value']['until_date'] = self
.default_until_date(cr
, uid
, ids
,
92 fiscalyear_id
=fiscalyear
,
98 def onchange_filter(self
, cr
, uid
, ids
, filter='filter_no', fiscalyear_id
=False, context
=None):
99 res
= super(AccountReportOpenInvoicesWizard
, self
).onchange_filter(cr
, uid
, ids
, filter=filter, fiscalyear_id
=fiscalyear_id
, context
=context
)
100 if res
.get('value', False):
101 res
['value']['until_date'] = self
.default_until_date(cr
, uid
, ids
,
102 fiscalyear_id
=fiscalyear_id
,
103 period_id
=res
['value'].get('period_to', False),
104 date_to
=res
['value'].get('date_to', False),
108 def pre_print_report(self
, cr
, uid
, ids
, data
, context
=None):
109 data
= super(AccountReportOpenInvoicesWizard
, self
).pre_print_report(cr
, uid
, ids
, data
, context
)
110 vals
= self
.read(cr
, uid
, ids
,
111 ['until_date', 'group_by_currency'],
113 data
['form'].update(vals
)
116 def _print_report(self
, cr
, uid
, ids
, data
, context
=None):
117 # we update form with display account value
118 data
= self
.pre_print_report(cr
, uid
, ids
, data
, context
=context
)
119 return {'type': 'ir.actions.report.xml',
120 'report_name': 'account.account_report_open_invoices_webkit',