1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
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 report import report_sxw
27
#from addons.account.wizard import wizard_account_balance_report
36
class account_balance_landscape(rml_parse.rml_parse):
37
def __init__(self, cr, uid, name, context):
38
super(account_balance_landscape, self).__init__(cr, uid, name, context=context)
47
self.result_total = {}
48
self.total_for_perc=[]
49
self.localcontext.update({
52
'get_lines':self.get_lines,
53
'linesForTotal': self.linesForTotal,
54
'linesForYear': self.linesForYear,
55
'get_years':self.get_years,
56
'cal_total':self.cal_total,
57
'total_dr':self.total_dr,
58
'total_cr':self.total_cr
60
self.context = context
62
# def repeatIn(self, lst, name, nodes_parent=False,td=False,width=[],value=[],type=[]):
63
# self._node.data = ''
64
# node = self._find_parent(self._node, nodes_parent or parents)
65
# ns = node.nextSibling
67
# if value==['Cash','%']:
71
# value=['','Cash','%']
72
# type=['lable','lable','lable']
75
# value=[' ','','Cash','%']
76
# type=['string','lable','lable','lable']
77
# width=[65,130,65,65]
85
# type=['string','lable']
91
# type=['lable','lable']
94
# value=[' ','Cash','%']
95
# type=['string','lable','lable']
104
# type=['string','lable']
108
# if value==['year']:
111
# if pattern=='none':
115
# type=['string','string']
118
# if pattern=='none':
122
# type=['string','string']
126
# if pattern=='none':
130
# type=['string','string']
134
# if pattern=='none':
138
# type=['string','string']
141
# if value==['Debit','Credit','Balance']:
144
# if pattern=='none':
147
# value=[' ','Debit','Credit','Balance']
148
# type=['string','lable','lable','lable']
149
# width=[65,65,65,130]
151
# if pattern=='none':
154
# value=[' ','Debit','Credit','Balance']
155
# type=['string','lable','lable','lable']
156
# width=[65,65,65,65]
160
# if pattern=='none':
165
# value=[' ','Balance']
166
# type=['string','lable']
169
# if pattern=='none':
174
# value=[' ','Balance']
175
# type=['string','lable']
178
# if value==['debit','credit','balance']:
181
# if pattern=='none':
182
# value=['debit','credit','balance','balance_perc']
183
# type=['string','string','string','string']
184
# width=[65,65,65,65]
186
# value=[pattern,'debit','credit','balance','balance_perc']
187
# type=['string','string','string','string','string']
188
# width=[65,65,65,65,65]
190
# if pattern=='none':
191
# value=['debit','credit','balance']
192
# type=['string','string','string']
195
# value=[pattern,'debit','credit','balance']
196
# type=['string','string','string','string']
197
# width=[65,65,65,65]
201
# if pattern=='none':
202
# value=['balance','balance_perc']
203
# type=['string','string']
206
# value=[pattern,'balance','balance_perc']
207
# type=['string','string','string']
210
# if pattern=='none':
215
# value=[pattern,'balance']
216
# type=['string','string']
219
# if value==['sum_debit','sum_credit','']:
222
# if pattern=='none':
225
# value=[' ','sum_debit','sum_credit','']
226
# type=['string','string','string','lable']
227
# width=[65,65,65,130]
229
# if pattern=='none':
232
# value=[' ','sum_debit','sum_credit','']
233
# type=['string','string','string','lable']
234
# width=[65,65,65,65]
237
# if pattern=='none':
243
# type=['string','lable']
246
# if pattern=='none':
252
# type=['string','lable']
257
# for ns in node.childNodes :
258
# if ns and ns.nodeName!='#text' and ns.tagName=='blockTable' and td :
259
# width_str = ns._attrs['colWidths'].nodeValue
260
# ns.removeAttribute('colWidths')
261
# total_td = td * len(value)
267
# for t in range(td):
268
# for v in range(len(value)):
269
# if type[v] in ('String','STRING','string'):
270
# if (value[v]==" " or value[0]==pattern):
275
# width_str +=',%d'%width[v]
277
# width_str +=',%d'%width[v]
279
# width_str +=',%d'%width[v]
280
# ns.setAttribute('colWidths',width_str)
282
# child_list = ns.childNodes
285
# for child in child_list:
286
# if child.nodeName=='tr':
287
# lc = child.childNodes[1]
288
# for t in range(td):
292
# newnode = lc.cloneNode(1)
293
# temp2="%s['status']==1 and ( setTag('para','para',{'fontName':'Helvetica-bold'})) ]]"%(name)
295
# if type[i] in ('String','STRING','string'):
296
# if (v==" " or v==pattern) and i==0 and check==0:
298
# if newnode.childNodes[1].lastChild:
299
# newnode.childNodes[1].lastChild.data=""
302
# if newnode.childNodes[1].lastChild:
303
# newnode.childNodes[1].lastChild.data=""
305
# t1= "[[ %s['%s%d'] ]]"%(name,v,t)
306
# if v=="year" or v=="sum_debit" or v=="sum_credit":
307
# if newnode.childNodes[1].lastChild:
308
# newnode.childNodes[1].lastChild.data = t1
310
# if newnode.childNodes[1].lastChild:
311
# newnode.childNodes[1].lastChild.data = t1+"[["+temp2
312
## newnode.childNodes[1].lastChild.data=[[ a['status']==1 and ( setTag('para','para',{'fontName':'Times-bold'})) ]]
313
# elif type[i] in ('Lable','LABLE','lable'):
314
# if newnode.childNodes[1].lastChild:
315
# newnode.childNodes[1].lastChild.data= v
317
# child.appendChild(newnode)
321
# return super(account_balance_landscape,self).repeatIn(lst, name, nodes_parent=False)
323
def linesForYear(self,form):
333
pattern=form['compare_pattern']
335
if form['show_columns']!=1:
338
show=form['show_columns']
340
if form['format_perc']!=1:
343
perc=form['format_perc']
345
if form['account_choice']=='bal_zero':
350
ctx = self.context.copy()
353
if form['select_account']!=False:
354
ref_ac=self.pool.get('account.account').browse(self.cr, self.uid,form['select_account'],ctx.copy())
355
if ref_ac.balance<>0.00:
356
ref_bal=ref_ac.balance
368
self.total_for_perc=self.linesForTotal(form,ids={},doneAccount={},level=1)
371
for t1 in range(0,len(form['fiscalyear'][0][2])):
372
locale.setlocale(locale.LC_ALL, '')
373
self.result_total["sum_credit" + str(t1)]=locale.format("%.2f", self.result_total["sum_credit" + str(t1)], grouping=True)
374
self.result_total["sum_debit" + str(t1)]=locale.format("%.2f", self.result_total["sum_debit" + str(t1)], grouping=True)
376
# self.result_total = {}
378
for temp in range(0,len(form['fiscalyear'][0][2])):
379
fy=self.pool.get('account.fiscalyear').name_get(self.cr,self.uid,form['fiscalyear'][0][2][temp])
380
years["year"+str(temp)]=fy[0][1][12:16]
385
def linesForTotal(self,form,ids={},doneAccount={},level=1):
386
if self.done_total==1:
389
return [self.result_total]
396
ctx = self.context.copy()
397
result_total_parent=[]
399
for id in form['fiscalyear'][0][2]:
402
ctx['fiscalyear'] = id
403
ctx['periods'] = form['periods'][0][2]
404
ctx['period_manner'] = form['period_manner']
405
ctx['state'] = form['context'].get('state','all')
406
tmp = self.pool.get('account.account').browse(self.cr, self.uid, ids, ctx.copy())
411
merged_accounts=zip(*accounts)
412
# used to check for the frst record so all sum_credit and sum_debit r set to 0.00
415
for entry in merged_accounts:
417
if entry[0].id in doneAccount:
419
doneAccount[entry[0].id] = 1
421
for k in range(0,len(entry)):
424
if entry[0].type <> 'view':
425
temp_credit+=entry[k].credit
426
temp_debit+=entry[k].debit
429
self.result_total["sum_credit" + str(k)]=0.00
430
self.result_total["sum_debit" + str(k)]=0.00
432
if form['account_choice']=='bal_zero':
433
if temp_credit<>temp_debit:
434
self.result_total["sum_credit" + str(k)]+=temp_credit
435
self.result_total["sum_debit" + str(k)]+=temp_debit
437
self.result_total["sum_credit" + str(k)]+=temp_credit
438
self.result_total["sum_debit" + str(k)]+=temp_debit
442
if entry[0].child_id:
443
ids2 = [(x.code,x.id) for x in entry[0].child_id]
446
result_total_parent = self.linesForTotal(form, [x[1] for x in ids2],doneAccount,level+1)
448
return [self.result_total]
450
def lines(self, form, ids={}, done={}, level=1):
457
ctx = self.context.copy()
459
for id in form['fiscalyear'][0][2]:
461
ctx['fiscalyear'] = id
462
ctx['periods'] = form['periods'][0][2]
463
ctx['period_manner']=form['period_manner']
464
ctx['state'] = form['context'].get('state','all')
465
tmp1 = self.pool.get('account.account').browse(self.cr, self.uid, ids,ctx.copy())
468
accounts.append(tmp1)
470
if level==1: #if parent is called,done is not empty when called again.
474
return cmp(x.code, y.code)
475
for n in range(0,len(accounts)):
476
accounts[n].sort(cmp_code)
478
merged_accounts=zip(*accounts)
480
for entry in merged_accounts:
484
if form['account_choice']!='all': # if checked,include empty a/c;not otherwise
487
if entry[0].id in done:
489
done[entry[0].id] = 1
491
if entry[0].child_id: # this is for parent account,dont check 0 for it
493
self.status=1 # for displaying it Bold
498
for i in range(0,len(entry)):
500
if entry[i].balance<>0.0:
507
if entry[i].credit <> 0.0 or entry[i].debit <> 0.0:
515
# this is the point where we skip those accounts which are encountered as empty ones
521
'code': entry[0].code,
522
'name': entry[0].name,
524
'status': self.status,
527
for j in range(0,len(entry)):
529
locale.setlocale(locale.LC_ALL, '')
530
res["debit"+str(j)]=locale.format("%.2f", entry[j].debit, grouping=True)
531
res["credit"+str(j)]=locale.format("%.2f", entry[j].credit, grouping=True)
532
res["balance"+str(j)]=locale.format("%.2f", entry[j].balance, grouping=True)
536
res["bal_cash"+str(j)]="0.00"
537
res["bal_perc"+str(j)]="0.00%"
539
temp_cash=entry[j].balance - entry[j-1].balance
540
res["bal_cash"+str(j)]=locale.format("%.2f", temp_cash, grouping=True)
541
if entry[j-1].balance<>0.00:
542
temp_perc=(entry[j].balance - entry[j-1].balance )*100/entry[j-1].balance
544
temp_perc=(entry[j].balance) *100
546
res["bal_perc"+str(j)]=locale.format("%.2f", temp_perc) + "%"
549
if ref_bal=='nothing':
555
if self.parent_bal==1:
556
res["balance_perc"+str(j)]="/"
558
if entry[j].balance==0.00:
559
if self.baldiv["baldiv"+str(level-1)+str(j)]<>0.00:
560
res["balance_perc"+str(j)]="0.00%"
562
res["balance_perc"+str(j)]="/"
564
if self.baldiv["baldiv"+str(level-1)+str(j)]<>0.00:
565
temp=self.baldiv["baldiv"+str(level-1)+str(j)]
566
temp1=(entry[j].balance * 100 )/ float(temp)
568
res["balance_perc" + str(j)]=str(temp1)+"%"
570
res["balance_perc"+str(j)]="/"
572
res["balance_perc"+str(j)]=str( (entry[j].balance * 100 )/ float(ref_bal)) + "%"
576
if entry[0].child_id:
578
for q in range(0,len(form['fiscalyear'][0][2])):
579
self.baldiv["baldiv"+str(level)+str(q)]=entry[q].balance
581
ids2 = [(x.code,x.id) for x in entry[0].child_id]
584
dir += self.lines(form, [x[1] for x in ids2], done, level+1)
586
for w in range(0,len(form['fiscalyear'][0][2])):
587
if entry[w].credit <> 0.0 or entry[w].debit <> 0.0 or entry[w].balance<>0.00:
595
result.pop(-1) # here we pop up the parent having its children as emprty accounts
601
def get_years(self,form):
604
for temp in range(0,len(form['fiscalyear'][0][2])):
606
fy=self.pool.get('account.fiscalyear').name_get(self.cr,self.uid,form['fiscalyear'][0][2][temp])
611
self.linesForYear(form)
614
def get_lines(self,year_dict,form):
618
line_l = self.lines(form)
619
self.cal_total(year_dict)
623
res['code'] = l['code']
624
res['name'] = l['name']
625
res['level'] = l['level']
626
for k,v in l.items():
627
if k.startswith('debit'+str(year_dict['last_str'])):
629
if k.startswith('credit'+str(year_dict['last_str'])):
631
if k.startswith('balance'+str(year_dict['last_str'])) and not k.startswith('balance_perc'+str(year_dict['last_str'])):
633
if k.startswith('balance_perc'+str(year_dict['last_str'])) and not k.startswith('balance'+str(year_dict['last_str'])):
634
res['balance_perc'] = v
635
if form['compare_pattern'] == 'bal_perc':
636
if k.startswith('bal_perc'+str(year_dict['last_str'])):
638
elif form['compare_pattern'] == 'bal_cash':
639
if k.startswith('bal_cash'+str(year_dict['last_str'])):
643
final_result.append(res)
646
def cal_total(self,year_dict):
647
total_l = self.result_total
649
for k,v in total_l.items():
650
if k.startswith('sum_debit'+str(year_dict['last_str'])):
652
elif k.startswith('sum_credit'+str(year_dict['last_str'])):
664
report_sxw.report_sxw('report.account.account.balance.landscape', 'account.account', 'addons/account/report/account_balance_landscape.rml', parser=account_balance_landscape, header=False)
665
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: