1
# -*- encoding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
6
# Copyright (c) 2011 Noviat nv/sa (www.noviat.be). All rights reserved.
8
# This program is free software: you can redistribute it and/or modify
9
# it under the terms of the GNU Affero General Public License as
10
# published by the Free Software Foundation, either version 3 of the
11
# License, or (at your option) any later version.
13
# This program is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU Affero General Public License for more details.
18
# You should have received a copy of the GNU Affero General Public License
19
# along with this program. If not, see <http://www.gnu.org/licenses/>.
21
##############################################################################
24
from datetime import datetime, date, timedelta
26
from report import report_sxw
28
from tools.translate import _
30
logger=netsvc.Logger()
32
class account_cashflow_report(report_sxw.rml_parse):
34
def __init__(self, cr, uid, name, context):
35
super(account_cashflow_report, self).__init__(cr, uid, name, context=context)
36
#logger.notifyChannel('addons.'+__name__, netsvc.LOG_WARNING, '_init, name = %s, context = %s' % (name, context))
37
self.context = context
41
if not context.get('date_start', None):
42
raise osv.except_osv(_('Warning!'), _('This report is only available from the Cash Flow Chart!'))
45
format_date = self.pool.get('account.cashflow.code').format_date
46
date_start = datetime.strptime(context.get('date_start'), '%Y-%m-%d').date()
47
nbr_days = int(context.get('nbr_days'))
48
days = [date_start.isoformat()] + [(date_start + timedelta(days=x)).isoformat() for x in range(1, nbr_days)]
50
self.localcontext.update({
52
'timedelta': timedelta,
56
'name_get': self._name_get,
57
'lang': context.get('lang', 'en_US'),
58
'date_start': days[0],
59
'date_stop': days[-1],
62
'balance_period': self._balance_period,
65
def set_context(self, objects, data, ids, report_type=None):
68
context = self.context
69
cfc_obj = self.pool.get('account.cashflow.code')
70
active_cfc = objects[0]
72
def _get_toplevel_cfc(record):
74
parent = record.parent_id
76
toplevel_cfc = _get_toplevel_cfc(parent)
78
toplevel_cfc = _get_toplevel_cfc(active_cfc)
79
cfc_tree_ids = cfc_obj.search(cr, uid, [('parent_id', 'child_of', [toplevel_cfc.id])], context=context)
80
cfc_tree = cfc_obj.browse(cr, uid, cfc_tree_ids, context=context)
83
cfc_levels = {toplevel_cfc.id:0}
84
for cfc in cfc_tree[1:]:
85
if cfc.parent_id.id in cfc_levels:
86
cfc_level = cfc_levels[cfc.parent_id.id] + 1
89
cfc_levels[cfc.id] = cfc_level
90
data['cfc_levels'] = cfc_levels
91
super(account_cashflow_report, self).set_context(cfc_tree, data, cfc_tree_ids, report_type=report_type)
93
def _name_get(self, object):
94
res = self.pool.get(object._name).name_get(self.cr, self.uid, [object.id], self.context)
97
def _balance_period(self, ids, date_start=None, date_stop=None, day=None):
98
res = self.pool.get('account.cashflow.code')._balance_period(self.cr, self.uid, ids, context=self.context, date_start=date_start, date_stop=date_stop, day=day)
99
balance = res.values()[0]
102
report_sxw.report_sxw('report.account.cashflow.report',
103
'account.cashflow.code',
104
'account_cashflow/report/account_cashflow_report.mako',
105
parser=account_cashflow_report)
107
report_sxw.report_sxw('report.account.cashflow.summary.report',
108
'account.cashflow.code',
109
'account_cashflow/report/account_cashflow_summary_report.mako',
110
parser=account_cashflow_report)