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.

165 lines
7.3 KiB

11 years ago
  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # account_financial_report_webkit module for OpenERP, Webkit based
  5. # extended report financial report
  6. # Copyright (C) 2012 SYLEAM Info Services (<http://www.syleam.fr/>)
  7. # Sebastien LANGE <sebastien.lange@syleam.fr>
  8. #
  9. # This file is a part of account_financial_report_webkit
  10. #
  11. # account_financial_report_webkit is free software: you can redistribute it
  12. # and/or modify it under the terms of the GNU Affero General Public License
  13. # as published by the Free Software Foundation, either version 3 of the
  14. # License, or (at your option) any later version.
  15. #
  16. # account_financial_report_webkit is distributed in the hope that it will be
  17. # useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. # GNU Affero General Public License for more details.
  20. #
  21. # You should have received a copy of the GNU Affero General Public License
  22. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. #
  24. ##############################################################################
  25. from openerp.report import report_sxw
  26. from openerp.tools.translate import _
  27. from openerp import pooler
  28. from datetime import datetime
  29. from .common_reports import CommonReportHeaderWebkit
  30. from .webkit_parser_header_fix import HeaderFooterTextWebKitParser
  31. class PrintJournalWebkit(report_sxw.rml_parse, CommonReportHeaderWebkit):
  32. def __init__(self, cursor, uid, name, context):
  33. super(PrintJournalWebkit, self).__init__(cursor, uid, name,
  34. context=context)
  35. self.pool = pooler.get_pool(self.cr.dbname)
  36. self.cursor = self.cr
  37. company_obj = self.pool.get('res.company')
  38. company_id = company_obj._company_default_get(self.cr, uid,
  39. 'res.users',
  40. context=context)
  41. company = company_obj.browse(self.cr, uid, company_id, context=context)
  42. header_report_name = ' - '.join((_('JOURNALS'), company.name,
  43. company.currency_id.name))
  44. footer_date_time = self.formatLang(str(datetime.today()),
  45. date_time=True)
  46. self.localcontext.update({
  47. 'cr': cursor,
  48. 'uid': uid,
  49. 'report_name': _('Journals'),
  50. 'display_account_raw': self._get_display_account_raw,
  51. 'filter_form': self._get_filter,
  52. 'target_move': self._get_target_move,
  53. 'initial_balance': self._get_initial_balance,
  54. 'amount_currency': self._get_amount_currency,
  55. 'display_partner_account': self._get_display_partner_account,
  56. 'display_target_move': self._get_display_target_move,
  57. 'journals': self._get_journals_br,
  58. 'additional_args': [
  59. ('--header-font-name', 'Helvetica'),
  60. ('--footer-font-name', 'Helvetica'),
  61. ('--header-font-size', '10'),
  62. ('--footer-font-size', '6'),
  63. ('--header-left', header_report_name),
  64. ('--header-spacing', '2'),
  65. ('--footer-left', footer_date_time),
  66. ('--footer-right', ' '.join((_('Page'), '[page]', _('of'),
  67. '[topage]'))),
  68. ('--footer-line',),
  69. ],
  70. })
  71. def set_context(self, objects, data, ids, report_type=None):
  72. """Populate a ledger_lines attribute on each browse record that will
  73. be used by mako template"""
  74. # Reading form
  75. main_filter = self._get_form_param('filter', data, default='filter_no')
  76. target_move = self._get_form_param('target_move', data, default='all')
  77. start_date = self._get_form_param('date_from', data)
  78. stop_date = self._get_form_param('date_to', data)
  79. start_period = self.get_start_period_br(data)
  80. stop_period = self.get_end_period_br(data)
  81. fiscalyear = self.get_fiscalyear_br(data)
  82. journal_ids = self._get_form_param('journal_ids', data)
  83. chart_account = self._get_chart_account_id_br(data)
  84. account_period_obj = self.pool.get('account.period')
  85. domain = [('journal_id', 'in', journal_ids)]
  86. if main_filter == 'filter_no':
  87. domain += [
  88. ('date', '>=',
  89. self.get_first_fiscalyear_period(fiscalyear).date_start),
  90. ('date', '<=',
  91. self.get_last_fiscalyear_period(fiscalyear).date_stop),
  92. ]
  93. # computation of move lines
  94. elif main_filter == 'filter_date':
  95. domain += [
  96. ('date', '>=', start_date),
  97. ('date', '<=', stop_date),
  98. ]
  99. elif main_filter == 'filter_period':
  100. period_ids = account_period_obj.build_ctx_periods(self.cursor,
  101. self.uid,
  102. start_period.id,
  103. stop_period.id)
  104. domain = [
  105. ('period_id', 'in', period_ids),
  106. ]
  107. if target_move == 'posted':
  108. domain += [('state', '=', 'posted')]
  109. account_journal_period_obj = self.pool.get('account.journal.period')
  110. new_ids = account_journal_period_obj.search(self.cursor, self.uid, [
  111. ('journal_id', 'in', journal_ids),
  112. ('period_id', 'in', period_ids),
  113. ])
  114. objects = account_journal_period_obj.browse(self.cursor, self.uid,
  115. new_ids)
  116. # Sort by journal and period
  117. objects.sort(key=lambda a: (a.journal_id.code, a.period_id.date_start))
  118. move_obj = self.pool.get('account.move')
  119. for journal_period in objects:
  120. domain_arg = [
  121. ('journal_id', '=', journal_period.journal_id.id),
  122. ('period_id', '=', journal_period.period_id.id),
  123. ]
  124. if target_move == 'posted':
  125. domain_arg += [('state', '=', 'posted')]
  126. move_ids = move_obj.search(self.cursor, self.uid, domain_arg,
  127. order="name")
  128. journal_period.moves = move_obj.browse(self.cursor, self.uid,
  129. move_ids)
  130. # Sort account move line by account accountant
  131. for move in journal_period.moves:
  132. move.line_id.sort(key=lambda a: (a.date, a.account_id.code))
  133. self.localcontext.update({
  134. 'fiscalyear': fiscalyear,
  135. 'start_date': start_date,
  136. 'stop_date': stop_date,
  137. 'start_period': start_period,
  138. 'stop_period': stop_period,
  139. 'chart_account': chart_account,
  140. })
  141. return super(PrintJournalWebkit, self).set_context(
  142. objects, data, new_ids, report_type=report_type)
  143. HeaderFooterTextWebKitParser(
  144. 'report.account.account_report_print_journal_webkit',
  145. 'account.journal.period',
  146. 'addons/account_financial_report_webkit/report/templates/\
  147. account_report_print_journal.mako',
  148. parser=PrintJournalWebkit)
  149. # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: