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.

162 lines
8.0 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. from tools.translate import _
  32. class wizard_report(osv.osv_memory):
  33. _name = "wizard.report"
  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'),('bml','Libro Mayor Legal')],'Tipo Informe',required=True),
  47. 'columns': fields.selection([('one','End. Balance'),('two','Debit | Credit'),('four',' Init. Balance | Debit | Credit | End. Balance'),('thirteen','12 Months | YTD')],'Column Number',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. 'columns': lambda *a:'four',
  60. }
  61. def onchange_filter(self,cr,uid,ids,fiscalyear,filters,context=None):
  62. if context is None:
  63. context = {}
  64. res = {}
  65. if filters in ("bydate","all"):
  66. fisy = self.pool.get("account.fiscalyear")
  67. fis_actual = fisy.browse(cr,uid,fiscalyear,context=context)
  68. res = {'value':{'date_from': fis_actual.date_start, 'date_to': fis_actual.date_stop}}
  69. return res
  70. def _get_defaults(self, cr, uid, data, context=None):
  71. if context is None:
  72. context = {}
  73. user = pooler.get_pool(cr.dbname).get('res.users').browse(cr, uid, uid, context=context)
  74. if user.company_id:
  75. company_id = user.company_id.id
  76. else:
  77. company_id = pooler.get_pool(cr.dbname).get('res.company').search(cr, uid, [('parent_id', '=', False)])[0]
  78. data['form']['company_id'] = company_id
  79. fiscalyear_obj = pooler.get_pool(cr.dbname).get('account.fiscalyear')
  80. data['form']['fiscalyear'] = fiscalyear_obj.find(cr, uid)
  81. data['form']['context'] = context
  82. return data['form']
  83. def _check_state(self, cr, uid, data, context=None):
  84. if context is None:
  85. context = {}
  86. if data['form']['filter'] == 'bydate':
  87. self._check_date(cr, uid, data, context)
  88. return data['form']
  89. def _check_date(self, cr, uid, data, context=None):
  90. if context is None:
  91. context = {}
  92. if data['form']['date_from'] > data['form']['date_to']:
  93. raise osv.except_osv(_('Error !'),('La fecha final debe ser mayor a la inicial'))
  94. sql = """SELECT f.id, f.date_start, f.date_stop
  95. FROM account_fiscalyear f
  96. WHERE '%s' = f.id """%(data['form']['fiscalyear'])
  97. cr.execute(sql)
  98. res = cr.dictfetchall()
  99. if res:
  100. if (data['form']['date_to'] > res[0]['date_stop'] or data['form']['date_from'] < res[0]['date_start']):
  101. raise osv.except_osv(_('UserError'),'Las fechas deben estar entre %s y %s' % (res[0]['date_start'], res[0]['date_stop']))
  102. else:
  103. return 'report'
  104. else:
  105. raise osv.except_osv(_('UserError'),'No existe periodo fiscal')
  106. def print_report(self, cr, uid, ids,data, context=None):
  107. if context is None:
  108. context = {}
  109. data = {}
  110. data['ids'] = context.get('active_ids', [])
  111. data['model'] = context.get('active_model', 'ir.ui.menu')
  112. data['form'] = self.read(cr, uid, ids[0])
  113. if data['form']['filter'] == 'byperiod':
  114. del data['form']['date_from']
  115. del data['form']['date_to']
  116. elif data['form']['filter'] == 'bydate':
  117. self._check_date(cr, uid, data)
  118. del data['form']['periods']
  119. elif data['form']['filter'] == 'none':
  120. del data['form']['date_from']
  121. del data['form']['date_to']
  122. del data['form']['periods']
  123. else:
  124. self._check_date(cr, uid, data)
  125. lis2 = str(data['form']['periods']).replace("[","(").replace("]",")")
  126. sqlmm = """select min(p.date_start) as inicio, max(p.date_stop) as fin
  127. from account_period p
  128. where p.id in %s"""%lis2
  129. cr.execute(sqlmm)
  130. minmax = cr.dictfetchall()
  131. if minmax:
  132. if (data['form']['date_to'] < minmax[0]['inicio']) or (data['form']['date_from'] > minmax[0]['fin']):
  133. raise osv.except_osv(_('Error !'),_('La interseccion entre el periodo y fecha es vacio'))
  134. if data['form']['columns'] == 'one':
  135. name = 'afr.1cols'
  136. if data['form']['columns'] == 'two':
  137. name = 'afr.2cols'
  138. if data['form']['columns'] == 'four':
  139. name = 'afr.4cols'
  140. if data['form']['columns'] == 'thirteen':
  141. name = 'wizard.report.account.balance.gene'
  142. print 'NOMBRE DEL REPORTE, ', name
  143. return {'type': 'ir.actions.report.xml', 'report_name': name, 'datas': data}
  144. wizard_report()