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.

128 lines
5.7 KiB

  1. # -*- encoding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # OpenERP, Open Source Management Solution
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. ##############################################################################
  20. import wizard
  21. import pooler
  22. import time
  23. from tools.translate import _
  24. options_form = '''<?xml version="1.0"?>
  25. <form string="Full Account Balance">
  26. <field name="company_id"/>
  27. <newline/>
  28. <group colspan="4">
  29. <separator string="Accounts to include" colspan="4"/>
  30. <field name="account_list" nolabel="1" colspan="4" domain="[('company_id','=',company_id)]"/>
  31. <field name="display_account" required="True"/>
  32. <field name="display_account_level" required="True" />
  33. </group>
  34. <group colspan="4">
  35. <separator string="Period" colspan="4"/>
  36. <field name="fiscalyear"/>
  37. <newline/>
  38. <field name="state" required="True"/>
  39. <newline/>
  40. <group attrs="{'invisible':[('state','=','none')]}" colspan="4">
  41. <group attrs="{'invisible':[('state','=','byperiod')]}" colspan="4">
  42. <separator string="Date Filter" colspan="4"/>
  43. <field name="date_from"/>
  44. <field name="date_to"/>
  45. </group>
  46. <group attrs="{'invisible':[('state','=','bydate')]}" colspan="4">
  47. <separator string="Filter on Periods" colspan="4"/>
  48. <field name="periods" colspan="4" nolabel="1" domain="[('fiscalyear_id','=',fiscalyear)]"/>
  49. </group>
  50. </group>
  51. </group>
  52. </form>'''
  53. options_fields = {
  54. 'company_id': {'string': 'Company', 'type': 'many2one', 'relation': 'res.company', 'required': True},
  55. 'account_list': {'string': 'Root accounts', 'type':'many2many', 'relation':'account.account', 'required':True ,'domain':[]},
  56. 'state':{
  57. 'string':"Date/Period Filter",
  58. 'type':'selection',
  59. 'selection':[('bydate','By Date'),('byperiod','By Period'),('all','By Date and Period'),('none','No Filter')],
  60. 'default': lambda *a:'none'
  61. },
  62. 'fiscalyear': {
  63. 'string':'Fiscal year',
  64. 'type':'many2one',
  65. 'relation':'account.fiscalyear',
  66. 'help':'Keep empty to use all open fiscal years to compute the balance'
  67. },
  68. 'periods': {'string': 'Periods', 'type': 'many2many', 'relation': 'account.period', 'help': 'All periods in the fiscal year if empty'},
  69. 'display_account':{'string':"Display accounts ", 'type':'selection', 'selection':[('bal_all','All'),('bal_solde', 'With balance'),('bal_mouvement','With movements')]},
  70. 'display_account_level':{'string':"Up to level", 'type':'integer', 'default': lambda *a: 0, 'help': 'Display accounts up to this level (0 to show all)'},
  71. 'date_from': {'string':"Start date", 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-01-01')},
  72. 'date_to': {'string':"End date", 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-%m-%d')},
  73. }
  74. class wizard_report(wizard.interface):
  75. def _get_defaults(self, cr, uid, data, context={}):
  76. user = pooler.get_pool(cr.dbname).get('res.users').browse(cr, uid, uid, context=context)
  77. if user.company_id:
  78. company_id = user.company_id.id
  79. else:
  80. company_id = pooler.get_pool(cr.dbname).get('res.company').search(cr, uid, [('parent_id', '=', False)])[0]
  81. data['form']['company_id'] = company_id
  82. fiscalyear_obj = pooler.get_pool(cr.dbname).get('account.fiscalyear')
  83. data['form']['fiscalyear'] = fiscalyear_obj.find(cr, uid)
  84. if (data['model'] == 'account.account'):
  85. data['form']['account_list'] = data['ids']
  86. data['form']['context'] = context
  87. return data['form']
  88. def _check_state(self, cr, uid, data, context):
  89. if data['form']['state'] == 'bydate':
  90. self._check_date(cr, uid, data, context)
  91. return data['form']
  92. def _check_date(self, cr, uid, data, context):
  93. sql = """SELECT f.id, f.date_start, f.date_stop
  94. FROM account_fiscalyear f
  95. WHERE '%s' between f.date_start and f.date_stop """%(data['form']['date_from'])
  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_to'] < res[0]['date_start']):
  100. raise wizard.except_wizard(_('UserError'),_('Date to must be set between %s and %s') % (res[0]['date_start'], res[0]['date_stop']))
  101. else:
  102. return 'report'
  103. else:
  104. raise wizard.except_wizard(_('UserError'),_('Date not in a defined fiscal year'))
  105. states = {
  106. 'init': {
  107. 'actions': [_get_defaults],
  108. 'result': {'type':'form', 'arch': options_form, 'fields': options_fields, 'state':[('end','Cancel','gtk-cancel'),('report','Print','gtk-print')]}
  109. },
  110. 'report': {
  111. 'actions': [_check_state],
  112. 'result': {'type':'print', 'report':'account.balance.full', 'state':'end'}
  113. }
  114. }
  115. wizard_report('account.balance.full.report')