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.

148 lines
7.3 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. from osv import osv,fields
  29. import pooler
  30. import time
  31. class wizard_account_balance_gene(osv.osv_memory):
  32. _name = "wizard.report.account.balance.gene"
  33. _columns = {
  34. 'company_id': fields.many2one('res.company','Company',required=True),
  35. 'account_list': fields.many2many ('account.account','rel_wizard_account','account_list','account_id','Root accounts',required=True),
  36. 'filter': fields.selection([('bydate','By Date'),('byperiod','By Period'),('all','By Date and Period'),('none','No Filter')],'Date/Period Filter'),
  37. 'fiscalyear': fields.many2one('account.fiscalyear','Fiscal year',help='Keep empty to use all open fiscal years to compute the balance',required=True),
  38. 'periods': fields.many2many('account.period','rel_wizard_period','wizard_id','period_id','Periods',help='All periods in the fiscal year if empty'),
  39. 'display_account': fields.selection([('all','All'),('con_balance', 'With balance'),('con_movimiento','With movements')],'Display accounts'),
  40. 'display_account_level': fields.integer('Up to level',help='Display accounts up to this level (0 to show all)'),
  41. 'date_from': fields.date('Start date'),
  42. 'date_to': fields.date('End date'),
  43. 'tot_check': fields.boolean('Show Total'),
  44. 'lab_str': fields.char('Description', size= 128),
  45. 'inf_type': fields.selection([('bgen','Balance General'),('bcom','Balance Comprobacion'),('edogp','Estado Ganancias y Perdidas')],'Tipo Informe',required=True),
  46. #~ 'type_report': fields.selection([('un_col','Una Columna'),('dos_col','Dos Columnas'),('cuatro_col','Cuatro Columnas')],'Tipo Informe',required=True),
  47. }
  48. _defaults = {
  49. 'date_from': lambda *a: time.strftime('%Y-%m-%d'),
  50. 'date_to': lambda *a: time.strftime('%Y-%m-%d'),
  51. 'filter': lambda *a:'byperiod',
  52. 'display_account_level': lambda *a: 0,
  53. 'inf_type': lambda *a:'bcom',
  54. 'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'account.invoice', context=c),
  55. 'fiscalyear': lambda self, cr, uid, c: self.pool.get('account.fiscalyear').find(cr, uid),
  56. 'display_account': lambda *a:'con_movimiento',
  57. }
  58. def onchange_filter(self,cr,uid,ids,fiscalyear,filters,context=None):
  59. if context is None:
  60. context = {}
  61. res = {}
  62. if filters in ("bydate","all"):
  63. fisy = self.pool.get("account.fiscalyear")
  64. fis_actual = fisy.browse(cr,uid,fiscalyear,context=context)
  65. res = {'value':{'date_from': fis_actual.date_start, 'date_to': fis_actual.date_stop}}
  66. return res
  67. def _get_defaults(self, cr, uid, data, context=None):
  68. if context is None:
  69. context = {}
  70. user = pooler.get_pool(cr.dbname).get('res.users').browse(cr, uid, uid, context=context)
  71. if user.company_id:
  72. company_id = user.company_id.id
  73. else:
  74. company_id = pooler.get_pool(cr.dbname).get('res.company').search(cr, uid, [('parent_id', '=', False)])[0]
  75. data['form']['company_id'] = company_id
  76. fiscalyear_obj = pooler.get_pool(cr.dbname).get('account.fiscalyear')
  77. data['form']['fiscalyear'] = fiscalyear_obj.find(cr, uid)
  78. data['form']['context'] = context
  79. return data['form']
  80. def _check_state(self, cr, uid, data, context=None):
  81. if context is None:
  82. context = {}
  83. if data['form']['filter'] == 'bydate':
  84. self._check_date(cr, uid, data, context)
  85. return data['form']
  86. def _check_date(self, cr, uid, data, context=None):
  87. if context is None:
  88. context = {}
  89. if data['form']['date_from'] > data['form']['date_to']:
  90. raise osv.except_osv(_('Error !'),('La fecha final debe ser mayor a la inicial'))
  91. sql = """SELECT f.id, f.date_start, f.date_stop
  92. FROM account_fiscalyear f
  93. WHERE '%s' = f.id """%(data['form']['fiscalyear'])
  94. cr.execute(sql)
  95. res = cr.dictfetchall()
  96. if res:
  97. if (data['form']['date_to'] > res[0]['date_stop'] or data['form']['date_from'] < res[0]['date_start']):
  98. raise osv.except_osv(_('UserError'),'Las fechas deben estar entre %s y %s' % (res[0]['date_start'], res[0]['date_stop']))
  99. else:
  100. return 'report'
  101. else:
  102. raise osv.except_osv(_('UserError'),'No existe periodo fiscal')
  103. def print_report(self, cr, uid, ids,data, context=None):
  104. if context is None:
  105. context = {}
  106. data = {}
  107. data['ids'] = context.get('active_ids', [])
  108. data['model'] = context.get('active_model', 'ir.ui.menu')
  109. data['form'] = self.read(cr, uid, ids[0])
  110. if data['form']['filter'] == 'byperiod':
  111. del data['form']['date_from']
  112. del data['form']['date_to']
  113. elif data['form']['filter'] == 'bydate':
  114. self._check_date(cr, uid, data)
  115. del data['form']['periods']
  116. elif data['form']['filter'] == 'none':
  117. del data['form']['date_from']
  118. del data['form']['date_to']
  119. del data['form']['periods']
  120. else:
  121. self._check_date(cr, uid, data)
  122. lis2 = str(data['form']['periods']).replace("[","(").replace("]",")")
  123. sqlmm = """select min(p.date_start) as inicio, max(p.date_stop) as fin
  124. from account_period p
  125. where p.id in %s"""%lis2
  126. cr.execute(sqlmm)
  127. minmax = cr.dictfetchall()
  128. if minmax:
  129. if (data['form']['date_to'] < minmax[0]['inicio']) or (data['form']['date_from'] > minmax[0]['fin']):
  130. raise osv.except_osv(_('Error !'),('La intersepcion entre el periodo y fecha es vacio'))
  131. return {'type': 'ir.actions.report.xml', 'report_name': 'account.account.balance.gene', 'datas': data}
  132. wizard_account_balance_gene()