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.

736 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. from osv import osv
  37. class account_balance(report_sxw.rml_parse):
  38. def __init__(self, cr, uid, name, context):
  39. super(account_balance, self).__init__(cr, uid, name, context)
  40. self.sum_debit = 0.00
  41. self.sum_credit = 0.00
  42. self.sum_balance = 0.00
  43. self.sum_debit_fy = 0.00
  44. self.sum_credit_fy = 0.00
  45. self.sum_balance_fy = 0.00
  46. self.date_lst = []
  47. self.date_lst_string = ''
  48. self.localcontext.update({
  49. 'time': time,
  50. 'lines': self.lines,
  51. 'get_fiscalyear_text': self.get_fiscalyear_text,
  52. 'get_periods_and_date_text': self.get_periods_and_date_text,
  53. 'get_informe_text': self.get_informe_text,
  54. 'get_month':self.get_month,
  55. 'exchange_name':self.exchange_name,
  56. })
  57. self.context = context
  58. def get_fiscalyear_text(self, form):
  59. """
  60. Returns the fiscal year text used on the report.
  61. """
  62. fiscalyear_obj = self.pool.get('account.fiscalyear')
  63. fiscalyear = None
  64. if form.get('fiscalyear'):
  65. fiscalyear = fiscalyear_obj.browse(self.cr, self.uid, form['fiscalyear'])
  66. return fiscalyear.name or fiscalyear.code
  67. else:
  68. fiscalyear = fiscalyear_obj.browse(self.cr, self.uid, fiscalyear_obj.find(self.cr, self.uid))
  69. return "%s*" % (fiscalyear.name or fiscalyear.code)
  70. def get_informe_text(self, form):
  71. """
  72. Returns the header text used on the report.
  73. """
  74. afr_id = form['afr_id'] and type(form['afr_id']) in (list,tuple) and form['afr_id'][0] or form['afr_id']
  75. if afr_id:
  76. name = self.pool.get('afr').browse(self.cr, self.uid, afr_id).name
  77. elif form['analytic_ledger'] and form['columns']=='four' and form['inf_type'] == 'BS':
  78. name = _('Analytic Ledger')
  79. elif form['inf_type'] == 'BS':
  80. name = _('Balance Sheet')
  81. elif form['inf_type'] == 'IS':
  82. name = _('Income Statement')
  83. return name
  84. def get_month(self, form):
  85. '''
  86. return day, year and month
  87. '''
  88. if form['filter'] in ['bydate', 'all']:
  89. months=["Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre"]
  90. mes = months[time.strptime(form['date_to'],"%Y-%m-%d")[1]-1]
  91. ano = time.strptime(form['date_to'],"%Y-%m-%d")[0]
  92. dia = time.strptime(form['date_to'],"%Y-%m-%d")[2]
  93. return _('From ')+self.formatLang(form['date_from'], date=True)+ _(' to ')+self.formatLang(form['date_to'], date=True)
  94. elif form['filter'] in ['byperiod', 'all']:
  95. aux=[]
  96. period_obj = self.pool.get('account.period')
  97. for period in period_obj.browse(self.cr, self.uid, form['periods']):
  98. aux.append(period.date_start)
  99. aux.append(period.date_stop)
  100. sorted(aux)
  101. return _('From ')+self.formatLang(aux[0], date=True)+_(' to ')+self.formatLang(aux[-1], date=True)
  102. def get_periods_and_date_text(self, form):
  103. """
  104. Returns the text with the periods/dates used on the report.
  105. """
  106. period_obj = self.pool.get('account.period')
  107. periods_str = None
  108. fiscalyear_id = form['fiscalyear'] or fiscalyear_obj.find(self.cr, self.uid)
  109. period_ids = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',fiscalyear_id),('special','=',False)])
  110. if form['filter'] in ['byperiod', 'all']:
  111. period_ids = form['periods']
  112. periods_str = ', '.join([period.name or period.code for period in period_obj.browse(self.cr, self.uid, period_ids)])
  113. dates_str = None
  114. if form['filter'] in ['bydate', 'all']:
  115. dates_str = self.formatLang(form['date_from'], date=True) + ' - ' + self.formatLang(form['date_to'], date=True) + ' '
  116. return {'periods':periods_str, 'date':dates_str}
  117. def special_period(self, periods):
  118. period_obj = self.pool.get('account.period')
  119. period_brw = period_obj.browse(self.cr, self.uid, periods)
  120. period_counter = [True for i in period_brw if not i.special]
  121. if not period_counter:
  122. return True
  123. return False
  124. def exchange_name(self, form):
  125. 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'])
  126. if not form['currency_id']:
  127. self.to_currency_id = self.from_currency_id
  128. else:
  129. self.to_currency_id = form['currency_id'] and type(form['currency_id']) in (list, tuple) and form['currency_id'][0] or form['currency_id']
  130. return self.pool.get('res.currency').browse(self.cr, self.uid, self.to_currency_id).name
  131. def exchange(self, from_amount):
  132. if self.from_currency_id == self.to_currency_id:
  133. return from_amount
  134. curr_obj = self.pool.get('res.currency')
  135. return curr_obj.compute(self.cr, self.uid, self.from_currency_id, self.to_currency_id, from_amount)
  136. def get_company_currency(self, company_id):
  137. rc_obj = self.pool.get('res.company')
  138. return rc_obj.browse(self.cr, self.uid, company_id).currency_id.id
  139. def get_company_accounts(self, company_id, acc='credit'):
  140. rc_obj = self.pool.get('res.company')
  141. if acc=='credit':
  142. return [brw.id for brw in rc_obj.browse(self.cr, self.uid, company_id).credit_account_ids]
  143. else:
  144. return [brw.id for brw in rc_obj.browse(self.cr, self.uid, company_id).debit_account_ids]
  145. def _get_analytic_ledger(self, account, ctx={}):
  146. res = []
  147. if account['type'] in ('other','liquidity','receivable','payable'):
  148. #~ TODO: CUANDO EL PERIODO ESTE VACIO LLENARLO CON LOS PERIODOS DEL EJERCICIO
  149. #~ FISCAL, SIN LOS PERIODOS ESPECIALES
  150. periods = ', '.join([str(i) for i in ctx['periods']])
  151. #~ periods = str(tuple(ctx['periods']))
  152. where = """where aml.period_id in (%s) and aa.id = %s and aml.state <> 'draft'"""%(periods,account['id'])
  153. sql_detalle = """select aml.id as id, aj.name as diario, aa.name as descripcion,
  154. (select name from res_partner where aml.partner_id = id) as partner,
  155. aa.code as cuenta, aml.name as name,
  156. aml.ref as ref,
  157. case when aml.debit is null then 0.00 else aml.debit end as debit,
  158. case when aml.credit is null then 0.00 else aml.credit end as credit,
  159. (select code from account_analytic_account where aml.analytic_account_id = id) as analitica,
  160. aml.date as date, ap.name as periodo,
  161. am.name as asiento
  162. from account_move_line aml
  163. inner join account_journal aj on aj.id = aml.journal_id
  164. inner join account_account aa on aa.id = aml.account_id
  165. inner join account_period ap on ap.id = aml.period_id
  166. inner join account_move am on am.id = aml.move_id """ + where +\
  167. """ order by date, am.name"""
  168. self.cr.execute(sql_detalle)
  169. resultat = self.cr.dictfetchall()
  170. balance = account['balanceinit']
  171. for det in resultat:
  172. balance += det['debit'] - det['credit']
  173. res.append({
  174. 'id': det['id'],
  175. 'date': det['date'],
  176. 'journal':det['diario'],
  177. 'partner':det['partner'],
  178. 'name':det['name'],
  179. 'entry':det['asiento'],
  180. 'ref': det['ref'],
  181. 'debit': det['debit'],
  182. 'credit': det['credit'],
  183. 'analytic': det['analitica'],
  184. 'period': det['periodo'],
  185. 'balance': balance,
  186. })
  187. return res
  188. def lines(self, form, level=0):
  189. """
  190. Returns all the data needed for the report lines
  191. (account info plus debit/credit/balance in the selected period
  192. and the full year)
  193. """
  194. account_obj = self.pool.get('account.account')
  195. period_obj = self.pool.get('account.period')
  196. fiscalyear_obj = self.pool.get('account.fiscalyear')
  197. def _get_children_and_consol(cr, uid, ids, level, context={},change_sign=False):
  198. aa_obj = self.pool.get('account.account')
  199. ids2=[]
  200. for aa_brw in aa_obj.browse(cr, uid, ids, context):
  201. if aa_brw.child_id and aa_brw.level < level and aa_brw.type !='consolidation':
  202. if not change_sign:
  203. ids2.append([aa_brw.id,True, False,aa_brw])
  204. ids2 += _get_children_and_consol(cr, uid, [x.id for x in aa_brw.child_id], level, context,change_sign=change_sign)
  205. if change_sign:
  206. ids2.append(aa_brw.id)
  207. else:
  208. ids2.append([aa_brw.id,False,True,aa_brw])
  209. else:
  210. if change_sign:
  211. ids2.append(aa_brw.id)
  212. else:
  213. ids2.append([aa_brw.id,True,True,aa_brw])
  214. return ids2
  215. #############################################################################
  216. # CONTEXT FOR ENDIND BALANCE #
  217. #############################################################################
  218. def _ctx_end(ctx):
  219. ctx_end = ctx
  220. ctx_end['filter'] = form.get('filter','all')
  221. ctx_end['fiscalyear'] = fiscalyear.id
  222. #~ ctx_end['periods'] = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',fiscalyear.id),('special','=',False)])
  223. if ctx_end['filter'] not in ['bydate','none']:
  224. special = self.special_period(form['periods'])
  225. else:
  226. special = False
  227. if form['filter'] in ['byperiod', 'all']:
  228. if special:
  229. ctx_end['periods'] = period_obj.search(self.cr, self.uid, [('id','in',form['periods'] or ctx_end.get('periods',False))])
  230. else:
  231. ctx_end['periods'] = period_obj.search(self.cr, self.uid, [('id','in',form['periods'] or ctx_end.get('periods',False)),('special','=',False)])
  232. if form['filter'] in ['bydate','all','none']:
  233. ctx_end['date_from'] = form['date_from']
  234. ctx_end['date_to'] = form['date_to']
  235. return ctx_end.copy()
  236. def missing_period(ctx_init):
  237. ctx_init['fiscalyear'] = fiscalyear_obj.search(self.cr, self.uid, [('date_stop','<',fiscalyear.date_start)],order='date_stop') and \
  238. fiscalyear_obj.search(self.cr, self.uid, [('date_stop','<',fiscalyear.date_start)],order='date_stop')[-1] or []
  239. ctx_init['periods'] = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',ctx_init['fiscalyear']),('date_stop','<',fiscalyear.date_start)])
  240. return ctx_init
  241. #############################################################################
  242. # CONTEXT FOR INITIAL BALANCE #
  243. #############################################################################
  244. def _ctx_init(ctx):
  245. ctx_init = self.context.copy()
  246. ctx_init['filter'] = form.get('filter','all')
  247. ctx_init['fiscalyear'] = fiscalyear.id
  248. if form['filter'] in ['byperiod', 'all']:
  249. ctx_init['periods'] = form['periods']
  250. if not ctx_init['periods']:
  251. ctx_init = missing_period(ctx_init.copy())
  252. date_start = min([period.date_start for period in period_obj.browse(self.cr, self.uid, ctx_init['periods'])])
  253. ctx_init['periods'] = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',fiscalyear.id),('date_stop','<=',date_start)])
  254. elif form['filter'] in ['bydate']:
  255. ctx_init['date_from'] = fiscalyear.date_start
  256. ctx_init['date_to'] = form['date_from']
  257. ctx_init['periods'] = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',fiscalyear.id),('date_stop','<=',ctx_init['date_to'])])
  258. elif form['filter'] == 'none':
  259. ctx_init['periods'] = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',fiscalyear.id),('special','=',True)])
  260. date_start = min([period.date_start for period in period_obj.browse(self.cr, self.uid, ctx_init['periods'])])
  261. ctx_init['periods'] = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',fiscalyear.id),('date_start','<=',date_start),('special','=',True)])
  262. return ctx_init.copy()
  263. def z(n):
  264. return abs(n) < 0.005 and 0.0 or n
  265. 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'])
  266. if not form['currency_id']:
  267. self.to_currency_id = self.from_currency_id
  268. else:
  269. self.to_currency_id = form['currency_id'] and type(form['currency_id']) in (list, tuple) and form['currency_id'][0] or form['currency_id']
  270. if form.has_key('account_list') and form['account_list']:
  271. account_ids = form['account_list']
  272. del form['account_list']
  273. 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')
  274. 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')
  275. if form.get('fiscalyear'):
  276. if type(form.get('fiscalyear')) in (list,tuple):
  277. fiscalyear = form['fiscalyear'] and form['fiscalyear'][0]
  278. elif type(form.get('fiscalyear')) in (int,):
  279. fiscalyear = form['fiscalyear']
  280. fiscalyear = fiscalyear_obj.browse(self.cr, self.uid, fiscalyear)
  281. ################################################################
  282. # Get the accounts #
  283. ################################################################
  284. 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)
  285. credit_account_ids = _get_children_and_consol(self.cr, self.uid, credit_account_ids, 100,self.context,change_sign=True)
  286. debit_account_ids = _get_children_and_consol(self.cr, self.uid, debit_account_ids, 100,self.context,change_sign=True)
  287. credit_account_ids = list(set(credit_account_ids) - set(debit_account_ids))
  288. #
  289. # Generate the report lines (checking each account)
  290. #
  291. tot_check = False
  292. if not form['periods']:
  293. form['periods'] = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',fiscalyear.id),('special','=',False)],order='date_start asc')
  294. if not form['periods']:
  295. raise osv.except_osv(_('UserError'),_('The Selected Fiscal Year Does not have Regular Periods'))
  296. if form['columns'] == 'qtr':
  297. period_ids = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',fiscalyear.id),('special','=',False)],order='date_start asc')
  298. a=0
  299. l=[]
  300. p=[]
  301. for x in period_ids:
  302. a+=1
  303. if a<3:
  304. l.append(x)
  305. else:
  306. l.append(x)
  307. p.append(l)
  308. l=[]
  309. a=0
  310. #~ period_ids = p
  311. elif form['columns'] == 'thirteen':
  312. period_ids = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',fiscalyear.id),('special','=',False)],order='date_start asc')
  313. if form['columns'] == 'qtr':
  314. tot_bal1 = 0.0
  315. tot_bal2 = 0.0
  316. tot_bal3 = 0.0
  317. tot_bal4 = 0.0
  318. tot_bal5 = 0.0
  319. elif form['columns'] == 'thirteen':
  320. tot_bal1 = 0.0
  321. tot_bal2 = 0.0
  322. tot_bal3 = 0.0
  323. tot_bal4 = 0.0
  324. tot_bal5 = 0.0
  325. tot_bal6 = 0.0
  326. tot_bal7 = 0.0
  327. tot_bal8 = 0.0
  328. tot_bal9 = 0.0
  329. tot_bal10 = 0.0
  330. tot_bal11 = 0.0
  331. tot_bal12 = 0.0
  332. tot_bal13 = 0.0
  333. else:
  334. ctx_init = _ctx_init(self.context.copy())
  335. ctx_end = _ctx_end(self.context.copy())
  336. tot_bin = 0.0
  337. tot_deb = 0.0
  338. tot_crd = 0.0
  339. tot_ytd = 0.0
  340. tot_eje = 0.0
  341. res = {}
  342. result_acc = []
  343. tot = {}
  344. for aa_id in account_ids:
  345. id = aa_id[0]
  346. #
  347. # Check if we need to include this level
  348. #
  349. if not form['display_account_level'] or aa_id[3].level <= form['display_account_level']:
  350. res = {
  351. 'id' : id,
  352. 'type' : aa_id[3].type,
  353. 'code' : aa_id[3].code,
  354. 'name' : (aa_id[2] and not aa_id[1]) and 'TOTAL %s'%(aa_id[3].name.upper()) or aa_id[3].name,
  355. 'parent_id' : aa_id[3].parent_id and aa_id[3].parent_id.id,
  356. 'level' : aa_id[3].level,
  357. 'label' : aa_id[1],
  358. 'total' : aa_id[2],
  359. 'change_sign' : credit_account_ids and (id in credit_account_ids and -1 or 1) or 1
  360. }
  361. if form['columns'] == 'qtr':
  362. pn = 1
  363. for p_id in p:
  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. 'dbr5': self.exchange(d),
  394. 'cdr5': self.exchange(c),
  395. 'bal5': 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. 'dbr5': self.exchange(d),
  402. 'cdr5': self.exchange(c),
  403. 'bal5': self.exchange(b),
  404. })
  405. elif form['columns'] == 'thirteen':
  406. pn = 1
  407. for p_id in period_ids:
  408. form['periods'] = [p_id]
  409. ctx_init = _ctx_init(self.context.copy())
  410. aa_brw_init = account_obj.browse(self.cr, self.uid, id, ctx_init)
  411. ctx_end = _ctx_end(self.context.copy())
  412. aa_brw_end = account_obj.browse(self.cr, self.uid, id, ctx_end)
  413. if form['inf_type'] == 'IS':
  414. d,c,b = map(z,[aa_brw_end.debit,aa_brw_end.credit,aa_brw_end.balance])
  415. res.update({
  416. 'dbr%s'%pn: self.exchange(d),
  417. 'cdr%s'%pn: self.exchange(c),
  418. 'bal%s'%pn: self.exchange(b),
  419. })
  420. else:
  421. i,d,c = map(z,[aa_brw_init.balance,aa_brw_end.debit,aa_brw_end.credit])
  422. b = z(i+d-c)
  423. res.update({
  424. 'dbr%s'%pn: self.exchange(d),
  425. 'cdr%s'%pn: self.exchange(c),
  426. 'bal%s'%pn: self.exchange(b),
  427. })
  428. pn +=1
  429. form['periods'] = period_ids
  430. ctx_init = _ctx_init(self.context.copy())
  431. aa_brw_init = account_obj.browse(self.cr, self.uid, id, ctx_init)
  432. ctx_end = _ctx_end(self.context.copy())
  433. aa_brw_end = account_obj.browse(self.cr, self.uid, id, ctx_end)
  434. if form['inf_type'] == 'IS':
  435. d,c,b = map(z,[aa_brw_end.debit,aa_brw_end.credit,aa_brw_end.balance])
  436. res.update({
  437. 'dbr13': self.exchange(d),
  438. 'cdr13': self.exchange(c),
  439. 'bal13': self.exchange(b),
  440. })
  441. else:
  442. i,d,c = map(z,[aa_brw_init.balance,aa_brw_end.debit,aa_brw_end.credit])
  443. b = z(i+d-c)
  444. res.update({
  445. 'dbr13': self.exchange(d),
  446. 'cdr13': self.exchange(c),
  447. 'bal13': self.exchange(b),
  448. })
  449. else:
  450. aa_brw_init = account_obj.browse(self.cr, self.uid, id, ctx_init)
  451. aa_brw_end = account_obj.browse(self.cr, self.uid, id, ctx_end)
  452. i,d,c = map(z,[aa_brw_init.balance,aa_brw_end.debit,aa_brw_end.credit])
  453. b = z(i+d-c)
  454. res.update({
  455. 'balanceinit': self.exchange(i),
  456. 'debit': self.exchange(d),
  457. 'credit': self.exchange(c),
  458. 'ytd': self.exchange(d-c),
  459. })
  460. if form['inf_type'] == 'IS' and form['columns'] == 'one':
  461. res.update({
  462. 'balance': self.exchange(d-c),
  463. })
  464. else:
  465. res.update({
  466. 'balance': self.exchange(b),
  467. })
  468. #
  469. # Check whether we must include this line in the report or not
  470. #
  471. to_include = False
  472. if form['columns'] in ('thirteen', 'qtr'):
  473. to_test = [False]
  474. if form['display_account'] == 'mov' and aa_id[3].parent_id:
  475. # Include accounts with movements
  476. for x in range(pn-1):
  477. to_test.append(res.get('dbr%s'%x,0.0) >= 0.005 and True or False)
  478. to_test.append(res.get('cdr%s'%x,0.0) >= 0.005 and True or False)
  479. if any(to_test):
  480. to_include = True
  481. elif form['display_account'] == 'bal' and aa_id[3].parent_id:
  482. # Include accounts with balance
  483. for x in range(pn-1):
  484. to_test.append(res.get('bal%s'%x,0.0) >= 0.005 and True or False)
  485. if any(to_test):
  486. to_include = True
  487. elif form['display_account'] == 'bal_mov' and aa_id[3].parent_id:
  488. # Include accounts with balance or movements
  489. for x in range(pn-1):
  490. to_test.append(res.get('bal%s'%x,0.0) >= 0.005 and True or False)
  491. to_test.append(res.get('dbr%s'%x,0.0) >= 0.005 and True or False)
  492. to_test.append(res.get('cdr%s'%x,0.0) >= 0.005 and True or False)
  493. if any(to_test):
  494. to_include = True
  495. else:
  496. # Include all accounts
  497. to_include = True
  498. else:
  499. if form['display_account'] == 'mov' and aa_id[3].parent_id:
  500. # Include accounts with movements
  501. if abs(d) >= 0.005 or abs(c) >= 0.005:
  502. to_include = True
  503. elif form['display_account'] == 'bal' and aa_id[3].parent_id:
  504. # Include accounts with balance
  505. if abs(b) >= 0.005:
  506. to_include = True
  507. elif form['display_account'] == 'bal_mov' and aa_id[3].parent_id:
  508. # Include accounts with balance or movements
  509. if abs(b) >= 0.005 or abs(d) >= 0.005 or abs(c) >= 0.005:
  510. to_include = True
  511. else:
  512. # Include all accounts
  513. to_include = True
  514. #~ ANALYTIC LEDGER
  515. if to_include and form['analytic_ledger'] and form['columns']=='four' and form['inf_type'] == 'BS' and res['type'] in ('other','liquidity','receivable','payable'):
  516. res['mayor'] = self._get_analytic_ledger(res,ctx=ctx_end)
  517. else:
  518. res['mayor'] = []
  519. if to_include:
  520. result_acc.append(res)
  521. #
  522. # Check whether we must sumarize this line in the report or not
  523. #
  524. if form['tot_check'] and res['type'] == 'view' and res['level'] == 1 and (res['id'] not in tot):
  525. if form['columns'] == 'qtr':
  526. tot_check = True
  527. #~ tot[res['id']] = True
  528. tot_bal1 += res.get('bal1',0.0)
  529. tot_bal2 += res.get('bal2',0.0)
  530. tot_bal3 += res.get('bal3',0.0)
  531. tot_bal4 += res.get('bal4',0.0)
  532. tot_bal5 += res.get('bal5',0.0)
  533. elif form['columns'] == 'thirteen':
  534. tot_check = True
  535. #~ tot[res['id']] = True
  536. tot_bal1 += res.get('bal1',0.0)
  537. tot_bal2 += res.get('bal2',0.0)
  538. tot_bal3 += res.get('bal3',0.0)
  539. tot_bal4 += res.get('bal4',0.0)
  540. tot_bal5 += res.get('bal5',0.0)
  541. tot_bal6 += res.get('bal6',0.0)
  542. tot_bal7 += res.get('bal7',0.0)
  543. tot_bal8 += res.get('bal8',0.0)
  544. tot_bal9 += res.get('bal9',0.0)
  545. tot_bal10 += res.get('bal10',0.0)
  546. tot_bal11 += res.get('bal11',0.0)
  547. tot_bal12 += res.get('bal12',0.0)
  548. tot_bal13 += res.get('bal13',0.0)
  549. else:
  550. tot_check = True
  551. #~ tot[res['id']] = True
  552. tot_bin += res['balanceinit']
  553. tot_deb += res['debit']
  554. tot_crd += res['credit']
  555. tot_ytd += res['ytd']
  556. tot_eje += res['balance']
  557. if tot_check:
  558. str_label = form['lab_str']
  559. res2 = {
  560. 'type' : 'view',
  561. 'name': 'TOTAL %s'%(str_label),
  562. 'label': False,
  563. 'total': True,
  564. }
  565. if form['columns'] == 'qtr':
  566. res2.update(dict(
  567. bal1 = tot_bal1,
  568. bal2 = tot_bal2,
  569. bal3 = tot_bal3,
  570. bal4 = tot_bal4,
  571. bal5 = tot_bal5,))
  572. elif form['columns'] == 'thirteen':
  573. res2.update(dict(
  574. bal1 = tot_bal1,
  575. bal2 = tot_bal2,
  576. bal3 = tot_bal3,
  577. bal4 = tot_bal4,
  578. bal5 = tot_bal5,
  579. bal6 = tot_bal6,
  580. bal7 = tot_bal7,
  581. bal8 = tot_bal8,
  582. bal9 = tot_bal9,
  583. bal10 = tot_bal10,
  584. bal11 = tot_bal11,
  585. bal12 = tot_bal12,
  586. bal13 = tot_bal13,))
  587. else:
  588. res2.update({
  589. 'balanceinit': tot_bin,
  590. 'debit': tot_deb,
  591. 'credit': tot_crd,
  592. 'ytd': tot_ytd,
  593. 'balance': tot_eje,
  594. })
  595. result_acc.append(res2)
  596. return result_acc
  597. report_sxw.report_sxw('report.afr.1cols',
  598. 'wizard.report',
  599. 'account_financial_report/report/balance_full.rml',
  600. parser=account_balance,
  601. header=False)
  602. report_sxw.report_sxw('report.afr.2cols',
  603. 'wizard.report',
  604. 'account_financial_report/report/balance_full_2_cols.rml',
  605. parser=account_balance,
  606. header=False)
  607. report_sxw.report_sxw('report.afr.4cols',
  608. 'wizard.report',
  609. 'account_financial_report/report/balance_full_4_cols.rml',
  610. parser=account_balance,
  611. header=False)
  612. report_sxw.report_sxw('report.afr.analytic.ledger',
  613. 'wizard.report',
  614. 'account_financial_report/report/balance_full_4_cols_analytic_ledger.rml',
  615. parser=account_balance,
  616. header=False)
  617. report_sxw.report_sxw('report.afr.5cols',
  618. 'wizard.report',
  619. 'account_financial_report/report/balance_full_5_cols.rml',
  620. parser=account_balance,
  621. header=False)
  622. report_sxw.report_sxw('report.afr.qtrcols',
  623. 'wizard.report',
  624. 'account_financial_report/report/balance_full_qtr_cols.rml',
  625. parser=account_balance,
  626. header=False)
  627. report_sxw.report_sxw('report.afr.13cols',
  628. 'wizard.report',
  629. 'account_financial_report/report/balance_full_13_cols.rml',
  630. parser=account_balance,
  631. header=False)