1 # -*- encoding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.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 General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (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 General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 ##############################################################################
25 from report import report_sxw
28 #from addons.account.wizard import wizard_account_balance_report
37 class account_balance_landscape(rml_parse.rml_parse):
38 def __init__(self, cr, uid, name, context):
39 super(account_balance_landscape, self).__init__(cr, uid, name, context)
48 self.result_total = {}
49 self.total_for_perc=[]
50 self.localcontext.update({
53 'get_lines':self.get_lines,
54 'linesForTotal': self.linesForTotal,
55 'linesForYear': self.linesForYear,
56 'get_years':self.get_years,
57 'cal_total':self.cal_total,
58 'total_dr':self.total_dr,
59 'total_cr':self.total_cr
61 self.context = context
63 # def repeatIn(self, lst, name, nodes_parent=False,td=False,width=[],value=[],type=[]):
64 # self._node.data = ''
65 # node = self._find_parent(self._node, nodes_parent or parents)
66 # ns = node.nextSibling
68 # if value==['Cash','%']:
72 # value=['','Cash','%']
73 # type=['lable','lable','lable']
76 # value=[' ','','Cash','%']
77 # type=['string','lable','lable','lable']
78 # width=[65,130,65,65]
86 # type=['string','lable']
92 # type=['lable','lable']
95 # value=[' ','Cash','%']
96 # type=['string','lable','lable']
105 # type=['string','lable']
109 # if value==['year']:
112 # if pattern=='none':
116 # type=['string','string']
119 # if pattern=='none':
123 # type=['string','string']
127 # if pattern=='none':
131 # type=['string','string']
135 # if pattern=='none':
139 # type=['string','string']
142 # if value==['Debit','Credit','Balance']:
145 # if pattern=='none':
148 # value=[' ','Debit','Credit','Balance']
149 # type=['string','lable','lable','lable']
150 # width=[65,65,65,130]
152 # if pattern=='none':
155 # value=[' ','Debit','Credit','Balance']
156 # type=['string','lable','lable','lable']
157 # width=[65,65,65,65]
161 # if pattern=='none':
166 # value=[' ','Balance']
167 # type=['string','lable']
170 # if pattern=='none':
175 # value=[' ','Balance']
176 # type=['string','lable']
179 # if value==['debit','credit','balance']:
182 # if pattern=='none':
183 # value=['debit','credit','balance','balance_perc']
184 # type=['string','string','string','string']
185 # width=[65,65,65,65]
187 # value=[pattern,'debit','credit','balance','balance_perc']
188 # type=['string','string','string','string','string']
189 # width=[65,65,65,65,65]
191 # if pattern=='none':
192 # value=['debit','credit','balance']
193 # type=['string','string','string']
196 # value=[pattern,'debit','credit','balance']
197 # type=['string','string','string','string']
198 # width=[65,65,65,65]
202 # if pattern=='none':
203 # value=['balance','balance_perc']
204 # type=['string','string']
207 # value=[pattern,'balance','balance_perc']
208 # type=['string','string','string']
211 # if pattern=='none':
216 # value=[pattern,'balance']
217 # type=['string','string']
220 # if value==['sum_debit','sum_credit','']:
223 # if pattern=='none':
226 # value=[' ','sum_debit','sum_credit','']
227 # type=['string','string','string','lable']
228 # width=[65,65,65,130]
230 # if pattern=='none':
233 # value=[' ','sum_debit','sum_credit','']
234 # type=['string','string','string','lable']
235 # width=[65,65,65,65]
238 # if pattern=='none':
244 # type=['string','lable']
247 # if pattern=='none':
253 # type=['string','lable']
258 # for ns in node.childNodes :
259 # if ns and ns.nodeName!='#text' and ns.tagName=='blockTable' and td :
260 # width_str = ns._attrs['colWidths'].nodeValue
261 # ns.removeAttribute('colWidths')
262 # total_td = td * len(value)
268 # for t in range(td):
269 # for v in range(len(value)):
270 # if type[v] in ('String','STRING','string'):
271 # if (value[v]==" " or value[0]==pattern):
276 # width_str +=',%d'%width[v]
278 # width_str +=',%d'%width[v]
280 # width_str +=',%d'%width[v]
281 # ns.setAttribute('colWidths',width_str)
283 # child_list = ns.childNodes
286 # for child in child_list:
287 # if child.nodeName=='tr':
288 # lc = child.childNodes[1]
289 # for t in range(td):
293 # newnode = lc.cloneNode(1)
294 # temp2="%s['status']==1 and ( setTag('para','para',{'fontName':'Helvetica-bold'})) ]]"%(name)
296 # if type[i] in ('String','STRING','string'):
297 # if (v==" " or v==pattern) and i==0 and check==0:
299 # if newnode.childNodes[1].lastChild:
300 # newnode.childNodes[1].lastChild.data=""
303 # if newnode.childNodes[1].lastChild:
304 # newnode.childNodes[1].lastChild.data=""
306 # t1= "[[ %s['%s%d'] ]]"%(name,v,t)
307 # if v=="year" or v=="sum_debit" or v=="sum_credit":
308 # if newnode.childNodes[1].lastChild:
309 # newnode.childNodes[1].lastChild.data = t1
311 # if newnode.childNodes[1].lastChild:
312 # newnode.childNodes[1].lastChild.data = t1+"[["+temp2
313 ## newnode.childNodes[1].lastChild.data=[[ a['status']==1 and ( setTag('para','para',{'fontName':'Times-bold'})) ]]
314 # elif type[i] in ('Lable','LABLE','lable'):
315 # if newnode.childNodes[1].lastChild:
316 # newnode.childNodes[1].lastChild.data= v
318 # child.appendChild(newnode)
322 # return super(account_balance_landscape,self).repeatIn(lst, name, nodes_parent=False)
324 def linesForYear(self,form):
334 pattern=form['compare_pattern']
336 if form['show_columns']!=1:
339 show=form['show_columns']
341 if form['format_perc']!=1:
344 perc=form['format_perc']
346 if form['account_choice']=='bal_zero':
351 ctx = self.context.copy()
354 if form['select_account']!=False:
355 ref_ac=self.pool.get('account.account').browse(self.cr, self.uid,form['select_account'],ctx.copy())
356 if ref_ac.balance<>0.00:
357 ref_bal=ref_ac.balance
369 self.total_for_perc=self.linesForTotal(form,ids={},doneAccount={},level=1)
372 for t1 in range(0,len(form['fiscalyear'][0][2])):
373 locale.setlocale(locale.LC_ALL, '')
374 self.result_total["sum_credit" + str(t1)]=locale.format("%.2f", self.result_total["sum_credit" + str(t1)], grouping=True)
375 self.result_total["sum_debit" + str(t1)]=locale.format("%.2f", self.result_total["sum_debit" + str(t1)], grouping=True)
377 # self.result_total = {}
379 for temp in range(0,len(form['fiscalyear'][0][2])):
380 fy=self.pool.get('account.fiscalyear').name_get(self.cr,self.uid,form['fiscalyear'][0][2][temp])
381 years["year"+str(temp)]=fy[0][1][12:16]
386 def linesForTotal(self,form,ids={},doneAccount={},level=1):
387 if self.done_total==1:
390 return [self.result_total]
397 ctx = self.context.copy()
398 result_total_parent=[]
400 for id in form['fiscalyear'][0][2]:
403 ctx['fiscalyear'] = id
404 ctx['periods'] = form['periods'][0][2]
405 ctx['period_manner']=form['period_manner']
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)):
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']
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])
607 res['year']=fy[0][1][12:16]
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_balance/report/account_balance_landscape.rml', parser=account_balance_landscape, header=False)
665 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: