~willowit-openerp-team/willowit-openerp-addons/development

« back to all changes in this revision

Viewing changes to account_balance/report/account_balance_landscape.py

  • Committer: Deepak Seshadri
  • Date: 2011-04-04 07:04:07 UTC
  • Revision ID: deepak@willowit.com.au-20110404070407-8j9mnxzzgh53o24t
Remove irrelevant modules from this branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: utf-8 -*-
2
 
##############################################################################
3
 
#    
4
 
#    OpenERP, Open Source Management Solution
5
 
#    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
6
 
#
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.
11
 
#
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.
16
 
#
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/>.     
19
 
#
20
 
##############################################################################
21
 
 
22
 
import time
23
 
import locale
24
 
from report import report_sxw
25
 
import rml_parse
26
 
 
27
 
#from addons.account.wizard import wizard_account_balance_report
28
 
 
29
 
parents = {
30
 
    'tr':1,
31
 
    'li':1,
32
 
    'story': 0,
33
 
    'section': 0
34
 
}
35
 
 
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)
39
 
        self.flag=1
40
 
        self.dr_total= 0.00
41
 
        self.cr_total= 0.00
42
 
        self.parent_bal=0
43
 
        self.status=0
44
 
        self.done_total=0
45
 
        self.baldiv={}
46
 
        self.empty_parent=0
47
 
        self.result_total = {}
48
 
        self.total_for_perc=[]
49
 
        self.localcontext.update({
50
 
            'time': time,
51
 
            'lines': self.lines,
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
59
 
            })
60
 
        self.context = context
61
 
 
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
66
 
##start
67
 
#        if value==['Cash','%']:
68
 
#            if show==1:
69
 
#                if perc==1:
70
 
#                    if pattern=='none':
71
 
#                        value=['','Cash','%']
72
 
#                        type=['lable','lable','lable']
73
 
#                        width=[130,65,65]
74
 
#                    else:
75
 
#                        value=[' ','','Cash','%']
76
 
#                        type=['string','lable','lable','lable']
77
 
#                        width=[65,130,65,65]
78
 
#                else:
79
 
#                    if pattern=='none':
80
 
#                        value=['']
81
 
#                        type=['lable']
82
 
#                        width=[195]
83
 
#                    else:
84
 
#                        value=[' ','']
85
 
#                        type=['string','lable']
86
 
#                        width=[65,195]
87
 
#            else:
88
 
#                if perc==1:
89
 
#                    if pattern=='none':
90
 
#                        value=['Cash','%']
91
 
#                        type=['lable','lable']
92
 
#                        width=[65,65]
93
 
#                    else:
94
 
#                        value=[' ','Cash','%']
95
 
#                        type=['string','lable','lable']
96
 
#                        width=[65,65,65]
97
 
#                else:
98
 
#                    if pattern=='none':
99
 
#                        value=['']
100
 
#                        type=['lable']
101
 
#                        width=[65]
102
 
#                    else:
103
 
#                        value=[' ','']
104
 
#                        type=['string','lable']
105
 
#                        width=[65,65]
106
 
#
107
 
#
108
 
#        if value==['year']:
109
 
#            if show==1:
110
 
#                if perc==1:
111
 
#                    if pattern=='none':
112
 
#                        width=[260]
113
 
#                    else:
114
 
#                        value=[' ','year']
115
 
#                        type=['string','string']
116
 
#                        width=[65,260]
117
 
#                else:
118
 
#                    if pattern=='none':
119
 
#                        width=[195]
120
 
#                    else:
121
 
#                        value=[' ','year']
122
 
#                        type=['string','string']
123
 
#                        width=[65,195]
124
 
#            else:
125
 
#                if perc==1:
126
 
#                    if pattern=='none':
127
 
#                        width=[130]
128
 
#                    else:
129
 
#                        value=[' ','year']
130
 
#                        type=['string','string']
131
 
#                        width=[65,130]
132
 
#
133
 
#                else:
134
 
#                    if pattern=='none':
135
 
#                        width=[65]
136
 
#                    else:
137
 
#                        value=[' ','year']
138
 
#                        type=['string','string']
139
 
#                        width=[65,65]
140
 
#
141
 
#        if value==['Debit','Credit','Balance']:
142
 
#            if show==1:
143
 
#                if perc==1:
144
 
#                    if pattern=='none':
145
 
#                        width=[65,65,130]
146
 
#                    else:
147
 
#                        value=[' ','Debit','Credit','Balance']
148
 
#                        type=['string','lable','lable','lable']
149
 
#                        width=[65,65,65,130]
150
 
#                else:
151
 
#                    if pattern=='none':
152
 
#                        width=[65,65,65]
153
 
#                    else:
154
 
#                        value=[' ','Debit','Credit','Balance']
155
 
#                        type=['string','lable','lable','lable']
156
 
#                        width=[65,65,65,65]
157
 
#
158
 
#            else:
159
 
#                if perc==1:
160
 
#                    if pattern=='none':
161
 
#                        value=['Balance']
162
 
#                        type=['lable']
163
 
#                        width=[130]
164
 
#                    else:
165
 
#                        value=[' ','Balance']
166
 
#                        type=['string','lable']
167
 
#                        width=[65,130]
168
 
#                else:
169
 
#                    if pattern=='none':
170
 
#                        value=['Balance']
171
 
#                        type=['lable']
172
 
#                        width=[65]
173
 
#                    else:
174
 
#                        value=[' ','Balance']
175
 
#                        type=['string','lable']
176
 
#                        width=[65,65]
177
 
#
178
 
#        if value==['debit','credit','balance']:
179
 
#            if show==1:
180
 
#                if perc==1:
181
 
#                    if pattern=='none':
182
 
#                        value=['debit','credit','balance','balance_perc']
183
 
#                        type=['string','string','string','string']
184
 
#                        width=[65,65,65,65]
185
 
#                    else:
186
 
#                        value=[pattern,'debit','credit','balance','balance_perc']
187
 
#                        type=['string','string','string','string','string']
188
 
#                        width=[65,65,65,65,65]
189
 
#                else:
190
 
#                    if pattern=='none':
191
 
#                        value=['debit','credit','balance']
192
 
#                        type=['string','string','string']
193
 
#                        width=[65,65,65]
194
 
#                    else:
195
 
#                        value=[pattern,'debit','credit','balance']
196
 
#                        type=['string','string','string','string']
197
 
#                        width=[65,65,65,65]
198
 
#
199
 
#            else:
200
 
#                if perc==1:
201
 
#                    if pattern=='none':
202
 
#                        value=['balance','balance_perc']
203
 
#                        type=['string','string']
204
 
#                        width=[65,65]
205
 
#                    else:
206
 
#                        value=[pattern,'balance','balance_perc']
207
 
#                        type=['string','string','string']
208
 
#                        width=[65,65,65]
209
 
#                else:
210
 
#                    if pattern=='none':
211
 
#                        value=['balance']
212
 
#                        type=['string']
213
 
#                        width=[65]
214
 
#                    else:
215
 
#                        value=[pattern,'balance']
216
 
#                        type=['string','string']
217
 
#                        width=[65,65]
218
 
#
219
 
#        if value==['sum_debit','sum_credit','']:
220
 
#            if show==1:
221
 
#                if perc==1:
222
 
#                    if pattern=='none':
223
 
#                        width=[65,65,130]
224
 
#                    else:
225
 
#                        value=[' ','sum_debit','sum_credit','']
226
 
#                        type=['string','string','string','lable']
227
 
#                        width=[65,65,65,130]
228
 
#                else:
229
 
#                    if pattern=='none':
230
 
#                        width=[65,65,65]
231
 
#                    else:
232
 
#                        value=[' ','sum_debit','sum_credit','']
233
 
#                        type=['string','string','string','lable']
234
 
#                        width=[65,65,65,65]
235
 
#            else:
236
 
#                if perc==1:
237
 
#                    if pattern=='none':
238
 
#                        value=['']
239
 
#                        type=['lable']
240
 
#                        width=[130]
241
 
#                    else:
242
 
#                        value=[' ','']
243
 
#                        type=['string','lable']
244
 
#                        width=[65,130]
245
 
#                else:
246
 
#                    if pattern=='none':
247
 
#                        value=['']
248
 
#                        type=['lable']
249
 
#                        width=[65]
250
 
#                    else:
251
 
#                        value=[' ','']
252
 
#                        type=['string','lable']
253
 
#                        width=[65,65]
254
 
#
255
 
#        if not lst:
256
 
#            lst.append(1)
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)
262
 
#
263
 
#                if not width:
264
 
#                    for v in value:
265
 
#                        width.append(30)
266
 
#                check1=0
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):
271
 
#                                if check1==0:
272
 
#                                    check1=1
273
 
#                                    width_str +=',0.0'
274
 
#                                else:
275
 
#                                    width_str +=',%d'%width[v]
276
 
#                            else:
277
 
#                                width_str +=',%d'%width[v]
278
 
#                        else:
279
 
#                            width_str +=',%d'%width[v]
280
 
#                ns.setAttribute('colWidths',width_str)
281
 
#
282
 
#                child_list =  ns.childNodes
283
 
#
284
 
#                check=0
285
 
#                for child in child_list:
286
 
#                    if child.nodeName=='tr':
287
 
#                        lc = child.childNodes[1]
288
 
#                        for t in range(td):
289
 
#                            i=0
290
 
#                            for v in value:
291
 
#
292
 
#                                newnode = lc.cloneNode(1)
293
 
#                                temp2="%s['status']==1 and ( setTag('para','para',{'fontName':'Helvetica-bold'})) ]]"%(name)
294
 
##
295
 
#                                if type[i] in ('String','STRING','string'):
296
 
#                                    if (v==" " or v==pattern) and i==0 and check==0:
297
 
#                                        check=1
298
 
#                                        if newnode.childNodes[1].lastChild:
299
 
#                                            newnode.childNodes[1].lastChild.data=""
300
 
#                                    else:
301
 
#                                        if v==" ":
302
 
#                                            if newnode.childNodes[1].lastChild:
303
 
#                                                newnode.childNodes[1].lastChild.data=""
304
 
#                                        else:
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
309
 
#                                            else:
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
316
 
#
317
 
#                                child.appendChild(newnode)
318
 
#
319
 
#                                newnode=False
320
 
#                                i+=1
321
 
#        return super(account_balance_landscape,self).repeatIn(lst, name, nodes_parent=False)
322
 
#end
323
 
    def linesForYear(self,form):
324
 
        temp=0
325
 
        years={}
326
 
 
327
 
        global pattern
328
 
        global show
329
 
        global perc
330
 
        global bal_zero
331
 
        global ref_bal
332
 
 
333
 
        pattern=form['compare_pattern']
334
 
 
335
 
        if form['show_columns']!=1:
336
 
            show=0
337
 
        else:
338
 
            show=form['show_columns']
339
 
 
340
 
        if form['format_perc']!=1:
341
 
            perc=0
342
 
        else:
343
 
            perc=form['format_perc']
344
 
 
345
 
        if form['account_choice']=='bal_zero':
346
 
            bal_zero=0
347
 
        else:
348
 
            bal_zero=1
349
 
 
350
 
        ctx = self.context.copy()
351
 
 
352
 
        if perc==1:
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
357
 
                else:
358
 
                    ref_bal=1.00
359
 
            else:
360
 
                ref_bal='nothing'
361
 
        else:
362
 
            ref_bal='nothing'
363
 
 
364
 
 
365
 
        total_for_perc=[]
366
 
#       if perc==1:
367
 
        self.done_total=1
368
 
        self.total_for_perc=self.linesForTotal(form,ids={},doneAccount={},level=1)
369
 
        self.done_total=0
370
 
 
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)
375
 
#           self.flag=1
376
 
#           self.result_total = {}
377
 
 
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]
381
 
 
382
 
        return [years]
383
 
 
384
 
 
385
 
    def linesForTotal(self,form,ids={},doneAccount={},level=1):
386
 
        if self.done_total==1:
387
 
            self.done_total==1
388
 
        else:
389
 
            return [self.result_total]
390
 
        accounts=[]
391
 
        if not ids:
392
 
            ids = self.ids
393
 
        if not ids:
394
 
            return []
395
 
 
396
 
        ctx = self.context.copy()
397
 
        result_total_parent=[]
398
 
 
399
 
        for id in form['fiscalyear'][0][2]:
400
 
            tmp=[]
401
 
 
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())
407
 
 
408
 
            if len(tmp):
409
 
                accounts.append(tmp)
410
 
 
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
413
 
        if level==1:
414
 
            doneAccount={}
415
 
        for entry in merged_accounts:
416
 
 
417
 
            if entry[0].id in doneAccount:
418
 
                continue
419
 
            doneAccount[entry[0].id] = 1
420
 
 
421
 
            for k in range(0,len(entry)):
422
 
                temp_credit=0.00
423
 
                temp_debit=0.00
424
 
                if entry[0].type <> 'view':
425
 
                    temp_credit+=entry[k].credit
426
 
                    temp_debit+=entry[k].debit
427
 
 
428
 
                if self.flag==1:
429
 
                    self.result_total["sum_credit" + str(k)]=0.00
430
 
                    self.result_total["sum_debit" + str(k)]=0.00
431
 
 
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
436
 
                else:
437
 
                    self.result_total["sum_credit" + str(k)]+=temp_credit
438
 
                    self.result_total["sum_debit" + str(k)]+=temp_debit
439
 
 
440
 
            self.flag=2
441
 
 
442
 
            if entry[0].child_id:
443
 
                ids2 = [(x.code,x.id) for x in entry[0].child_id]
444
 
                ids2.sort()
445
 
 
446
 
                result_total_parent = self.linesForTotal(form, [x[1] for x in ids2],doneAccount,level+1)
447
 
 
448
 
        return [self.result_total]
449
 
 
450
 
    def lines(self, form, ids={}, done={}, level=1):
451
 
        accounts=[]
452
 
        if not ids:
453
 
            ids = self.ids
454
 
        if not ids:
455
 
            return []
456
 
        result = []
457
 
        ctx = self.context.copy()
458
 
        tmp1=[]
459
 
        for id in form['fiscalyear'][0][2]:
460
 
 
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())
466
 
 
467
 
            if len(tmp1):
468
 
                accounts.append(tmp1)
469
 
 
470
 
        if level==1:   #if parent is called,done is not empty when called again.
471
 
            done={}
472
 
 
473
 
        def cmp_code(x, y):
474
 
            return cmp(x.code, y.code)
475
 
        for n in range(0,len(accounts)):
476
 
            accounts[n].sort(cmp_code)
477
 
        common={}
478
 
        merged_accounts=zip(*accounts)
479
 
 
480
 
        for entry in merged_accounts:
481
 
            j=0
482
 
            checked=1
483
 
 
484
 
            if form['account_choice']!='all':    #  if checked,include empty a/c;not otherwise
485
 
                checked=0
486
 
 
487
 
            if entry[0].id in done:
488
 
                continue
489
 
            done[entry[0].id] = 1
490
 
 
491
 
            if entry[0].child_id:  # this is for parent account,dont check 0 for it
492
 
                checked=4
493
 
                self.status=1 # for displaying it Bold
494
 
            else:
495
 
                self.status=0
496
 
            if checked==0:
497
 
                i=0
498
 
                for i in range(0,len(entry)):
499
 
                    if bal_zero==0:
500
 
                        if entry[i].balance<>0.0:
501
 
                            checked=4
502
 
                            break
503
 
                        else:
504
 
                            checked=3
505
 
                            i=i+1
506
 
                    else:
507
 
                        if entry[i].credit <> 0.0 or entry[i].debit <> 0.0:
508
 
                            checked=4
509
 
                            break
510
 
                        else:
511
 
                            checked=3
512
 
                            i=i+1
513
 
 
514
 
            if checked==3:
515
 
                # this is the point where we skip those accounts which are encountered as empty ones
516
 
                continue
517
 
                self.empty_parent=0
518
 
            else:
519
 
                self.empty_parent=1
520
 
                res = {
521
 
                    'code': entry[0].code,
522
 
                    'name': entry[0].name,
523
 
                    'level': level,
524
 
                    'status': self.status,
525
 
                    }
526
 
 
527
 
                for j in range(0,len(entry)):
528
 
 
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)
533
 
 
534
 
 
535
 
                    if j==0:
536
 
                        res["bal_cash"+str(j)]="0.00"
537
 
                        res["bal_perc"+str(j)]="0.00%"
538
 
                    else:
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
543
 
                        else:
544
 
                            temp_perc=(entry[j].balance) *100
545
 
 
546
 
                        res["bal_perc"+str(j)]=locale.format("%.2f", temp_perc) + "%"
547
 
 
548
 
 
549
 
                    if ref_bal=='nothing':
550
 
                        if level==1:
551
 
                            self.parent_bal=1
552
 
                        else:
553
 
                            self.parent_bal=0
554
 
 
555
 
                        if self.parent_bal==1:
556
 
                            res["balance_perc"+str(j)]="/"
557
 
                        else:
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%"
561
 
                                else:
562
 
                                    res["balance_perc"+str(j)]="/"
563
 
                            else:
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)
567
 
                                    temp1=round(temp1,2)
568
 
                                    res["balance_perc" + str(j)]=str(temp1)+"%"
569
 
                                else:
570
 
                                    res["balance_perc"+str(j)]="/"
571
 
                    else:
572
 
                        res["balance_perc"+str(j)]=str( (entry[j].balance * 100 )/ float(ref_bal)) + "%"
573
 
 
574
 
            result.append(res)
575
 
 
576
 
            if entry[0].child_id:
577
 
 
578
 
                for q in range(0,len(form['fiscalyear'][0][2])):
579
 
                    self.baldiv["baldiv"+str(level)+str(q)]=entry[q].balance
580
 
 
581
 
                ids2 = [(x.code,x.id) for x in entry[0].child_id]
582
 
                ids2.sort()
583
 
                dir=[]
584
 
                dir += self.lines(form, [x[1] for x in ids2], done, level+1)
585
 
                if dir==[]:
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:
588
 
                            dont_pop=1
589
 
                            break
590
 
                        else:
591
 
                            dont_pop=0
592
 
                    if dont_pop==1:
593
 
                        result +=dir
594
 
                    else:
595
 
                        result.pop(-1)   # here we pop up the parent having its children as emprty accounts
596
 
                else:
597
 
                    result +=dir
598
 
 
599
 
        return result
600
 
    
601
 
    def get_years(self,form):
602
 
        result =[]
603
 
        res={}
604
 
        for temp in range(0,len(form['fiscalyear'][0][2])):
605
 
            res={}
606
 
            fy=self.pool.get('account.fiscalyear').name_get(self.cr,self.uid,form['fiscalyear'][0][2][temp])
607
 
            res['year']=fy[0][1]
608
 
            res['last_str']=temp
609
 
            
610
 
            result.append(res)
611
 
        self.linesForYear(form)
612
 
        return result
613
 
    
614
 
    def get_lines(self,year_dict,form):
615
 
        final_result = []
616
 
        line_l =[]
617
 
        res = {}         
618
 
        line_l = self.lines(form)
619
 
        self.cal_total(year_dict)
620
 
        if line_l:
621
 
            for l in line_l:
622
 
                res = {}
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'])):
628
 
                     res['debit'] = v  
629
 
                    if k.startswith('credit'+str(year_dict['last_str'])):
630
 
                     res['credit'] = v
631
 
                    if k.startswith('balance'+str(year_dict['last_str'])) and not k.startswith('balance_perc'+str(year_dict['last_str'])):
632
 
                     res['balance'] =v 
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'])):
637
 
                         res['pattern'] = v
638
 
                    elif form['compare_pattern'] == 'bal_cash':
639
 
                        if k.startswith('bal_cash'+str(year_dict['last_str'])):
640
 
                         res['pattern'] = v
641
 
                    else:
642
 
                         res['pattern'] = ''
643
 
                final_result.append(res)
644
 
        return final_result
645
 
 
646
 
    def cal_total(self,year_dict):
647
 
        total_l = self.result_total
648
 
        if total_l:
649
 
            for k,v in total_l.items():
650
 
                if k.startswith('sum_debit'+str(year_dict['last_str'])):
651
 
                    self.dr_total = v
652
 
                elif k.startswith('sum_credit'+str(year_dict['last_str'])):
653
 
                    self.cr_total = v
654
 
                else:
655
 
                    continue
656
 
        return True
657
 
    
658
 
    def total_dr(self):
659
 
        return self.dr_total
660
 
    
661
 
    def total_cr(self):
662
 
        return self.cr_total
663
 
 
664
 
report_sxw.report_sxw('report.account.account.balance.landscape', 'account.account', 'addons/account_balance/report/account_balance_landscape.rml', parser=account_balance_landscape, header=False)
665
 
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
666