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.

169 lines
8.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. 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. 'currency_id': fields.many2one('res.currency', 'Currency', help="Currency at which this report will be expressed. If not selected will be used the one set in the company"),
  37. 'inf_type': fields.selection([('bgen','Balance Sheet'),('IS','Income Statement'),('bcom','Balance Comprobacion'),('edogp','Estado Ganancias y Perdidas'),('bml','Libro Mayor Legal')],'Tipo Informe',required=True),
  38. 'columns': fields.selection([('one','End. Balance'),('two','Debit | Credit'), ('four','Initial | Debit | Credit | YTD'), ('five','Initial | Debit | Credit | Period | YTD'),('thirteen','12 Months | YTD')],'Columns',required=True),
  39. 'display_account': fields.selection([('all','All Accounts'),('bal', 'With Balance'),('mov','With movements'),('bal_mov','With Balance / Movements')],'Display accounts'),
  40. 'display_account_level': fields.integer('Up to level',help='Display accounts up to this level (0 to show all)'),
  41. 'account_list': fields.many2many ('account.account','rel_wizard_account','account_list','account_id','Root accounts',required=True),
  42. 'fiscalyear': fields.many2one('account.fiscalyear','Fiscal year',help='Fiscal Year for this report',required=True),
  43. 'periods': fields.many2many('account.period','rel_wizard_period','wizard_id','period_id','Periods',help='All periods in the fiscal year if empty'),
  44. 'tot_check': fields.boolean('Summarize?', help='Checking will add a new line at the end of the Report which will Summarize Columns in Report'),
  45. 'lab_str': fields.char('Description', help='Description for the Summary', size= 128),
  46. #~ Deprecated fields
  47. 'filter': fields.selection([('bydate','By Date'),('byperiod','By Period'),('all','By Date and Period'),('none','No Filter')],'Date/Period Filter'),
  48. 'date_to': fields.date('End date'),
  49. 'date_from': fields.date('Start date'),
  50. }
  51. _defaults = {
  52. 'date_from': lambda *a: time.strftime('%Y-%m-%d'),
  53. 'date_to': lambda *a: time.strftime('%Y-%m-%d'),
  54. 'filter': lambda *a:'byperiod',
  55. 'display_account_level': lambda *a: 0,
  56. 'inf_type': lambda *a:'bgen',
  57. 'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'account.invoice', context=c),
  58. 'fiscalyear': lambda self, cr, uid, c: self.pool.get('account.fiscalyear').find(cr, uid),
  59. 'display_account': lambda *a:'bal_mov',
  60. 'columns': lambda *a:'five',
  61. }
  62. def onchange_filter(self,cr,uid,ids,fiscalyear,filters,context=None):
  63. if context is None:
  64. context = {}
  65. res = {}
  66. if filters in ("bydate","all"):
  67. fisy = self.pool.get("account.fiscalyear")
  68. fis_actual = fisy.browse(cr,uid,fiscalyear,context=context)
  69. res = {'value':{'date_from': fis_actual.date_start, 'date_to': fis_actual.date_stop}}
  70. return res
  71. def _get_defaults(self, cr, uid, data, context=None):
  72. if context is None:
  73. context = {}
  74. user = pooler.get_pool(cr.dbname).get('res.users').browse(cr, uid, uid, context=context)
  75. if user.company_id:
  76. company_id = user.company_id.id
  77. else:
  78. company_id = pooler.get_pool(cr.dbname).get('res.company').search(cr, uid, [('parent_id', '=', False)])[0]
  79. data['form']['company_id'] = company_id
  80. fiscalyear_obj = pooler.get_pool(cr.dbname).get('account.fiscalyear')
  81. data['form']['fiscalyear'] = fiscalyear_obj.find(cr, uid)
  82. data['form']['context'] = context
  83. return data['form']
  84. def _check_state(self, cr, uid, data, context=None):
  85. if context is None:
  86. context = {}
  87. if data['form']['filter'] == 'bydate':
  88. self._check_date(cr, uid, data, context)
  89. return data['form']
  90. def _check_date(self, cr, uid, data, context=None):
  91. if context is None:
  92. context = {}
  93. if data['form']['date_from'] > data['form']['date_to']:
  94. raise osv.except_osv(_('Error !'),('La fecha final debe ser mayor a la inicial'))
  95. sql = """SELECT f.id, f.date_start, f.date_stop
  96. FROM account_fiscalyear f
  97. WHERE '%s' = f.id """%(data['form']['fiscalyear'])
  98. cr.execute(sql)
  99. res = cr.dictfetchall()
  100. if res:
  101. if (data['form']['date_to'] > res[0]['date_stop'] or data['form']['date_from'] < res[0]['date_start']):
  102. raise osv.except_osv(_('UserError'),'Las fechas deben estar entre %s y %s' % (res[0]['date_start'], res[0]['date_stop']))
  103. else:
  104. return 'report'
  105. else:
  106. raise osv.except_osv(_('UserError'),'No existe periodo fiscal')
  107. def print_report(self, cr, uid, ids,data, context=None):
  108. if context is None:
  109. context = {}
  110. data = {}
  111. data['ids'] = context.get('active_ids', [])
  112. data['model'] = context.get('active_model', 'ir.ui.menu')
  113. data['form'] = self.read(cr, uid, ids[0])
  114. if data['form']['filter'] == 'byperiod':
  115. del data['form']['date_from']
  116. del data['form']['date_to']
  117. elif data['form']['filter'] == 'bydate':
  118. self._check_date(cr, uid, data)
  119. del data['form']['periods']
  120. elif data['form']['filter'] == 'none':
  121. del data['form']['date_from']
  122. del data['form']['date_to']
  123. del data['form']['periods']
  124. else:
  125. self._check_date(cr, uid, data)
  126. lis2 = str(data['form']['periods']).replace("[","(").replace("]",")")
  127. sqlmm = """select min(p.date_start) as inicio, max(p.date_stop) as fin
  128. from account_period p
  129. where p.id in %s"""%lis2
  130. cr.execute(sqlmm)
  131. minmax = cr.dictfetchall()
  132. if minmax:
  133. if (data['form']['date_to'] < minmax[0]['inicio']) or (data['form']['date_from'] > minmax[0]['fin']):
  134. raise osv.except_osv(_('Error !'),_('La interseccion entre el periodo y fecha es vacio'))
  135. if data['form']['columns'] == 'one':
  136. name = 'afr.1cols'
  137. if data['form']['columns'] == 'two':
  138. name = 'afr.2cols'
  139. if data['form']['columns'] == 'four':
  140. name = 'afr.4cols'
  141. if data['form']['columns'] == 'five':
  142. name = 'afr.5cols'
  143. if data['form']['columns'] == 'thirteen':
  144. name = 'afr.13cols'
  145. print 'NOMBRE DEL REPORTE, ', name
  146. return {'type': 'ir.actions.report.xml', 'report_name': name, 'datas': data}
  147. wizard_report()