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.

150 lines
7.6 KiB

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