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.

791 lines
35 KiB

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