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.

153 lines
6.8 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 wizard
  29. import pooler
  30. import time
  31. from tools.translate import _
  32. options_form = '''<?xml version="1.0"?>
  33. <form string="General Account Balance [ Debit - Credit ] (One Column)">
  34. <field name="company_id"/>
  35. <newline/>
  36. <group colspan="4">
  37. <separator string="Accounts to include" colspan="4"/>
  38. <field name="account_list" nolabel="1" colspan="4" domain="[('company_id','=',company_id)]"/>
  39. <field name="display_account" required="True"/>
  40. <field name="display_account_level" required="True" />
  41. </group>
  42. <group colspan="4">
  43. <separator string="Period" colspan="4"/>
  44. <field name="fiscalyear"/>
  45. <newline/>
  46. <field name="state" required="True"/>
  47. <newline/>
  48. <group attrs="{'invisible':[('state','=','none')]}" colspan="4">
  49. <group attrs="{'invisible':[('state','=','byperiod')]}" colspan="4">
  50. <separator string="Date Filter" colspan="4"/>
  51. <field name="date_from"/>
  52. <field name="date_to"/>
  53. </group>
  54. <group attrs="{'invisible':[('state','=','bydate')]}" colspan="4">
  55. <separator string="Filter on Periods" colspan="4"/>
  56. <field name="periods" colspan="4" nolabel="1" domain="[('fiscalyear_id','=',fiscalyear)]"/>
  57. </group>
  58. </group>
  59. </group>
  60. <group colspan="4">
  61. <separator string="Total" colspan="4"/>
  62. <field name="tot_check"/>
  63. <field name="lab_str"/>
  64. <field name="inf_type"/>
  65. </group>
  66. </form>'''
  67. options_fields = {
  68. 'company_id': {'string': 'Company', 'type': 'many2one', 'relation': 'res.company', 'required': True},
  69. 'account_list': {'string': 'Root accounts', 'type':'many2many', 'relation':'account.account', 'required':True ,'domain':[]},
  70. 'state':{
  71. 'string':"Date/Period Filter",
  72. 'type':'selection',
  73. 'selection':[('bydate','By Date'),('byperiod','By Period'),('all','By Date and Period'),('none','No Filter')],
  74. 'default': lambda *a:'none'
  75. },
  76. 'fiscalyear': {
  77. 'string':'Fiscal year',
  78. 'type':'many2one',
  79. 'relation':'account.fiscalyear',
  80. 'help':'Keep empty to use all open fiscal years to compute the balance'
  81. },
  82. 'periods': {'string': 'Periods', 'type': 'many2many', 'relation': 'account.period', 'help': 'All periods in the fiscal year if empty'},
  83. 'display_account':{'string':"Display accounts ", 'type':'selection', 'selection':[('bal_all','All'),('bal_solde', 'With balance'),('bal_mouvement','With movements')]},
  84. 'display_account_level':{'string':"Up to level", 'type':'integer', 'default': lambda *a: 0, 'help': 'Display accounts up to this level (0 to show all)'},
  85. 'date_from': {'string':"Start date", 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-01-01')},
  86. 'date_to': {'string':"End date", 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-%m-%d')},
  87. 'tot_check': {'string':'Show Total', 'type':'boolean'},
  88. 'lab_str': {'string': 'Description', 'type': 'char', 'size': 128},
  89. 'inf_type':{
  90. 'string':"Tipo Informe",
  91. 'type':'selection',
  92. 'selection':[('bgen','Balance General'),('bcom','Balance Comprobacion'),('edogp','Estado Ganancias y Perdidas')],
  93. 'default': lambda *a:'bgen',
  94. 'required':True
  95. },
  96. }
  97. class wizard_report(wizard.interface):
  98. def _get_defaults(self, cr, uid, data, context={}):
  99. user = pooler.get_pool(cr.dbname).get('res.users').browse(cr, uid, uid, context=context)
  100. if user.company_id:
  101. company_id = user.company_id.id
  102. else:
  103. company_id = pooler.get_pool(cr.dbname).get('res.company').search(cr, uid, [('parent_id', '=', False)])[0]
  104. data['form']['company_id'] = company_id
  105. fiscalyear_obj = pooler.get_pool(cr.dbname).get('account.fiscalyear')
  106. data['form']['fiscalyear'] = fiscalyear_obj.find(cr, uid)
  107. data['form']['context'] = context
  108. return data['form']
  109. def _check_state(self, cr, uid, data, context):
  110. if data['form']['state'] == 'bydate':
  111. self._check_date(cr, uid, data, context)
  112. return data['form']
  113. def _check_date(self, cr, uid, data, context):
  114. sql = """SELECT f.id, f.date_start, f.date_stop
  115. FROM account_fiscalyear f
  116. WHERE '%s' between f.date_start and f.date_stop """%(data['form']['date_from'])
  117. cr.execute(sql)
  118. res = cr.dictfetchall()
  119. if res:
  120. if (data['form']['date_to'] > res[0]['date_stop'] or data['form']['date_to'] < res[0]['date_start']):
  121. raise wizard.except_wizard(_('UserError'),_('Date to must be set between %s and %s') % (res[0]['date_start'], res[0]['date_stop']))
  122. else:
  123. return 'report'
  124. else:
  125. raise wizard.except_wizard(_('UserError'),_('Date not in a defined fiscal year'))
  126. states = {
  127. 'init': {
  128. 'actions': [_get_defaults],
  129. 'result': {'type':'form', 'arch': options_form, 'fields': options_fields, 'state':[('end','Cancel','gtk-cancel'),('report','Print','gtk-print')]}
  130. },
  131. 'report': {
  132. 'actions': [_check_state],
  133. 'result': {'type':'print', 'report':'account.account.balance.gene', 'state':'end'}
  134. }
  135. }
  136. wizard_report('account.balance.gene.report')