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.

131 lines
5.6 KiB

11 years ago
11 years ago
  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # account_financial_report_webkit module for OpenERP
  5. # Copyright (C) 2012 SYLEAM Info Services (<http://www.syleam.fr/>)
  6. # Sebastien LANGE <sebastien.lange@syleam.fr>
  7. #
  8. # This file is a part of account_financial_report_webkit
  9. #
  10. # account_financial_report_webkit is free software: you can redistribute it
  11. # and/or modify it under the terms of the GNU Affero General Public License
  12. # as published by the Free Software Foundation, either version 3 of the
  13. # License, or (at your option) any later version.
  14. #
  15. # account_financial_report_webkit is distributed in the hope that it will be
  16. # useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. # GNU Affero General Public License for more details.
  19. #
  20. # You should have received a copy of the GNU Affero General Public License
  21. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. #
  23. ##############################################################################
  24. from openerp.osv import fields, orm
  25. import time
  26. class AccountReportPrintJournalWizard(orm.TransientModel):
  27. """Will launch print journal report and pass requiered args"""
  28. _inherit = "account.common.account.report"
  29. _name = "print.journal.webkit"
  30. _description = "Journals Report"
  31. _columns = {
  32. 'amount_currency': fields.boolean("With Currency",
  33. help="It adds the currency column"),
  34. }
  35. _defaults = {
  36. 'amount_currency': False,
  37. 'journal_ids': False,
  38. 'filter': 'filter_period',
  39. }
  40. def _check_fiscalyear(self, cr, uid, ids, context=None):
  41. obj = self.read(cr, uid, ids[0], ['fiscalyear_id', 'filter'],
  42. context=context)
  43. if not obj['fiscalyear_id'] and obj['filter'] == 'filter_no':
  44. return False
  45. return True
  46. _constraints = [
  47. (_check_fiscalyear, 'When no Fiscal year is selected, you must choose \
  48. to filter by periods or by date.', ['filter']),
  49. ]
  50. def pre_print_report(self, cr, uid, ids, data, context=None):
  51. data = super(AccountReportPrintJournalWizard, self).\
  52. pre_print_report(cr, uid, ids, data, context=context)
  53. # will be used to attach the report on the main account
  54. data['ids'] = [data['form']['chart_account_id']]
  55. vals = self.read(cr, uid, ids,
  56. ['amount_currency',
  57. 'display_account',
  58. 'journal_ids'],
  59. context=context)[0]
  60. data['form'].update(vals)
  61. return data
  62. def onchange_filter(self, cr, uid, ids, filter='filter_no',
  63. fiscalyear_id=False, context=None):
  64. res = {}
  65. if filter == 'filter_no':
  66. res['value'] = {'period_from': False,
  67. 'period_to': False,
  68. 'date_from': False,
  69. 'date_to': False}
  70. if filter == 'filter_date':
  71. if fiscalyear_id:
  72. fyear = self.pool.get('account.fiscalyear').browse(
  73. cr, uid, fiscalyear_id, context=context)
  74. date_from = fyear.date_start
  75. date_to = fyear.date_stop > time.strftime(
  76. '%Y-%m-%d') and time.strftime('%Y-%m-%d') \
  77. or fyear.date_stop
  78. else:
  79. date_from, date_to = time.strftime(
  80. '%Y-01-01'), time.strftime('%Y-%m-%d')
  81. res['value'] = {'period_from': False, 'period_to':
  82. False, 'date_from': date_from, 'date_to': date_to}
  83. if filter == 'filter_period' and fiscalyear_id:
  84. start_period = end_period = False
  85. cr.execute('''
  86. SELECT * FROM (SELECT p.id
  87. FROM account_period p
  88. LEFT JOIN account_fiscalyear f
  89. ON (p.fiscalyear_id = f.id)
  90. WHERE f.id = %s
  91. AND COALESCE(p.special, FALSE) = FALSE
  92. ORDER BY p.date_start ASC
  93. LIMIT 1) AS period_start
  94. UNION ALL
  95. SELECT * FROM (SELECT p.id
  96. FROM account_period p
  97. LEFT JOIN account_fiscalyear f
  98. ON (p.fiscalyear_id = f.id)
  99. WHERE f.id = %s
  100. AND p.date_start < NOW()
  101. AND COALESCE(p.special, FALSE) = FALSE
  102. ORDER BY p.date_stop DESC
  103. LIMIT 1) AS period_stop''',
  104. (fiscalyear_id, fiscalyear_id))
  105. periods = [i[0] for i in cr.fetchall()]
  106. if periods:
  107. start_period = end_period = periods[0]
  108. if len(periods) > 1:
  109. end_period = periods[1]
  110. res['value'] = {'period_from': start_period, 'period_to':
  111. end_period, 'date_from': False, 'date_to': False}
  112. return res
  113. def _print_report(self, cursor, uid, ids, data, context=None):
  114. context = context or {}
  115. # we update form with display account value
  116. data = self.pre_print_report(cursor, uid, ids, data, context=context)
  117. return {'type': 'ir.actions.report.xml',
  118. 'report_name': 'account.account_report_print_journal_webkit',
  119. 'datas': data}