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.

269 lines
11 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. class account_balance(report_sxw.rml_parse):
  36. def __init__(self, cr, uid, name, context):
  37. print 'INICIO: ',datetime.datetime.now()
  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_inf_text': self.get_informe_text,
  53. })
  54. self.context = context
  55. def get_fiscalyear_text(self, form):
  56. """
  57. Returns the fiscal year text used on the report.
  58. """
  59. fiscalyear_obj = self.pool.get('account.fiscalyear')
  60. fiscalyear = None
  61. if form.get('fiscalyear'):
  62. fiscalyear = fiscalyear_obj.browse(self.cr, self.uid, form['fiscalyear'])
  63. return fiscalyear.name or fiscalyear.code
  64. else:
  65. fiscalyear = fiscalyear_obj.browse(self.cr, self.uid, fiscalyear_obj.find(self.cr, self.uid))
  66. return "%s*" % (fiscalyear.name or fiscalyear.code)
  67. def get_informe_text(self, form):
  68. """
  69. Returns the header text used on the report.
  70. """
  71. inf_type = {
  72. 'bgen' : ' Balance General',
  73. 'bcom' : ' Balance de Comprobacion',
  74. 'edogp': 'Estado de Ganancias y Perdidas'
  75. }
  76. return inf_type[form['inf_type']]
  77. def get_periods_and_date_text(self, form):
  78. """
  79. Returns the text with the periods/dates used on the report.
  80. """
  81. period_obj = self.pool.get('account.period')
  82. periods_str = None
  83. fiscalyear_id = form['fiscalyear'] or fiscalyear_obj.find(self.cr, self.uid)
  84. period_ids = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',fiscalyear_id),('special','=',False)])
  85. if form['filter'] in ['byperiod', 'all']:
  86. period_ids = form['periods']
  87. periods_str = ', '.join([period.name or period.code for period in period_obj.browse(self.cr, self.uid, period_ids)])
  88. dates_str = None
  89. if form['filter'] in ['bydate', 'all']:
  90. dates_str = self.formatLang(form['date_from'], date=True) + ' - ' + self.formatLang(form['date_to'], date=True) + ' '
  91. return {'periods':periods_str, 'date':dates_str}
  92. def lines(self, form, ids={}, done=None, level=0):
  93. """
  94. Returns all the data needed for the report lines
  95. (account info plus debit/credit/balance in the selected period
  96. and the full year)
  97. """
  98. tot_deb = 0.0
  99. tot_crd = 0.0
  100. if not ids:
  101. ids = self.ids
  102. if not ids:
  103. return []
  104. if not done:
  105. done = {}
  106. print "Lista Form %s"%form
  107. print "Tipo de Obj %s"%type(form)
  108. print "form:%s"%form
  109. if form.has_key('account_list') and form['account_list']:
  110. #account_ids = form['account_list'][0][2]
  111. account_ids = form['account_list']
  112. del form['account_list']
  113. res = {}
  114. result_acc = []
  115. accounts_levels = {}
  116. account_obj = self.pool.get('account.account')
  117. period_obj = self.pool.get('account.period')
  118. fiscalyear_obj = self.pool.get('account.fiscalyear')
  119. # Get the fiscal year
  120. fiscalyear = None
  121. if form.get('fiscalyear'):
  122. fiscalyear = fiscalyear_obj.browse(self.cr, self.uid, form['fiscalyear'])
  123. else:
  124. fiscalyear = fiscalyear_obj.browse(self.cr, self.uid, fiscalyear_obj.find(self.cr, self.uid))
  125. #
  126. # Get the accounts
  127. #
  128. def _get_children_and_consol(cr, uid, ids, level, context={}):
  129. aa_obj = self.pool.get('account.account')
  130. ids2=[]
  131. temp=[]
  132. read_data= aa_obj.read(cr, uid, ids,['id','child_id','level','type'], context)
  133. for data in read_data:
  134. if data['child_id'] and data['level'] < level and data['type']!='consolidation':
  135. #ids2.append([data['id'],'Label', 'Total'])
  136. ids2.append([data['id'],True, False])
  137. temp=[]
  138. for x in data['child_id']:
  139. temp.append(x)
  140. ids2 += _get_children_and_consol(cr, uid, temp, level, context)
  141. ids2.append([data['id'],False,True])
  142. else:
  143. ids2.append([data['id'],True,True])
  144. return ids2
  145. child_ids = _get_children_and_consol(self.cr, self.uid, account_ids, form['display_account_level'] and form['display_account_level'] or 100,self.context)
  146. if child_ids:
  147. account_ids = child_ids
  148. #
  149. # Calculate the period Debit/Credit
  150. # (from the selected period or all the non special periods in the fy)
  151. #
  152. ctx = self.context.copy()
  153. print "CTX = %s\nY\nFORM = %s"%(ctx,form)
  154. ctx['filter'] = form.get('filter','all')
  155. #~ ctx['filter'] = form['context'].get('filter','all')
  156. ctx['fiscalyear'] = fiscalyear.id
  157. ctx['periods'] = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',fiscalyear.id),('special','=',False)])
  158. if form['filter'] in ['byperiod', 'all']:
  159. print "PERIODS ",form['periods']
  160. #~ ctx['periods'] = form['periods'][0][2]
  161. ctx['periods'] = form['periods']
  162. if form['filter'] in ['bydate', 'all']:
  163. ctx['date_from'] = form['date_from']
  164. ctx['date_to'] = form['date_to']
  165. accounts=[]
  166. for aa_id in account_ids:
  167. new_acc = account_obj.read(self.cr, self.uid, aa_id[0], ['type','code','name','debit','credit','parent_id','level'], ctx)
  168. new_acc.update({'label':aa_id[1],'total':aa_id[2]})
  169. accounts.append(new_acc)
  170. def missing_period():
  171. ctx['fiscalyear'] = fiscalyear_obj.search(self.cr, self.uid, [('date_stop','<',fiscalyear.date_start)],order='date_stop') and \
  172. fiscalyear_obj.search(self.cr, self.uid, [('date_stop','<',fiscalyear.date_start)],order='date_stop')[-1] or []
  173. ctx['periods'] = period_obj.search(self.cr, self.uid, [('fiscalyear_id','=',ctx['fiscalyear']),('date_stop','<',fiscalyear.date_start)])
  174. #
  175. # Generate the report lines (checking each account)
  176. #
  177. tot = {}
  178. for account in accounts:
  179. account_id = account['id']
  180. if account_id in done:
  181. pass
  182. # continue
  183. done[account_id] = 1
  184. accounts_levels[account_id] = account['level']
  185. #
  186. # Check if we need to include this level
  187. #
  188. if not form['display_account_level'] or account['level'] <= form['display_account_level']:
  189. #
  190. # Copy the account values
  191. #
  192. res = {
  193. 'id' : account_id,
  194. 'type' : account['type'],
  195. 'code': account['code'],
  196. 'name': (account['total'] and not account['label']) and 'TOTAL %s'%(account['name'].upper()) or account['name'],
  197. 'level': account['level'],
  198. 'debit': account['debit'],
  199. 'credit': account['credit'],
  200. 'parent_id': account['parent_id'],
  201. 'bal_type': '',
  202. 'label': account['label'],
  203. 'total': account['total'],
  204. }
  205. #
  206. # Check whether we must include this line in the report or not
  207. #
  208. if form['display_account'] == 'con_movimiento' and account['parent_id']:
  209. # Include accounts with movements
  210. if abs(res['credit']-res['debit']) >= 0.5 * 10**-int(2) \
  211. or abs(res['credit']) >= 0.5 * 10**-int(2) \
  212. or abs(res['debit']) >= 0.5 * 10**-int(2):
  213. result_acc.append(res)
  214. elif form['display_account'] == 'con_balance' and account['parent_id']:
  215. # Include accounts with balance
  216. if abs(res['credit']-res['debit']) >= 0.5 * 10**-int(2):
  217. result_acc.append(res)
  218. else:
  219. # Include all account
  220. result_acc.append(res)
  221. if form['tot_check'] and res['type'] == 'view' and res['level'] == 1 and (res['id'] not in tot):
  222. tot[res['id']] = True
  223. tot_deb += res['debit']
  224. tot_crd += res['credit']
  225. if form['tot_check']:
  226. str_label = form['lab_str']
  227. res2 = {
  228. 'type' : 'view',
  229. 'name': 'TOTAL %s'%(str_label),
  230. 'debit': tot_deb,
  231. 'credit': tot_crd,
  232. 'label': False,
  233. 'total': True,
  234. }
  235. result_acc.append(res2)
  236. print 'FIN: ',datetime.datetime.now()
  237. return result_acc
  238. report_sxw.report_sxw('report.wizard.reporte.comprobacion.dos.col',
  239. 'account.account',
  240. 'l10n_ve_account_financial_report/report/balance_full_2_cols.rml',
  241. parser=account_balance,
  242. header=False)