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.

147 lines
6.7 KiB

  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # account_financial_report_webkit module for OpenERP, Webkit based extended report financial report
  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 and/or modify
  11. # it under the terms of the GNU Affero General Public License as published by
  12. # the Free Software Foundation, either version 3 of the License, or
  13. # (at your option) any later version.
  14. #
  15. # account_financial_report_webkit is distributed in the hope that it will be useful,
  16. # 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 report import report_sxw
  25. from tools.translate import _
  26. import pooler
  27. from datetime import datetime
  28. from common_reports import CommonReportHeaderWebkit
  29. from webkit_parser_header_fix import HeaderFooterTextWebKitParser
  30. class PrintJournalWebkit(report_sxw.rml_parse, CommonReportHeaderWebkit):
  31. def __init__(self, cursor, uid, name, context):
  32. super(PrintJournalWebkit, self).__init__(cursor, uid, name, context=context)
  33. self.pool = pooler.get_pool(self.cr.dbname)
  34. self.cursor = self.cr
  35. company_obj = self.pool.get('res.company')
  36. company_id = company_obj._company_default_get(self.cr, uid, 'res.users', context=context)
  37. company = company_obj.browse(self.cr, uid, company_id, context=context)
  38. header_report_name = ' - '.join((_('JOURNALS'), company.name, company.currency_id.name))
  39. footer_date_time = self.formatLang(str(datetime.today()), date_time=True)
  40. self.localcontext.update({
  41. 'cr': cursor,
  42. 'uid': uid,
  43. 'report_name': _('Journals'),
  44. 'display_account_raw': self._get_display_account_raw,
  45. 'filter_form': self._get_filter,
  46. 'target_move': self._get_target_move,
  47. 'initial_balance': self._get_initial_balance,
  48. 'amount_currency': self._get_amount_currency,
  49. 'display_partner_account': self._get_display_partner_account,
  50. 'display_target_move': self._get_display_target_move,
  51. 'journals': self._get_journals_br,
  52. 'additional_args': [
  53. ('--header-font-name', 'Helvetica'),
  54. ('--footer-font-name', 'Helvetica'),
  55. ('--header-font-size', '10'),
  56. ('--footer-font-size', '6'),
  57. ('--header-left', header_report_name),
  58. ('--header-spacing', '2'),
  59. ('--footer-left', footer_date_time),
  60. ('--footer-right', ' '.join((_('Page'), '[page]', _('of'), '[topage]'))),
  61. ('--footer-line',),
  62. ],
  63. })
  64. def set_context(self, objects, data, ids, report_type=None):
  65. """Populate a ledger_lines attribute on each browse record that will be used
  66. by mako template"""
  67. # Reading form
  68. main_filter = self._get_form_param('filter', data, default='filter_no')
  69. target_move = self._get_form_param('target_move', data, default='all')
  70. start_date = self._get_form_param('date_from', data)
  71. stop_date = self._get_form_param('date_to', data)
  72. start_period = self.get_start_period_br(data)
  73. stop_period = self.get_end_period_br(data)
  74. fiscalyear = self.get_fiscalyear_br(data)
  75. journal_ids = self._get_form_param('journal_ids', data)
  76. chart_account = self._get_chart_account_id_br(data)
  77. account_period_obj = self.pool.get('account.period')
  78. domain = [('journal_id', 'in', journal_ids)]
  79. if main_filter == 'filter_no':
  80. domain += [
  81. ('date', '>=', self.get_first_fiscalyear_period(fiscalyear).date_start),
  82. ('date', '<=', self.get_last_fiscalyear_period(fiscalyear).date_stop),
  83. ]
  84. # computation of move lines
  85. elif main_filter == 'filter_date':
  86. domain += [
  87. ('date', '>=', start_date),
  88. ('date', '<=', stop_date),
  89. ]
  90. elif main_filter == 'filter_period':
  91. period_ids = account_period_obj.build_ctx_periods(self.cursor, self.uid, start_period.id, stop_period.id)
  92. domain = [
  93. ('period_id', 'in', period_ids),
  94. ]
  95. if target_move == 'posted':
  96. domain += [('state', '=', 'posted')]
  97. account_journal_period_obj = self.pool.get('account.journal.period')
  98. new_ids = account_journal_period_obj.search(self.cursor, self.uid, [
  99. ('journal_id', 'in', journal_ids),
  100. ('period_id', 'in', period_ids),
  101. ])
  102. objects = account_journal_period_obj.browse(self.cursor, self.uid, new_ids)
  103. # Sort by journal and period
  104. objects.sort(key=lambda a: (a.journal_id.code, a.period_id.date_start))
  105. move_obj = self.pool.get('account.move')
  106. for journal_period in objects:
  107. domain_arg = [
  108. ('journal_id', '=', journal_period.journal_id.id),
  109. ('period_id', '=', journal_period.period_id.id),
  110. ]
  111. if target_move == 'posted':
  112. domain_arg += [('state', '=', 'posted')]
  113. move_ids = move_obj.search(self.cursor, self.uid, domain_arg, order="name")
  114. journal_period.moves = move_obj.browse(self.cursor, self.uid, move_ids)
  115. # Sort account move line by account accountant
  116. for move in journal_period.moves:
  117. move.line_id.sort(key=lambda a: (a.date, a.account_id.code))
  118. self.localcontext.update({
  119. 'fiscalyear': fiscalyear,
  120. 'start_date': start_date,
  121. 'stop_date': stop_date,
  122. 'start_period': start_period,
  123. 'stop_period': stop_period,
  124. 'chart_account': chart_account,
  125. })
  126. return super(PrintJournalWebkit, self).set_context(objects, data, new_ids, report_type=report_type)
  127. HeaderFooterTextWebKitParser('report.account.account_report_print_journal_webkit',
  128. 'account.journal.period',
  129. 'addons/account_financial_report_webkit/report/templates/account_report_print_journal.mako',
  130. parser=PrintJournalWebkit)
  131. # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: