1
# -*- encoding: utf-8 -*-
2
##############################################################################
4
# Copyright (c) 2004-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
5
# Copyright (c) 2009 Zikzakmedia S.L. (http://zikzakmedia.com) All Rights Reserved.
6
# Jordi Esteve <jesteve@zikzakmedia.com>
8
# WARNING: This program as such is intended to be used by professional
9
# programmers who take the whole responsability of assessing all potential
10
# consequences resulting from its eventual inadequacies and bugs
11
# End users who are looking for a ready-to-use solution with commercial
12
# garantees and support are strongly adviced to contract a Free Software
15
# This program is Free Software; you can redistribute it and/or
16
# modify it under the terms of the GNU General Public License
17
# as published by the Free Software Foundation; either version 2
18
# of the License, or (at your option) any later version.
20
# This program is distributed in the hope that it will be useful,
21
# but WITHOUT ANY WARRANTY; without even the implied warranty of
22
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
# GNU General Public License for more details.
25
# You should have received a copy of the GNU General Public License
26
# along with this program; if not, write to the Free Software
27
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29
##############################################################################
32
from report import report_sxw
36
from operator import itemgetter
38
class account_chart(rml_parse.rml_parse):
39
_name = 'report.account.account.chart.report'
42
def __init__(self, cr, uid, name, context):
43
super(account_chart, self).__init__(cr, uid, name, context)
44
self.localcontext.update({
48
self.context = context
51
def set_context(self, objects, data, ids, report_type = None):
53
if (data['model'] == 'account.account'):
56
new_ids.append(data['form']['account'])
57
objects = self.pool.get('account.account').browse(self.cr, self.uid, new_ids)
59
super(account_chart, self).set_context(objects, data, new_ids, report_type)
62
def lines(self,ids={}, done=None, level=1):
63
retour_unsort = self.get_result(ids,done)
64
return self.sort_result(retour_unsort,31)
67
def sort_result(self,account,rupture):
68
max_level = self.max_level_search(account)
74
while ind_type < len(account):
75
account_elem = account[ind_type]
77
'code' : account_elem['code'],
78
'name': account_elem['name'],
83
if account_elem['level'] < max_level:
84
res_sort['type_gd'] = 2;
85
res_sort['name_gd'] = account_elem['name']
86
# ind_type_dr = ind_type + rupture;
87
# if (ind_type_dr >= len(account)):
88
# account_result.append(res_sort)
92
# account_elem = account[ind_type_dr]
93
# res_sort['name_dr'] = account_elem['code']+ ' ' + account_elem['name']
94
# if account_elem['level'] < 5:
95
# res_sort['type_dr'] = 2
96
# res_sort['name_dr'] = account_elem['name']
99
account_result.append(res_sort)
102
# si on a remplis une page on fait la rupture de la page
103
# if (ind_rup >= rupture):
104
# # On multiplie la rupture par 2 pour repositionner le tableau correctement
106
# ind_type = ind_type + rupture
108
return account_result
111
def get_result(self,ids={},done=None,level=1):
119
accounts = self.pool.get('account.account').browse(self.cr, self.uid, ids,self.context)
121
return cmp(x.code, y.code)
122
accounts.sort(cmp_code)
123
for account in accounts:
124
if account.id in done:
128
'code': account.code,
129
'name' : account.name,
135
ids2 = [(x.code,x.id) for x in account.child_id]
137
result += self.get_result([x[1] for x in ids2], done,level+1)
140
def max_level_search(self,account_list):
141
result = sorted(account_list, key=itemgetter('level'))
143
return result[len(result)-1]['level']
148
report_sxw.report_sxw('report.account.account.chart.report', 'account.account','addons/account_financial_report/report/account_chart.rml', parser=account_chart, header=False)