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.

735 lines
34 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 _get_analytic_ledger(self, account, ctx={}):
  143. res = []
  144. if account['type'] in ('other','liquidity','receivable','payable'):
  145. #~ TODO: CUANDO EL PERIODO ESTE VACIO LLENARLO CON LOS PERIODOS DEL EJERCICIO
  146. #~ FISCAL, SIN LOS PERIODOS ESPECIALES
  147. periods = ', '.join([str(i) for i in ctx['periods']])
  148. #~ periods = str(tuple(ctx['periods']))
  149. where = """where aml.period_id in (%s) and aa.id = %s and aml.state <> 'draft'"""%(periods,account['id'])
  150. sql_detalle = """select aml.id as id, aj.name as diario, aa.name as descripcion,
  151. (select name from res_partner where aml.partner_id = id) as partner,
  152. aa.code as cuenta, aml.name as name,
  153. aml.ref as ref,
  154. case when aml.debit is null then 0.00 else aml.debit end as debit,
  155. case when aml.credit is null then 0.00 else aml.credit end as credit,
  156. (select code from account_analytic_account where aml.analytic_account_id = id) as analitica,
  157. aml.date as date, ap.name as periodo,
  158. am.name as asiento
  159. from account_move_line aml
  160. inner join account_journal aj on aj.id = aml.journal_id
  161. inner join account_account aa on aa.id = aml.account_id
  162. inner join account_period ap on ap.id = aml.period_id
  163. inner join account_move am on am.id = aml.move_id """ + where +\
  164. """ order by date, am.name"""
  165. self.cr.execute(sql_detalle)
  166. resultat = self.cr.dictfetchall()
  167. balance = account['balanceinit']
  168. #~ print balance
  169. for det in resultat:
  170. balance += det['debit'] - det['credit']
  171. res.append({
  172. 'id': det['id'],
  173. 'date': det['date'],
  174. 'journal':det['diario'],
  175. 'partner':det['partner'],
  176. 'name':det['name'],
  177. 'entry':det['asiento'],
  178. 'ref': det['ref'],
  179. 'debit': det['debit'],
  180. 'credit': det['credit'],
  181. 'analytic': det['analitica'],
  182. 'period': det['periodo'],
  183. 'balance': balance,
  184. })
  185. return res
  186. def lines(self, form, level=0):
  187. """
  188. Returns all the data needed for the report lines
  189. (account info plus debit/credit/balance in the selected period
  190. and the full year)
  191. """
  192. account_obj = self.pool.get('account.account')
  193. period_obj = self.pool.get('account.period')
  194. fiscalyear_obj = self.pool.get('account.fiscalyear')
  195. def _get_children_and_consol(cr, uid, ids, level, context={},change_sign=False):
  196. aa_obj = self.pool.get('account.account')
  197. ids2=[]
  198. for aa_brw in aa_obj.browse(cr, uid, ids, context):
  199. if aa_brw.child_id and aa_brw.level < level and aa_brw.type !='consolidation':
  200. if not change_sign:
  201. ids2.append([aa_brw.id,True, False,aa_brw])
  202. ids2 += _get_children_and_consol(cr, uid, [x.id for x in aa_brw.child_id], level, context,change_sign=change_sign)
  203. if change_sign:
  204. ids2.append(aa_brw.id)
  205. else:
  206. ids2.append([aa_brw.id,False,True,aa_brw])
  207. else:
  208. if change_sign:
  209. ids2.append(aa_brw.id)
  210. else:
  211. ids2.append([aa_brw.id,True,True,aa_brw])
  212. return ids2
  213. #############################################################################
  214. # CONTEXT FOR ENDIND BALANCE #
  215. #############################################################################
  216. def _ctx_end(ctx):
  217. ctx_end = ctx
  218. ctx_end['filter'] = form.get('filter','all')
  219. ctx_end['fiscalyear'] = fiscalyear.id
  220. #~ ctx_end['periods'] = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',fiscalyear.id),('special','=',False)])
  221. if ctx_end['filter'] not in ['bydate','none']:
  222. special = self.special_period(form['periods'])
  223. else:
  224. special = False
  225. if form['filter'] in ['byperiod', 'all']:
  226. if special:
  227. ctx_end['periods'] = period_obj.search(self.cr, self.uid, [('id','in',form['periods'] or ctx_end.get('periods',False))])
  228. else:
  229. ctx_end['periods'] = period_obj.search(self.cr, self.uid, [('id','in',form['periods'] or ctx_end.get('periods',False)),('special','=',False)])
  230. if form['filter'] in ['bydate','all','none']:
  231. ctx_end['date_from'] = form['date_from']
  232. ctx_end['date_to'] = form['date_to']
  233. return ctx_end.copy()
  234. def missing_period(ctx_init):
  235. ctx_init['fiscalyear'] = fiscalyear_obj.search(self.cr, self.uid, [('date_stop','<',fiscalyear.date_start)],order='date_stop') and \
  236. fiscalyear_obj.search(self.cr, self.uid, [('date_stop','<',fiscalyear.date_start)],order='date_stop')[-1] or []
  237. ctx_init['periods'] = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',ctx_init['fiscalyear']),('date_stop','<',fiscalyear.date_start)])
  238. return ctx_init
  239. #############################################################################
  240. # CONTEXT FOR INITIAL BALANCE #
  241. #############################################################################
  242. def _ctx_init(ctx):
  243. ctx_init = self.context.copy()
  244. ctx_init['filter'] = form.get('filter','all')
  245. ctx_init['fiscalyear'] = fiscalyear.id
  246. if form['filter'] in ['byperiod', 'all']:
  247. ctx_init['periods'] = form['periods']
  248. if not ctx_init['periods']:
  249. ctx_init = missing_period(ctx_init.copy())
  250. date_start = min([period.date_start for period in period_obj.browse(self.cr, self.uid, ctx_init['periods'])])
  251. ctx_init['periods'] = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',fiscalyear.id),('date_stop','<=',date_start)])
  252. elif form['filter'] in ['bydate']:
  253. ctx_init['date_from'] = fiscalyear.date_start
  254. ctx_init['date_to'] = form['date_from']
  255. ctx_init['periods'] = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',fiscalyear.id),('date_stop','<=',ctx_init['date_to'])])
  256. elif form['filter'] == 'none':
  257. ctx_init['periods'] = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',fiscalyear.id),('special','=',True)])
  258. date_start = min([period.date_start for period in period_obj.browse(self.cr, self.uid, ctx_init['periods'])])
  259. ctx_init['periods'] = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',fiscalyear.id),('date_start','<=',date_start),('special','=',True)])
  260. return ctx_init.copy()
  261. def z(n):
  262. return abs(n) < 0.005 and 0.0 or n
  263. 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'])
  264. if not form['currency_id']:
  265. self.to_currency_id = self.from_currency_id
  266. else:
  267. self.to_currency_id = form['currency_id'] and type(form['currency_id']) in (list, tuple) and form['currency_id'][0] or form['currency_id']
  268. if form.has_key('account_list') and form['account_list']:
  269. account_ids = form['account_list']
  270. del form['account_list']
  271. 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')
  272. 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')
  273. if form.get('fiscalyear'):
  274. if type(form.get('fiscalyear')) in (list,tuple):
  275. fiscalyear = form['fiscalyear'] and form['fiscalyear'][0]
  276. elif type(form.get('fiscalyear')) in (int,):
  277. fiscalyear = form['fiscalyear']
  278. fiscalyear = fiscalyear_obj.browse(self.cr, self.uid, fiscalyear)
  279. ################################################################
  280. # Get the accounts #
  281. ################################################################
  282. 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)
  283. credit_account_ids = _get_children_and_consol(self.cr, self.uid, credit_account_ids, 100,self.context,change_sign=True)
  284. debit_account_ids = _get_children_and_consol(self.cr, self.uid, debit_account_ids, 100,self.context,change_sign=True)
  285. credit_account_ids = list(set(credit_account_ids) - set(debit_account_ids))
  286. #
  287. # Generate the report lines (checking each account)
  288. #
  289. tot_check = False
  290. if not form['periods']:
  291. form['periods'] = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',fiscalyear.id),('special','=',False)],order='date_start asc')
  292. if form['columns'] == 'qtr':
  293. period_ids = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',fiscalyear.id),('special','=',False)],order='date_start asc')
  294. a=0
  295. l=[]
  296. p=[]
  297. for x in period_ids:
  298. a+=1
  299. if a<3:
  300. l.append(x)
  301. else:
  302. l.append(x)
  303. p.append(l)
  304. l=[]
  305. a=0
  306. #~ period_ids = p
  307. elif form['columns'] == 'thirteen':
  308. period_ids = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',fiscalyear.id),('special','=',False)],order='date_start asc')
  309. if form['columns'] == 'qtr':
  310. tot_bal1 = 0.0
  311. tot_bal2 = 0.0
  312. tot_bal3 = 0.0
  313. tot_bal4 = 0.0
  314. tot_bal5 = 0.0
  315. elif form['columns'] == 'thirteen':
  316. tot_bal1 = 0.0
  317. tot_bal2 = 0.0
  318. tot_bal3 = 0.0
  319. tot_bal4 = 0.0
  320. tot_bal5 = 0.0
  321. tot_bal6 = 0.0
  322. tot_bal7 = 0.0
  323. tot_bal8 = 0.0
  324. tot_bal9 = 0.0
  325. tot_bal10 = 0.0
  326. tot_bal11 = 0.0
  327. tot_bal12 = 0.0
  328. tot_bal13 = 0.0
  329. else:
  330. ctx_init = _ctx_init(self.context.copy())
  331. ctx_end = _ctx_end(self.context.copy())
  332. tot_bin = 0.0
  333. tot_deb = 0.0
  334. tot_crd = 0.0
  335. tot_ytd = 0.0
  336. tot_eje = 0.0
  337. res = {}
  338. result_acc = []
  339. tot = {}
  340. for aa_id in account_ids:
  341. id = aa_id[0]
  342. #
  343. # Check if we need to include this level
  344. #
  345. if not form['display_account_level'] or aa_id[3].level <= form['display_account_level']:
  346. res = {
  347. 'id' : id,
  348. 'type' : aa_id[3].type,
  349. 'code' : aa_id[3].code,
  350. 'name' : (aa_id[2] and not aa_id[1]) and 'TOTAL %s'%(aa_id[3].name.upper()) or aa_id[3].name,
  351. 'parent_id' : aa_id[3].parent_id and aa_id[3].parent_id.id,
  352. 'level' : aa_id[3].level,
  353. 'label' : aa_id[1],
  354. 'total' : aa_id[2],
  355. 'change_sign' : credit_account_ids and (id in credit_account_ids and -1 or 1) or 1
  356. }
  357. if form['columns'] == 'qtr':
  358. pn = 1
  359. for p_id in p:
  360. form['periods'] = p_id
  361. ctx_init = _ctx_init(self.context.copy())
  362. aa_brw_init = account_obj.browse(self.cr, self.uid, id, ctx_init)
  363. ctx_end = _ctx_end(self.context.copy())
  364. aa_brw_end = account_obj.browse(self.cr, self.uid, id, ctx_end)
  365. if form['inf_type'] == 'IS':
  366. d,c,b = map(z,[aa_brw_end.debit,aa_brw_end.credit,aa_brw_end.balance])
  367. res.update({
  368. 'dbr%s'%pn: self.exchange(d),
  369. 'cdr%s'%pn: self.exchange(c),
  370. 'bal%s'%pn: self.exchange(b),
  371. })
  372. else:
  373. i,d,c = map(z,[aa_brw_init.balance,aa_brw_end.debit,aa_brw_end.credit])
  374. b = z(i+d-c)
  375. res.update({
  376. 'dbr%s'%pn: self.exchange(d),
  377. 'cdr%s'%pn: self.exchange(c),
  378. 'bal%s'%pn: self.exchange(b),
  379. })
  380. pn +=1
  381. form['periods'] = period_ids
  382. ctx_init = _ctx_init(self.context.copy())
  383. aa_brw_init = account_obj.browse(self.cr, self.uid, id, ctx_init)
  384. ctx_end = _ctx_end(self.context.copy())
  385. aa_brw_end = account_obj.browse(self.cr, self.uid, id, ctx_end)
  386. if form['inf_type'] == 'IS':
  387. d,c,b = map(z,[aa_brw_end.debit,aa_brw_end.credit,aa_brw_end.balance])
  388. res.update({
  389. 'dbr5': self.exchange(d),
  390. 'cdr5': self.exchange(c),
  391. 'bal5': self.exchange(b),
  392. })
  393. else:
  394. i,d,c = map(z,[aa_brw_init.balance,aa_brw_end.debit,aa_brw_end.credit])
  395. b = z(i+d-c)
  396. res.update({
  397. 'dbr5': self.exchange(d),
  398. 'cdr5': self.exchange(c),
  399. 'bal5': self.exchange(b),
  400. })
  401. elif form['columns'] == 'thirteen':
  402. pn = 1
  403. for p_id in period_ids:
  404. form['periods'] = [p_id]
  405. ctx_init = _ctx_init(self.context.copy())
  406. aa_brw_init = account_obj.browse(self.cr, self.uid, id, ctx_init)
  407. ctx_end = _ctx_end(self.context.copy())
  408. aa_brw_end = account_obj.browse(self.cr, self.uid, id, ctx_end)
  409. if form['inf_type'] == 'IS':
  410. d,c,b = map(z,[aa_brw_end.debit,aa_brw_end.credit,aa_brw_end.balance])
  411. res.update({
  412. 'dbr%s'%pn: self.exchange(d),
  413. 'cdr%s'%pn: self.exchange(c),
  414. 'bal%s'%pn: self.exchange(b),
  415. })
  416. else:
  417. i,d,c = map(z,[aa_brw_init.balance,aa_brw_end.debit,aa_brw_end.credit])
  418. b = z(i+d-c)
  419. res.update({
  420. 'dbr%s'%pn: self.exchange(d),
  421. 'cdr%s'%pn: self.exchange(c),
  422. 'bal%s'%pn: self.exchange(b),
  423. })
  424. pn +=1
  425. form['periods'] = period_ids
  426. ctx_init = _ctx_init(self.context.copy())
  427. aa_brw_init = account_obj.browse(self.cr, self.uid, id, ctx_init)
  428. ctx_end = _ctx_end(self.context.copy())
  429. aa_brw_end = account_obj.browse(self.cr, self.uid, id, ctx_end)
  430. if form['inf_type'] == 'IS':
  431. d,c,b = map(z,[aa_brw_end.debit,aa_brw_end.credit,aa_brw_end.balance])
  432. res.update({
  433. 'dbr13': self.exchange(d),
  434. 'cdr13': self.exchange(c),
  435. 'bal13': self.exchange(b),
  436. })
  437. else:
  438. i,d,c = map(z,[aa_brw_init.balance,aa_brw_end.debit,aa_brw_end.credit])
  439. b = z(i+d-c)
  440. res.update({
  441. 'dbr13': self.exchange(d),
  442. 'cdr13': self.exchange(c),
  443. 'bal13': self.exchange(b),
  444. })
  445. else:
  446. aa_brw_init = account_obj.browse(self.cr, self.uid, id, ctx_init)
  447. aa_brw_end = account_obj.browse(self.cr, self.uid, id, ctx_end)
  448. i,d,c = map(z,[aa_brw_init.balance,aa_brw_end.debit,aa_brw_end.credit])
  449. b = z(i+d-c)
  450. res.update({
  451. 'balanceinit': self.exchange(i),
  452. 'debit': self.exchange(d),
  453. 'credit': self.exchange(c),
  454. 'ytd': self.exchange(d-c),
  455. })
  456. if form['inf_type'] == 'IS' and form['columns'] == 'one':
  457. res.update({
  458. 'balance': self.exchange(d-c),
  459. })
  460. else:
  461. res.update({
  462. 'balance': self.exchange(b),
  463. })
  464. #
  465. # Check whether we must include this line in the report or not
  466. #
  467. to_include = False
  468. if form['columns'] in ('thirteen', 'qtr'):
  469. to_test = [False]
  470. if form['display_account'] == 'mov' and aa_id[3].parent_id:
  471. # Include accounts with movements
  472. for x in range(pn-1):
  473. to_test.append(res.get('dbr%s'%x,0.0) >= 0.005 and True or False)
  474. to_test.append(res.get('cdr%s'%x,0.0) >= 0.005 and True or False)
  475. if any(to_test):
  476. to_include = True
  477. elif form['display_account'] == 'bal' and aa_id[3].parent_id:
  478. # Include accounts with balance
  479. for x in range(pn-1):
  480. to_test.append(res.get('bal%s'%x,0.0) >= 0.005 and True or False)
  481. if any(to_test):
  482. to_include = True
  483. elif form['display_account'] == 'bal_mov' and aa_id[3].parent_id:
  484. # Include accounts with balance or movements
  485. for x in range(pn-1):
  486. to_test.append(res.get('bal%s'%x,0.0) >= 0.005 and True or False)
  487. to_test.append(res.get('dbr%s'%x,0.0) >= 0.005 and True or False)
  488. to_test.append(res.get('cdr%s'%x,0.0) >= 0.005 and True or False)
  489. if any(to_test):
  490. to_include = True
  491. else:
  492. # Include all accounts
  493. to_include = True
  494. else:
  495. if form['display_account'] == 'mov' and aa_id[3].parent_id:
  496. # Include accounts with movements
  497. if abs(d) >= 0.005 or abs(c) >= 0.005:
  498. to_include = True
  499. elif form['display_account'] == 'bal' and aa_id[3].parent_id:
  500. # Include accounts with balance
  501. if abs(b) >= 0.005:
  502. to_include = True
  503. elif form['display_account'] == 'bal_mov' and aa_id[3].parent_id:
  504. # Include accounts with balance or movements
  505. if abs(b) >= 0.005 or abs(d) >= 0.005 or abs(c) >= 0.005:
  506. to_include = True
  507. else:
  508. # Include all accounts
  509. to_include = True
  510. #~ ANALYTIC LEDGER
  511. if to_include and form['analytic_ledger'] and form['columns']=='four' and form['inf_type'] == 'BS' and res['type'] in ('other','liquidity','receivable','payable'):
  512. print 'MAYOR ANALITICO'
  513. res['mayor'] = self._get_analytic_ledger(res,ctx=ctx_end)
  514. print "res['mayor'] ", res['mayor']
  515. else:
  516. res['mayor'] = []
  517. if to_include:
  518. result_acc.append(res)
  519. #
  520. # Check whether we must sumarize this line in the report or not
  521. #
  522. if form['tot_check'] and res['type'] == 'view' and res['level'] == 1 and (res['id'] not in tot):
  523. if form['columns'] == 'qtr':
  524. tot_check = True
  525. tot[res['id']] = True
  526. tot_bal1 += res.get('bal1',0.0)
  527. tot_bal2 += res.get('bal2',0.0)
  528. tot_bal3 += res.get('bal3',0.0)
  529. tot_bal4 += res.get('bal4',0.0)
  530. tot_bal5 += res.get('bal5',0.0)
  531. elif form['columns'] == 'thirteen':
  532. tot_check = True
  533. tot[res['id']] = True
  534. tot_bal1 += res.get('bal1',0.0)
  535. tot_bal2 += res.get('bal2',0.0)
  536. tot_bal3 += res.get('bal3',0.0)
  537. tot_bal4 += res.get('bal4',0.0)
  538. tot_bal5 += res.get('bal5',0.0)
  539. tot_bal6 += res.get('bal6',0.0)
  540. tot_bal7 += res.get('bal7',0.0)
  541. tot_bal8 += res.get('bal8',0.0)
  542. tot_bal9 += res.get('bal9',0.0)
  543. tot_bal10 += res.get('bal10',0.0)
  544. tot_bal11 += res.get('bal11',0.0)
  545. tot_bal12 += res.get('bal12',0.0)
  546. tot_bal13 += res.get('bal13',0.0)
  547. else:
  548. tot_check = True
  549. tot[res['id']] = True
  550. tot_bin += res['balanceinit']
  551. tot_deb += res['debit']
  552. tot_crd += res['credit']
  553. tot_ytd += res['ytd']
  554. tot_eje += res['balance']
  555. if tot_check:
  556. str_label = form['lab_str']
  557. res2 = {
  558. 'type' : 'view',
  559. 'name': 'TOTAL %s'%(str_label),
  560. 'label': False,
  561. 'total': True,
  562. }
  563. if form['columns'] == 'qtr':
  564. res2.update(dict(
  565. bal1 = tot_bal1,
  566. bal2 = tot_bal2,
  567. bal3 = tot_bal3,
  568. bal4 = tot_bal4,
  569. bal5 = tot_bal5,))
  570. elif form['columns'] == 'thirteen':
  571. res2.update(dict(
  572. bal1 = tot_bal1,
  573. bal2 = tot_bal2,
  574. bal3 = tot_bal3,
  575. bal4 = tot_bal4,
  576. bal5 = tot_bal5,
  577. bal6 = tot_bal6,
  578. bal7 = tot_bal7,
  579. bal8 = tot_bal8,
  580. bal9 = tot_bal9,
  581. bal10 = tot_bal10,
  582. bal11 = tot_bal11,
  583. bal12 = tot_bal12,
  584. bal13 = tot_bal13,))
  585. else:
  586. res2.update({
  587. 'balanceinit': tot_bin,
  588. 'debit': tot_deb,
  589. 'credit': tot_crd,
  590. 'ytd': tot_ytd,
  591. 'balance': tot_eje,
  592. })
  593. result_acc.append(res2)
  594. return result_acc
  595. report_sxw.report_sxw('report.afr.1cols',
  596. 'wizard.report',
  597. 'account_financial_report/report/balance_full.rml',
  598. parser=account_balance,
  599. header=False)
  600. report_sxw.report_sxw('report.afr.2cols',
  601. 'wizard.report',
  602. 'account_financial_report/report/balance_full_2_cols.rml',
  603. parser=account_balance,
  604. header=False)
  605. report_sxw.report_sxw('report.afr.4cols',
  606. 'wizard.report',
  607. 'account_financial_report/report/balance_full_4_cols.rml',
  608. parser=account_balance,
  609. header=False)
  610. report_sxw.report_sxw('report.afr.analytic.ledger',
  611. 'wizard.report',
  612. 'account_financial_report/report/balance_full_4_cols_analytic_ledger.rml',
  613. parser=account_balance,
  614. header=False)
  615. report_sxw.report_sxw('report.afr.5cols',
  616. 'wizard.report',
  617. 'account_financial_report/report/balance_full_5_cols.rml',
  618. parser=account_balance,
  619. header=False)
  620. report_sxw.report_sxw('report.afr.qtrcols',
  621. 'wizard.report',
  622. 'account_financial_report/report/balance_full_qtr_cols.rml',
  623. parser=account_balance,
  624. header=False)
  625. report_sxw.report_sxw('report.afr.13cols',
  626. 'wizard.report',
  627. 'account_financial_report/report/balance_full_13_cols.rml',
  628. parser=account_balance,
  629. header=False)