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.

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