You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

681 lines
31 KiB

  1. # -*- encoding: utf-8 -*-
  2. ###########################################################################
  3. # Module Writen to OpenERP, Open Source Management Solution
  4. # Copyright (C) OpenERP Venezuela (<http://openerp.com.ve>).
  5. # All Rights Reserved
  6. ###############Credits######################################################
  7. # Coded by: Humberto Arocha humberto@openerp.com.ve
  8. # Angelica Barrios angelicaisabelb@gmail.com
  9. # Jordi Esteve <jesteve@zikzakmedia.com>
  10. # Javier Duran <javieredm@gmail.com>
  11. # Planified by: Humberto Arocha
  12. # Finance by: LUBCAN COL S.A.S http://www.lubcancol.com
  13. # Audited by: Humberto Arocha humberto@openerp.com.ve
  14. #############################################################################
  15. # This program is free software: you can redistribute it and/or modify
  16. # it under the terms of the GNU General Public License as published by
  17. # the Free Software Foundation, either version 3 of the License, or
  18. # (at your option) any later version.
  19. #
  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.
  24. #
  25. # You should have received a copy of the GNU General Public License
  26. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  27. ##############################################################################
  28. import xml
  29. import copy
  30. from operator import itemgetter
  31. import time
  32. import datetime
  33. from report import report_sxw
  34. from tools import config
  35. from tools.translate import _
  36. class account_balance(report_sxw.rml_parse):
  37. def __init__(self, cr, uid, name, context):
  38. super(account_balance, self).__init__(cr, uid, name, context)
  39. self.sum_debit = 0.00
  40. self.sum_credit = 0.00
  41. self.sum_balance = 0.00
  42. self.sum_debit_fy = 0.00
  43. self.sum_credit_fy = 0.00
  44. self.sum_balance_fy = 0.00
  45. self.date_lst = []
  46. self.date_lst_string = ''
  47. self.localcontext.update({
  48. 'time': time,
  49. 'lines': self.lines,
  50. 'get_fiscalyear_text': self.get_fiscalyear_text,
  51. 'get_periods_and_date_text': self.get_periods_and_date_text,
  52. 'get_informe_text': self.get_informe_text,
  53. 'get_month':self.get_month,
  54. 'exchange_name':self.exchange_name,
  55. })
  56. self.context = context
  57. def get_fiscalyear_text(self, form):
  58. """
  59. Returns the fiscal year text used on the report.
  60. """
  61. fiscalyear_obj = self.pool.get('account.fiscalyear')
  62. fiscalyear = None
  63. if form.get('fiscalyear'):
  64. fiscalyear = fiscalyear_obj.browse(self.cr, self.uid, form['fiscalyear'])
  65. return fiscalyear.name or fiscalyear.code
  66. else:
  67. fiscalyear = fiscalyear_obj.browse(self.cr, self.uid, fiscalyear_obj.find(self.cr, self.uid))
  68. return "%s*" % (fiscalyear.name or fiscalyear.code)
  69. def get_informe_text(self, form):
  70. """
  71. Returns the header text used on the report.
  72. """
  73. inf_type = {
  74. 'BS' : _('Balance Sheet'),
  75. 'IS' : _('Income Statement'),
  76. }
  77. return inf_type[form['inf_type']]
  78. def get_month(self, form):
  79. '''
  80. return day, year and month
  81. '''
  82. if form['filter'] in ['bydate', 'all']:
  83. months=["Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre"]
  84. mes = months[time.strptime(form['date_to'],"%Y-%m-%d")[1]-1]
  85. ano = time.strptime(form['date_to'],"%Y-%m-%d")[0]
  86. dia = time.strptime(form['date_to'],"%Y-%m-%d")[2]
  87. return 'Período del '+self.formatLang(form['date_from'], date=True)+' al '+self.formatLang(form['date_to'], date=True)
  88. elif form['filter'] in ['byperiod', 'all']:
  89. aux=[]
  90. period_obj = self.pool.get('account.period')
  91. for period in period_obj.browse(self.cr, self.uid, form['periods']):
  92. aux.append(period.date_start)
  93. aux.append(period.date_stop)
  94. sorted(aux)
  95. return _('Período del ')+self.formatLang(aux[0], date=True)+_(' al ')+self.formatLang(aux[-1], date=True)
  96. def get_periods_and_date_text(self, form):
  97. """
  98. Returns the text with the periods/dates used on the report.
  99. """
  100. period_obj = self.pool.get('account.period')
  101. periods_str = None
  102. fiscalyear_id = form['fiscalyear'] or fiscalyear_obj.find(self.cr, self.uid)
  103. period_ids = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',fiscalyear_id),('special','=',False)])
  104. if form['filter'] in ['byperiod', 'all']:
  105. period_ids = form['periods']
  106. periods_str = ', '.join([period.name or period.code for period in period_obj.browse(self.cr, self.uid, period_ids)])
  107. dates_str = None
  108. if form['filter'] in ['bydate', 'all']:
  109. dates_str = self.formatLang(form['date_from'], date=True) + ' - ' + self.formatLang(form['date_to'], date=True) + ' '
  110. return {'periods':periods_str, 'date':dates_str}
  111. def special_period(self, periods):
  112. period_obj = self.pool.get('account.period')
  113. period_brw = period_obj.browse(self.cr, self.uid, periods)
  114. period_counter = [True for i in period_brw if not i.special]
  115. if not period_counter:
  116. return True
  117. return False
  118. def exchange_name(self, form):
  119. self.from_currency_id = self.get_company_currency(form['company_id'] and type(form['company_id']) in (list,tuple) and form['company_id'][0] or form['company_id'])
  120. if not form['currency_id']:
  121. self.to_currency_id = self.from_currency_id
  122. else:
  123. self.to_currency_id = form['currency_id'] and type(form['currency_id']) in (list, tuple) and form['currency_id'][0] or form['currency_id']
  124. return self.pool.get('res.currency').browse(self.cr, self.uid, self.to_currency_id).name
  125. def exchange(self, from_amount):
  126. if self.from_currency_id == self.to_currency_id:
  127. return from_amount
  128. curr_obj = self.pool.get('res.currency')
  129. return curr_obj.compute(self.cr, self.uid, self.from_currency_id, self.to_currency_id, from_amount)
  130. def get_company_currency(self, company_id):
  131. rc_obj = self.pool.get('res.company')
  132. return rc_obj.browse(self.cr, self.uid, company_id).currency_id.id
  133. def get_company_accounts(self, company_id, acc='credit'):
  134. rc_obj = self.pool.get('res.company')
  135. if acc=='credit':
  136. return [brw.id for brw in rc_obj.browse(self.cr, self.uid, company_id).credit_account_ids]
  137. else:
  138. return [brw.id for brw in rc_obj.browse(self.cr, self.uid, company_id).debit_account_ids]
  139. def lines(self, form, level=0):
  140. """
  141. Returns all the data needed for the report lines
  142. (account info plus debit/credit/balance in the selected period
  143. and the full year)
  144. """
  145. account_obj = self.pool.get('account.account')
  146. period_obj = self.pool.get('account.period')
  147. fiscalyear_obj = self.pool.get('account.fiscalyear')
  148. def _get_children_and_consol(cr, uid, ids, level, context={},change_sign=False):
  149. aa_obj = self.pool.get('account.account')
  150. ids2=[]
  151. for aa_brw in aa_obj.browse(cr, uid, ids, context):
  152. if aa_brw.child_id and aa_brw.level < level and aa_brw.type !='consolidation':
  153. if not change_sign:
  154. ids2.append([aa_brw.id,True, False,aa_brw])
  155. ids2 += _get_children_and_consol(cr, uid, [x.id for x in aa_brw.child_id], level, context,change_sign=change_sign)
  156. if change_sign:
  157. ids2.append(aa_brw.id)
  158. else:
  159. ids2.append([aa_brw.id,False,True,aa_brw])
  160. else:
  161. if change_sign:
  162. ids2.append(aa_brw.id)
  163. else:
  164. ids2.append([aa_brw.id,True,True,aa_brw])
  165. return ids2
  166. #############################################################################
  167. # CONTEXT FOR ENDIND BALANCE #
  168. #############################################################################
  169. def _ctx_end(ctx):
  170. ctx_end = ctx
  171. ctx_end['filter'] = form.get('filter','all')
  172. ctx_end['fiscalyear'] = fiscalyear.id
  173. #~ ctx_end['periods'] = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',fiscalyear.id),('special','=',False)])
  174. if ctx_end['filter'] not in ['bydate','none']:
  175. special = self.special_period(form['periods'])
  176. else:
  177. special = False
  178. if form['filter'] in ['byperiod', 'all']:
  179. if special:
  180. ctx_end['periods'] = period_obj.search(self.cr, self.uid, [('id','in',form['periods'] or ctx_end.get('periods',False))])
  181. else:
  182. ctx_end['periods'] = period_obj.search(self.cr, self.uid, [('id','in',form['periods'] or ctx_end.get('periods',False)),('special','=',False)])
  183. if form['filter'] in ['bydate','all','none']:
  184. ctx_end['date_from'] = form['date_from']
  185. ctx_end['date_to'] = form['date_to']
  186. return ctx_end.copy()
  187. def missing_period(ctx_init):
  188. ctx_init['fiscalyear'] = fiscalyear_obj.search(self.cr, self.uid, [('date_stop','<',fiscalyear.date_start)],order='date_stop') and \
  189. fiscalyear_obj.search(self.cr, self.uid, [('date_stop','<',fiscalyear.date_start)],order='date_stop')[-1] or []
  190. ctx_init['periods'] = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',ctx_init['fiscalyear']),('date_stop','<',fiscalyear.date_start)])
  191. return ctx_init
  192. #############################################################################
  193. # CONTEXT FOR INITIAL BALANCE #
  194. #############################################################################
  195. def _ctx_init(ctx):
  196. ctx_init = self.context.copy()
  197. ctx_init['filter'] = form.get('filter','all')
  198. ctx_init['fiscalyear'] = fiscalyear.id
  199. if form['filter'] in ['byperiod', 'all']:
  200. ctx_init['periods'] = form['periods']
  201. if not ctx_init['periods']:
  202. ctx_init = missing_period(ctx_init.copy())
  203. date_start = min([period.date_start for period in period_obj.browse(self.cr, self.uid, ctx_init['periods'])])
  204. ctx_init['periods'] = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',fiscalyear.id),('date_stop','<=',date_start)])
  205. elif form['filter'] in ['bydate']:
  206. ctx_init['date_from'] = fiscalyear.date_start
  207. ctx_init['date_to'] = form['date_from']
  208. ctx_init['periods'] = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',fiscalyear.id),('date_stop','<=',ctx_init['date_to'])])
  209. elif form['filter'] == 'none':
  210. ctx_init['periods'] = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',fiscalyear.id),('special','=',True)])
  211. date_start = min([period.date_start for period in period_obj.browse(self.cr, self.uid, ctx_init['periods'])])
  212. ctx_init['periods'] = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',fiscalyear.id),('date_start','<=',date_start),('special','=',True)])
  213. return ctx_init.copy()
  214. def z(n):
  215. return abs(n) < 0.005 and 0.0 or n
  216. self.from_currency_id = self.get_company_currency(form['company_id'] and type(form['company_id']) in (list,tuple) and form['company_id'][0] or form['company_id'])
  217. if not form['currency_id']:
  218. self.to_currency_id = self.from_currency_id
  219. else:
  220. self.to_currency_id = form['currency_id'] and type(form['currency_id']) in (list, tuple) and form['currency_id'][0] or form['currency_id']
  221. if form.has_key('account_list') and form['account_list']:
  222. account_ids = form['account_list']
  223. del form['account_list']
  224. credit_account_ids = self.get_company_accounts(form['company_id'] and type(form['company_id']) in (list,tuple) and form['company_id'][0] or form['company_id'],'credit')
  225. print 'Primer print de credit_account_ids ', credit_account_ids
  226. debit_account_ids = self.get_company_accounts(form['company_id'] and type(form['company_id']) in (list,tuple) and form['company_id'][0] or form['company_id'],'debit')
  227. print 'Primer print de debit_account_ids ', debit_account_ids
  228. if form.get('fiscalyear'):
  229. if type(form.get('fiscalyear')) in (list,tuple):
  230. fiscalyear = form['fiscalyear'] and form['fiscalyear'][0]
  231. elif type(form.get('fiscalyear')) in (int,):
  232. fiscalyear = form['fiscalyear']
  233. fiscalyear = fiscalyear_obj.browse(self.cr, self.uid, fiscalyear)
  234. ################################################################
  235. # Get the accounts #
  236. ################################################################
  237. account_ids = _get_children_and_consol(self.cr, self.uid, account_ids, form['display_account_level'] and form['display_account_level'] or 100,self.context)
  238. credit_account_ids = _get_children_and_consol(self.cr, self.uid, credit_account_ids, 100,self.context,change_sign=True)
  239. print 'credit_account_ids ', credit_account_ids
  240. debit_account_ids = _get_children_and_consol(self.cr, self.uid, debit_account_ids, 100,self.context,change_sign=True)
  241. print 'debit_account_ids ', debit_account_ids
  242. credit_account_ids = list(set(credit_account_ids) - set(debit_account_ids))
  243. print 'Segundo print de credit_account_ids ', credit_account_ids
  244. #
  245. # Generate the report lines (checking each account)
  246. #
  247. tot_check = False
  248. if form['columns'] == 'qtr':
  249. period_ids = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',fiscalyear.id),('special','=',False)],order='date_start asc')
  250. a=0
  251. l=[]
  252. p=[]
  253. for x in period_ids:
  254. a+=1
  255. if a<3:
  256. l.append(x)
  257. else:
  258. l.append(x)
  259. p.append(l)
  260. l=[]
  261. a=0
  262. #~ period_ids = p
  263. elif form['columns'] == 'thirteen':
  264. period_ids = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',fiscalyear.id),('special','=',False)],order='date_start asc')
  265. if form['columns'] == 'qtr':
  266. tot_bal1 = 0.0
  267. tot_bal2 = 0.0
  268. tot_bal3 = 0.0
  269. tot_bal4 = 0.0
  270. tot_bal5 = 0.0
  271. elif form['columns'] == 'thirteen':
  272. tot_bal1 = 0.0
  273. tot_bal2 = 0.0
  274. tot_bal3 = 0.0
  275. tot_bal4 = 0.0
  276. tot_bal5 = 0.0
  277. tot_bal6 = 0.0
  278. tot_bal7 = 0.0
  279. tot_bal8 = 0.0
  280. tot_bal9 = 0.0
  281. tot_bal10 = 0.0
  282. tot_bal11 = 0.0
  283. tot_bal12 = 0.0
  284. tot_bal13 = 0.0
  285. else:
  286. ctx_init = _ctx_init(self.context.copy())
  287. ctx_end = _ctx_end(self.context.copy())
  288. tot_bin = 0.0
  289. tot_deb = 0.0
  290. tot_crd = 0.0
  291. tot_ytd = 0.0
  292. tot_eje = 0.0
  293. res = {}
  294. result_acc = []
  295. tot = {}
  296. for aa_id in account_ids:
  297. id = aa_id[0]
  298. #
  299. # Check if we need to include this level
  300. #
  301. if not form['display_account_level'] or aa_id[3].level <= form['display_account_level']:
  302. res = {
  303. 'id' : id,
  304. 'type' : aa_id[3].type,
  305. 'code' : aa_id[3].code,
  306. 'name' : (aa_id[2] and not aa_id[1]) and 'TOTAL %s'%(aa_id[3].name.upper()) or aa_id[3].name,
  307. 'parent_id' : aa_id[3].parent_id and aa_id[3].parent_id.id,
  308. 'level' : aa_id[3].level,
  309. 'label' : aa_id[1],
  310. 'total' : aa_id[2],
  311. 'change_sign' : credit_account_ids and (id in credit_account_ids and -1 or 1) or 1
  312. }
  313. if form['columns'] == 'qtr':
  314. pn = 1
  315. print 'PERIODOS DEL QTR ', p
  316. for p_id in p:
  317. form['periods'] = p_id
  318. ctx_init = _ctx_init(self.context.copy())
  319. aa_brw_init = account_obj.browse(self.cr, self.uid, id, ctx_init)
  320. ctx_end = _ctx_end(self.context.copy())
  321. aa_brw_end = account_obj.browse(self.cr, self.uid, id, ctx_end)
  322. if form['inf_type'] == 'IS':
  323. d,c,b = map(z,[aa_brw_end.debit,aa_brw_end.credit,aa_brw_end.balance])
  324. res.update({
  325. 'dbr%s'%pn: self.exchange(d),
  326. 'cdr%s'%pn: self.exchange(c),
  327. 'bal%s'%pn: self.exchange(b),
  328. })
  329. else:
  330. i,d,c = map(z,[aa_brw_init.balance,aa_brw_end.debit,aa_brw_end.credit])
  331. b = z(i+d-c)
  332. res.update({
  333. 'dbr%s'%pn: self.exchange(d),
  334. 'cdr%s'%pn: self.exchange(c),
  335. 'bal%s'%pn: self.exchange(b),
  336. })
  337. pn +=1
  338. form['periods'] = period_ids
  339. ctx_init = _ctx_init(self.context.copy())
  340. aa_brw_init = account_obj.browse(self.cr, self.uid, id, ctx_init)
  341. ctx_end = _ctx_end(self.context.copy())
  342. aa_brw_end = account_obj.browse(self.cr, self.uid, id, ctx_end)
  343. if form['inf_type'] == 'IS':
  344. d,c,b = map(z,[aa_brw_end.debit,aa_brw_end.credit,aa_brw_end.balance])
  345. res.update({
  346. 'dbr5': self.exchange(d),
  347. 'cdr5': self.exchange(c),
  348. 'bal5': self.exchange(b),
  349. })
  350. else:
  351. i,d,c = map(z,[aa_brw_init.balance,aa_brw_end.debit,aa_brw_end.credit])
  352. b = z(i+d-c)
  353. res.update({
  354. 'dbr5': self.exchange(d),
  355. 'cdr5': self.exchange(c),
  356. 'bal5': self.exchange(b),
  357. })
  358. elif form['columns'] == 'thirteen':
  359. pn = 1
  360. for p_id in period_ids:
  361. form['periods'] = [p_id]
  362. ctx_init = _ctx_init(self.context.copy())
  363. aa_brw_init = account_obj.browse(self.cr, self.uid, id, ctx_init)
  364. ctx_end = _ctx_end(self.context.copy())
  365. aa_brw_end = account_obj.browse(self.cr, self.uid, id, ctx_end)
  366. if form['inf_type'] == 'IS':
  367. d,c,b = map(z,[aa_brw_end.debit,aa_brw_end.credit,aa_brw_end.balance])
  368. res.update({
  369. 'dbr%s'%pn: self.exchange(d),
  370. 'cdr%s'%pn: self.exchange(c),
  371. 'bal%s'%pn: self.exchange(b),
  372. })
  373. else:
  374. i,d,c = map(z,[aa_brw_init.balance,aa_brw_end.debit,aa_brw_end.credit])
  375. b = z(i+d-c)
  376. res.update({
  377. 'dbr%s'%pn: self.exchange(d),
  378. 'cdr%s'%pn: self.exchange(c),
  379. 'bal%s'%pn: self.exchange(b),
  380. })
  381. pn +=1
  382. form['periods'] = period_ids
  383. ctx_init = _ctx_init(self.context.copy())
  384. aa_brw_init = account_obj.browse(self.cr, self.uid, id, ctx_init)
  385. ctx_end = _ctx_end(self.context.copy())
  386. aa_brw_end = account_obj.browse(self.cr, self.uid, id, ctx_end)
  387. if form['inf_type'] == 'IS':
  388. d,c,b = map(z,[aa_brw_end.debit,aa_brw_end.credit,aa_brw_end.balance])
  389. res.update({
  390. 'dbr13': self.exchange(d),
  391. 'cdr13': self.exchange(c),
  392. 'bal13': self.exchange(b),
  393. })
  394. else:
  395. i,d,c = map(z,[aa_brw_init.balance,aa_brw_end.debit,aa_brw_end.credit])
  396. b = z(i+d-c)
  397. res.update({
  398. 'dbr13': self.exchange(d),
  399. 'cdr13': self.exchange(c),
  400. 'bal13': self.exchange(b),
  401. })
  402. else:
  403. aa_brw_init = account_obj.browse(self.cr, self.uid, id, ctx_init)
  404. aa_brw_end = account_obj.browse(self.cr, self.uid, id, ctx_end)
  405. i,d,c = map(z,[aa_brw_init.balance,aa_brw_end.debit,aa_brw_end.credit])
  406. b = z(i+d-c)
  407. res.update({
  408. 'balanceinit': self.exchange(i),
  409. 'debit': self.exchange(d),
  410. 'credit': self.exchange(c),
  411. 'ytd': self.exchange(d-c),
  412. })
  413. if form['inf_type'] == 'IS' and form['columns'] == 'one':
  414. res.update({
  415. 'balance': self.exchange(d-c),
  416. })
  417. else:
  418. res.update({
  419. 'balance': self.exchange(b),
  420. })
  421. #
  422. # Check whether we must include this line in the report or not
  423. #
  424. to_include = False
  425. if form['columns'] in ('thirteen', 'qtr'):
  426. to_test = [False]
  427. if form['display_account'] == 'mov' and aa_id[3].parent_id:
  428. # Include accounts with movements
  429. for x in range(pn-1):
  430. to_test.append(res.get('dbr%s'%x,0.0) >= 0.005 and True or False)
  431. to_test.append(res.get('cdr%s'%x,0.0) >= 0.005 and True or False)
  432. if any(to_test):
  433. to_include = True
  434. elif form['display_account'] == 'bal' and aa_id[3].parent_id:
  435. # Include accounts with balance
  436. for x in range(pn-1):
  437. to_test.append(res.get('bal%s'%x,0.0) >= 0.005 and True or False)
  438. if any(to_test):
  439. to_include = True
  440. elif form['display_account'] == 'bal_mov' and aa_id[3].parent_id:
  441. # Include accounts with balance or movements
  442. for x in range(pn-1):
  443. to_test.append(res.get('bal%s'%x,0.0) >= 0.005 and True or False)
  444. to_test.append(res.get('dbr%s'%x,0.0) >= 0.005 and True or False)
  445. to_test.append(res.get('cdr%s'%x,0.0) >= 0.005 and True or False)
  446. if any(to_test):
  447. to_include = True
  448. else:
  449. # Include all accounts
  450. to_include = True
  451. else:
  452. if form['display_account'] == 'mov' and aa_id[3].parent_id:
  453. # Include accounts with movements
  454. if abs(d) >= 0.005 or abs(c) >= 0.005:
  455. to_include = True
  456. elif form['display_account'] == 'bal' and aa_id[3].parent_id:
  457. # Include accounts with balance
  458. if abs(b) >= 0.005:
  459. to_include = True
  460. elif form['display_account'] == 'bal_mov' and aa_id[3].parent_id:
  461. # Include accounts with balance or movements
  462. if abs(b) >= 0.005 or abs(d) >= 0.005 or abs(c) >= 0.005:
  463. to_include = True
  464. else:
  465. # Include all accounts
  466. to_include = True
  467. if to_include:
  468. result_acc.append(res)
  469. #
  470. # Check whether we must sumarize this line in the report or not
  471. #
  472. if form['tot_check'] and res['type'] == 'view' and res['level'] == 1 and (res['id'] not in tot):
  473. if form['columns'] == 'qtr':
  474. tot_check = True
  475. tot[res['id']] = True
  476. tot_bal1 += res.get('bal1',0.0)
  477. tot_bal2 += res.get('bal2',0.0)
  478. tot_bal3 += res.get('bal3',0.0)
  479. tot_bal4 += res.get('bal4',0.0)
  480. tot_bal5 += res.get('bal5',0.0)
  481. elif form['columns'] == 'thirteen':
  482. tot_check = True
  483. tot[res['id']] = True
  484. tot_bal1 += res.get('bal1',0.0)
  485. tot_bal2 += res.get('bal2',0.0)
  486. tot_bal3 += res.get('bal3',0.0)
  487. tot_bal4 += res.get('bal4',0.0)
  488. tot_bal5 += res.get('bal5',0.0)
  489. tot_bal6 += res.get('bal6',0.0)
  490. tot_bal7 += res.get('bal7',0.0)
  491. tot_bal8 += res.get('bal8',0.0)
  492. tot_bal9 += res.get('bal9',0.0)
  493. tot_bal10 += res.get('bal10',0.0)
  494. tot_bal11 += res.get('bal11',0.0)
  495. tot_bal12 += res.get('bal12',0.0)
  496. tot_bal13 += res.get('bal13',0.0)
  497. else:
  498. tot_check = True
  499. tot[res['id']] = True
  500. tot_bin += res['balanceinit']
  501. tot_deb += res['debit']
  502. tot_crd += res['credit']
  503. tot_ytd += res['ytd']
  504. tot_eje += res['balance']
  505. if tot_check:
  506. str_label = form['lab_str']
  507. res2 = {
  508. 'type' : 'view',
  509. 'name': 'TOTAL %s'%(str_label),
  510. 'label': False,
  511. 'total': True,
  512. }
  513. if form['columns'] == 'qtr':
  514. res2.update(dict(
  515. bal1 = tot_bal1,
  516. bal2 = tot_bal2,
  517. bal3 = tot_bal3,
  518. bal4 = tot_bal4,
  519. bal5 = tot_bal5,))
  520. if form['columns'] == 'thirteen':
  521. res2.update(dict(
  522. bal1 = tot_bal1,
  523. bal2 = tot_bal2,
  524. bal3 = tot_bal3,
  525. bal4 = tot_bal4,
  526. bal5 = tot_bal5,
  527. bal6 = tot_bal6,
  528. bal7 = tot_bal7,
  529. bal8 = tot_bal8,
  530. bal9 = tot_bal9,
  531. bal10 = tot_bal10,
  532. bal11 = tot_bal11,
  533. bal12 = tot_bal12,
  534. bal13 = tot_bal13,))
  535. else:
  536. res2.update({
  537. 'balanceinit': tot_bin,
  538. 'debit': tot_deb,
  539. 'credit': tot_crd,
  540. 'ytd': tot_ytd,
  541. 'balance': tot_eje,
  542. })
  543. result_acc.append(res2)
  544. print 100 * 'FIN ', result_acc
  545. return result_acc
  546. report_sxw.report_sxw('report.afr.1cols',
  547. 'wizard.report',
  548. 'account_financial_report/report/balance_full.rml',
  549. parser=account_balance,
  550. header=False)
  551. report_sxw.report_sxw('report.afr.2cols',
  552. 'wizard.report',
  553. 'account_financial_report/report/balance_full_2_cols.rml',
  554. parser=account_balance,
  555. header=False)
  556. report_sxw.report_sxw('report.afr.4cols',
  557. 'wizard.report',
  558. 'account_financial_report/report/balance_full_4_cols.rml',
  559. parser=account_balance,
  560. header=False)
  561. report_sxw.report_sxw('report.afr.5cols',
  562. 'wizard.report',
  563. 'account_financial_report/report/balance_full_5_cols.rml',
  564. parser=account_balance,
  565. header=False)
  566. report_sxw.report_sxw('report.afr.qtrcols',
  567. 'wizard.report',
  568. 'account_financial_report/report/balance_full_qtr_cols.rml',
  569. parser=account_balance,
  570. header=False)
  571. report_sxw.report_sxw('report.afr.13cols',
  572. 'wizard.report',
  573. 'account_financial_report/report/balance_full_13_cols.rml',
  574. parser=account_balance,
  575. header=False)