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.

684 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. print 'Primer print de credit_account_ids ', credit_account_ids
  229. 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')
  230. print 'Primer print de debit_account_ids ', debit_account_ids
  231. if form.get('fiscalyear'):
  232. if type(form.get('fiscalyear')) in (list,tuple):
  233. fiscalyear = form['fiscalyear'] and form['fiscalyear'][0]
  234. elif type(form.get('fiscalyear')) in (int,):
  235. fiscalyear = form['fiscalyear']
  236. fiscalyear = fiscalyear_obj.browse(self.cr, self.uid, fiscalyear)
  237. ################################################################
  238. # Get the accounts #
  239. ################################################################
  240. 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)
  241. credit_account_ids = _get_children_and_consol(self.cr, self.uid, credit_account_ids, 100,self.context,change_sign=True)
  242. print 'credit_account_ids ', credit_account_ids
  243. debit_account_ids = _get_children_and_consol(self.cr, self.uid, debit_account_ids, 100,self.context,change_sign=True)
  244. print 'debit_account_ids ', debit_account_ids
  245. credit_account_ids = list(set(credit_account_ids) - set(debit_account_ids))
  246. print 'Segundo print de credit_account_ids ', credit_account_ids
  247. #
  248. # Generate the report lines (checking each account)
  249. #
  250. tot_check = False
  251. if form['columns'] == 'qtr':
  252. period_ids = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',fiscalyear.id),('special','=',False)],order='date_start asc')
  253. a=0
  254. l=[]
  255. p=[]
  256. for x in period_ids:
  257. a+=1
  258. if a<3:
  259. l.append(x)
  260. else:
  261. l.append(x)
  262. p.append(l)
  263. l=[]
  264. a=0
  265. #~ period_ids = p
  266. elif form['columns'] == 'thirteen':
  267. period_ids = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',fiscalyear.id),('special','=',False)],order='date_start asc')
  268. if form['columns'] == 'qtr':
  269. tot_bal1 = 0.0
  270. tot_bal2 = 0.0
  271. tot_bal3 = 0.0
  272. tot_bal4 = 0.0
  273. tot_bal5 = 0.0
  274. elif form['columns'] == 'thirteen':
  275. tot_bal1 = 0.0
  276. tot_bal2 = 0.0
  277. tot_bal3 = 0.0
  278. tot_bal4 = 0.0
  279. tot_bal5 = 0.0
  280. tot_bal6 = 0.0
  281. tot_bal7 = 0.0
  282. tot_bal8 = 0.0
  283. tot_bal9 = 0.0
  284. tot_bal10 = 0.0
  285. tot_bal11 = 0.0
  286. tot_bal12 = 0.0
  287. tot_bal13 = 0.0
  288. else:
  289. ctx_init = _ctx_init(self.context.copy())
  290. ctx_end = _ctx_end(self.context.copy())
  291. tot_bin = 0.0
  292. tot_deb = 0.0
  293. tot_crd = 0.0
  294. tot_ytd = 0.0
  295. tot_eje = 0.0
  296. res = {}
  297. result_acc = []
  298. tot = {}
  299. for aa_id in account_ids:
  300. id = aa_id[0]
  301. #
  302. # Check if we need to include this level
  303. #
  304. if not form['display_account_level'] or aa_id[3].level <= form['display_account_level']:
  305. res = {
  306. 'id' : id,
  307. 'type' : aa_id[3].type,
  308. 'code' : aa_id[3].code,
  309. 'name' : (aa_id[2] and not aa_id[1]) and 'TOTAL %s'%(aa_id[3].name.upper()) or aa_id[3].name,
  310. 'parent_id' : aa_id[3].parent_id and aa_id[3].parent_id.id,
  311. 'level' : aa_id[3].level,
  312. 'label' : aa_id[1],
  313. 'total' : aa_id[2],
  314. 'change_sign' : credit_account_ids and (id in credit_account_ids and -1 or 1) or 1
  315. }
  316. if form['columns'] == 'qtr':
  317. pn = 1
  318. print 'PERIODOS DEL QTR ', p
  319. for p_id in p:
  320. form['periods'] = p_id
  321. ctx_init = _ctx_init(self.context.copy())
  322. aa_brw_init = account_obj.browse(self.cr, self.uid, id, ctx_init)
  323. ctx_end = _ctx_end(self.context.copy())
  324. aa_brw_end = account_obj.browse(self.cr, self.uid, id, ctx_end)
  325. if form['inf_type'] == 'IS':
  326. d,c,b = map(z,[aa_brw_end.debit,aa_brw_end.credit,aa_brw_end.balance])
  327. res.update({
  328. 'dbr%s'%pn: self.exchange(d),
  329. 'cdr%s'%pn: self.exchange(c),
  330. 'bal%s'%pn: self.exchange(b),
  331. })
  332. else:
  333. i,d,c = map(z,[aa_brw_init.balance,aa_brw_end.debit,aa_brw_end.credit])
  334. b = z(i+d-c)
  335. res.update({
  336. 'dbr%s'%pn: self.exchange(d),
  337. 'cdr%s'%pn: self.exchange(c),
  338. 'bal%s'%pn: self.exchange(b),
  339. })
  340. pn +=1
  341. form['periods'] = period_ids
  342. ctx_init = _ctx_init(self.context.copy())
  343. aa_brw_init = account_obj.browse(self.cr, self.uid, id, ctx_init)
  344. ctx_end = _ctx_end(self.context.copy())
  345. aa_brw_end = account_obj.browse(self.cr, self.uid, id, ctx_end)
  346. if form['inf_type'] == 'IS':
  347. d,c,b = map(z,[aa_brw_end.debit,aa_brw_end.credit,aa_brw_end.balance])
  348. res.update({
  349. 'dbr5': self.exchange(d),
  350. 'cdr5': self.exchange(c),
  351. 'bal5': self.exchange(b),
  352. })
  353. else:
  354. i,d,c = map(z,[aa_brw_init.balance,aa_brw_end.debit,aa_brw_end.credit])
  355. b = z(i+d-c)
  356. res.update({
  357. 'dbr5': self.exchange(d),
  358. 'cdr5': self.exchange(c),
  359. 'bal5': self.exchange(b),
  360. })
  361. elif form['columns'] == 'thirteen':
  362. pn = 1
  363. for p_id in period_ids:
  364. form['periods'] = [p_id]
  365. ctx_init = _ctx_init(self.context.copy())
  366. aa_brw_init = account_obj.browse(self.cr, self.uid, id, ctx_init)
  367. ctx_end = _ctx_end(self.context.copy())
  368. aa_brw_end = account_obj.browse(self.cr, self.uid, id, ctx_end)
  369. if form['inf_type'] == 'IS':
  370. d,c,b = map(z,[aa_brw_end.debit,aa_brw_end.credit,aa_brw_end.balance])
  371. res.update({
  372. 'dbr%s'%pn: self.exchange(d),
  373. 'cdr%s'%pn: self.exchange(c),
  374. 'bal%s'%pn: self.exchange(b),
  375. })
  376. else:
  377. i,d,c = map(z,[aa_brw_init.balance,aa_brw_end.debit,aa_brw_end.credit])
  378. b = z(i+d-c)
  379. res.update({
  380. 'dbr%s'%pn: self.exchange(d),
  381. 'cdr%s'%pn: self.exchange(c),
  382. 'bal%s'%pn: self.exchange(b),
  383. })
  384. pn +=1
  385. form['periods'] = period_ids
  386. ctx_init = _ctx_init(self.context.copy())
  387. aa_brw_init = account_obj.browse(self.cr, self.uid, id, ctx_init)
  388. ctx_end = _ctx_end(self.context.copy())
  389. aa_brw_end = account_obj.browse(self.cr, self.uid, id, ctx_end)
  390. if form['inf_type'] == 'IS':
  391. d,c,b = map(z,[aa_brw_end.debit,aa_brw_end.credit,aa_brw_end.balance])
  392. res.update({
  393. 'dbr13': self.exchange(d),
  394. 'cdr13': self.exchange(c),
  395. 'bal13': self.exchange(b),
  396. })
  397. else:
  398. i,d,c = map(z,[aa_brw_init.balance,aa_brw_end.debit,aa_brw_end.credit])
  399. b = z(i+d-c)
  400. res.update({
  401. 'dbr13': self.exchange(d),
  402. 'cdr13': self.exchange(c),
  403. 'bal13': self.exchange(b),
  404. })
  405. else:
  406. aa_brw_init = account_obj.browse(self.cr, self.uid, id, ctx_init)
  407. aa_brw_end = account_obj.browse(self.cr, self.uid, id, ctx_end)
  408. i,d,c = map(z,[aa_brw_init.balance,aa_brw_end.debit,aa_brw_end.credit])
  409. b = z(i+d-c)
  410. res.update({
  411. 'balanceinit': self.exchange(i),
  412. 'debit': self.exchange(d),
  413. 'credit': self.exchange(c),
  414. 'ytd': self.exchange(d-c),
  415. })
  416. if form['inf_type'] == 'IS' and form['columns'] == 'one':
  417. res.update({
  418. 'balance': self.exchange(d-c),
  419. })
  420. else:
  421. res.update({
  422. 'balance': self.exchange(b),
  423. })
  424. #
  425. # Check whether we must include this line in the report or not
  426. #
  427. to_include = False
  428. if form['columns'] in ('thirteen', 'qtr'):
  429. to_test = [False]
  430. if form['display_account'] == 'mov' and aa_id[3].parent_id:
  431. # Include accounts with movements
  432. for x in range(pn-1):
  433. to_test.append(res.get('dbr%s'%x,0.0) >= 0.005 and True or False)
  434. to_test.append(res.get('cdr%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' and aa_id[3].parent_id:
  438. # Include accounts with balance
  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. if any(to_test):
  442. to_include = True
  443. elif form['display_account'] == 'bal_mov' and aa_id[3].parent_id:
  444. # Include accounts with balance or movements
  445. for x in range(pn-1):
  446. to_test.append(res.get('bal%s'%x,0.0) >= 0.005 and True or False)
  447. to_test.append(res.get('dbr%s'%x,0.0) >= 0.005 and True or False)
  448. to_test.append(res.get('cdr%s'%x,0.0) >= 0.005 and True or False)
  449. if any(to_test):
  450. to_include = True
  451. else:
  452. # Include all accounts
  453. to_include = True
  454. else:
  455. if form['display_account'] == 'mov' and aa_id[3].parent_id:
  456. # Include accounts with movements
  457. if abs(d) >= 0.005 or abs(c) >= 0.005:
  458. to_include = True
  459. elif form['display_account'] == 'bal' and aa_id[3].parent_id:
  460. # Include accounts with balance
  461. if abs(b) >= 0.005:
  462. to_include = True
  463. elif form['display_account'] == 'bal_mov' and aa_id[3].parent_id:
  464. # Include accounts with balance or movements
  465. if abs(b) >= 0.005 or abs(d) >= 0.005 or abs(c) >= 0.005:
  466. to_include = True
  467. else:
  468. # Include all accounts
  469. to_include = True
  470. if to_include:
  471. result_acc.append(res)
  472. #
  473. # Check whether we must sumarize this line in the report or not
  474. #
  475. if form['tot_check'] and res['type'] == 'view' and res['level'] == 1 and (res['id'] not in tot):
  476. if form['columns'] == 'qtr':
  477. tot_check = True
  478. tot[res['id']] = True
  479. tot_bal1 += res.get('bal1',0.0)
  480. tot_bal2 += res.get('bal2',0.0)
  481. tot_bal3 += res.get('bal3',0.0)
  482. tot_bal4 += res.get('bal4',0.0)
  483. tot_bal5 += res.get('bal5',0.0)
  484. elif form['columns'] == 'thirteen':
  485. tot_check = True
  486. tot[res['id']] = True
  487. tot_bal1 += res.get('bal1',0.0)
  488. tot_bal2 += res.get('bal2',0.0)
  489. tot_bal3 += res.get('bal3',0.0)
  490. tot_bal4 += res.get('bal4',0.0)
  491. tot_bal5 += res.get('bal5',0.0)
  492. tot_bal6 += res.get('bal6',0.0)
  493. tot_bal7 += res.get('bal7',0.0)
  494. tot_bal8 += res.get('bal8',0.0)
  495. tot_bal9 += res.get('bal9',0.0)
  496. tot_bal10 += res.get('bal10',0.0)
  497. tot_bal11 += res.get('bal11',0.0)
  498. tot_bal12 += res.get('bal12',0.0)
  499. tot_bal13 += res.get('bal13',0.0)
  500. else:
  501. tot_check = True
  502. tot[res['id']] = True
  503. tot_bin += res['balanceinit']
  504. tot_deb += res['debit']
  505. tot_crd += res['credit']
  506. tot_ytd += res['ytd']
  507. tot_eje += res['balance']
  508. if tot_check:
  509. str_label = form['lab_str']
  510. res2 = {
  511. 'type' : 'view',
  512. 'name': 'TOTAL %s'%(str_label),
  513. 'label': False,
  514. 'total': True,
  515. }
  516. if form['columns'] == 'qtr':
  517. res2.update(dict(
  518. bal1 = tot_bal1,
  519. bal2 = tot_bal2,
  520. bal3 = tot_bal3,
  521. bal4 = tot_bal4,
  522. bal5 = tot_bal5,))
  523. elif form['columns'] == 'thirteen':
  524. res2.update(dict(
  525. bal1 = tot_bal1,
  526. bal2 = tot_bal2,
  527. bal3 = tot_bal3,
  528. bal4 = tot_bal4,
  529. bal5 = tot_bal5,
  530. bal6 = tot_bal6,
  531. bal7 = tot_bal7,
  532. bal8 = tot_bal8,
  533. bal9 = tot_bal9,
  534. bal10 = tot_bal10,
  535. bal11 = tot_bal11,
  536. bal12 = tot_bal12,
  537. bal13 = tot_bal13,))
  538. else:
  539. res2.update({
  540. 'balanceinit': tot_bin,
  541. 'debit': tot_deb,
  542. 'credit': tot_crd,
  543. 'ytd': tot_ytd,
  544. 'balance': tot_eje,
  545. })
  546. result_acc.append(res2)
  547. print 100 * 'FIN ', result_acc
  548. return result_acc
  549. report_sxw.report_sxw('report.afr.1cols',
  550. 'wizard.report',
  551. 'account_financial_report/report/balance_full.rml',
  552. parser=account_balance,
  553. header=False)
  554. report_sxw.report_sxw('report.afr.2cols',
  555. 'wizard.report',
  556. 'account_financial_report/report/balance_full_2_cols.rml',
  557. parser=account_balance,
  558. header=False)
  559. report_sxw.report_sxw('report.afr.4cols',
  560. 'wizard.report',
  561. 'account_financial_report/report/balance_full_4_cols.rml',
  562. parser=account_balance,
  563. header=False)
  564. report_sxw.report_sxw('report.afr.5cols',
  565. 'wizard.report',
  566. 'account_financial_report/report/balance_full_5_cols.rml',
  567. parser=account_balance,
  568. header=False)
  569. report_sxw.report_sxw('report.afr.qtrcols',
  570. 'wizard.report',
  571. 'account_financial_report/report/balance_full_qtr_cols.rml',
  572. parser=account_balance,
  573. header=False)
  574. report_sxw.report_sxw('report.afr.13cols',
  575. 'wizard.report',
  576. 'account_financial_report/report/balance_full_13_cols.rml',
  577. parser=account_balance,
  578. header=False)