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.

129 lines
5.8 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 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 import models, fields
  25. import time
  26. class AccountReportPrintJournalWizard(models.TransientModel):
  27. """Will launch print journal report and pass requiered args"""
  28. # pylint: disable=consider-merging-classes-inherited
  29. _inherit = "account.common.account.report"
  30. _name = "print.journal.webkit"
  31. _description = "Journals Report"
  32. amount_currency = fields.Boolean(
  33. "With Currency", default=False, help="It adds the currency column",
  34. )
  35. filter = fields.Selection(default='filter_period')
  36. # pylint: disable=old-api7-method-defined
  37. def _check_fiscalyear(self, cr, uid, ids, context=None):
  38. obj = self.read(cr, uid, ids[0], ['fiscalyear_id', 'filter'],
  39. context=context)
  40. if not obj['fiscalyear_id'] and obj['filter'] == 'filter_no':
  41. return False
  42. return True
  43. _constraints = [
  44. (_check_fiscalyear, 'When no Fiscal year is selected, you must choose \
  45. to filter by periods or by date.', ['filter']),
  46. ]
  47. # pylint: disable=old-api7-method-defined
  48. def pre_print_report(self, cr, uid, ids, data, context=None):
  49. data = super(AccountReportPrintJournalWizard, self).\
  50. pre_print_report(cr, uid, ids, data, context=context)
  51. # will be used to attach the report on the main account
  52. data['ids'] = [data['form']['chart_account_id']]
  53. vals = self.read(cr, uid, ids,
  54. ['amount_currency',
  55. 'display_account',
  56. 'journal_ids'],
  57. context=context)[0]
  58. data['form'].update(vals)
  59. return data
  60. # pylint: disable=old-api7-method-defined
  61. def onchange_filter(self, cr, uid, ids, filter='filter_no',
  62. fiscalyear_id=False, context=None):
  63. res = {}
  64. if filter == 'filter_no':
  65. res['value'] = {'period_from': False,
  66. 'period_to': False,
  67. 'date_from': False,
  68. 'date_to': False}
  69. if filter == 'filter_date':
  70. if fiscalyear_id:
  71. fyear = self.pool.get('account.fiscalyear').browse(
  72. cr, uid, fiscalyear_id, context=context)
  73. date_from = fyear.date_start
  74. date_to = fyear.date_stop > time.strftime(
  75. '%Y-%m-%d') and time.strftime('%Y-%m-%d') \
  76. or fyear.date_stop
  77. else:
  78. date_from, date_to = time.strftime(
  79. '%Y-01-01'), time.strftime('%Y-%m-%d')
  80. res['value'] = {'period_from': False, 'period_to':
  81. False, 'date_from': date_from, 'date_to': date_to}
  82. if filter == 'filter_period' and fiscalyear_id:
  83. start_period = end_period = False
  84. cr.execute('''
  85. SELECT * FROM (SELECT p.id
  86. FROM account_period p
  87. LEFT JOIN account_fiscalyear f
  88. ON (p.fiscalyear_id = f.id)
  89. WHERE f.id = %s
  90. AND COALESCE(p.special, FALSE) = FALSE
  91. ORDER BY p.date_start ASC
  92. LIMIT 1) AS period_start
  93. UNION ALL
  94. SELECT * FROM (SELECT p.id
  95. FROM account_period p
  96. LEFT JOIN account_fiscalyear f
  97. ON (p.fiscalyear_id = f.id)
  98. WHERE f.id = %s
  99. AND p.date_start < NOW()
  100. AND COALESCE(p.special, FALSE) = FALSE
  101. ORDER BY p.date_stop DESC
  102. LIMIT 1) AS period_stop''',
  103. (fiscalyear_id, fiscalyear_id))
  104. periods = [i[0] for i in cr.fetchall()]
  105. if periods:
  106. start_period = end_period = periods[0]
  107. if len(periods) > 1:
  108. end_period = periods[1]
  109. res['value'] = {'period_from': start_period, 'period_to':
  110. end_period, 'date_from': False, 'date_to': False}
  111. return res
  112. # pylint: disable=old-api7-method-defined
  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}