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.

142 lines
4.1 KiB

  1. # Copyright 2017 ACSONE SA/NV
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  3. from odoo import api, fields, models, _
  4. from odoo.tools.safe_eval import safe_eval
  5. from odoo.tools import pycompat
  6. class JournalLedgerReportWizard(models.TransientModel):
  7. """Journal Ledger report wizard."""
  8. _name = 'journal.ledger.report.wizard'
  9. _description = "Journal Ledger Report Wizard"
  10. company_id = fields.Many2one(
  11. comodel_name='res.company',
  12. default=lambda self: self.env.user.company_id,
  13. string='Company',
  14. required=True,
  15. ondelete='cascade',
  16. )
  17. date_range_id = fields.Many2one(
  18. comodel_name='date.range',
  19. string='Date range',
  20. domain="['|', "
  21. "('company_id', '=', False),"
  22. "('company_id', '=', company_id)]",
  23. )
  24. date_from = fields.Date(
  25. string="Start date",
  26. required=True
  27. )
  28. date_to = fields.Date(
  29. string="End date",
  30. required=True
  31. )
  32. journal_ids = fields.Many2many(
  33. comodel_name='account.journal',
  34. string="Journals",
  35. domain="[('company_id', '=', company_id)]",
  36. required=True,
  37. )
  38. move_target = fields.Selection(
  39. selection='_get_move_targets',
  40. default='all',
  41. required=True,
  42. )
  43. foreign_currency = fields.Boolean()
  44. sort_option = fields.Selection(
  45. selection='_get_sort_options',
  46. string="Sort entries by",
  47. default='move_name',
  48. required=True,
  49. )
  50. group_option = fields.Selection(
  51. selection='_get_group_options',
  52. string="Group entries by",
  53. default='journal',
  54. required=True,
  55. )
  56. with_account_name = fields.Boolean(
  57. default=False,
  58. )
  59. @api.model
  60. def _get_move_targets(self):
  61. return [
  62. ('all', _("All")),
  63. ('posted', _("Posted")),
  64. ('draft', _("Not Posted"))
  65. ]
  66. @api.model
  67. def _get_sort_options(self):
  68. return [
  69. ('move_name', _("Entry number")),
  70. ('date', _("Date")),
  71. ]
  72. @api.model
  73. def _get_group_options(self):
  74. return [
  75. ('journal', _("Journal")),
  76. ('none', _("No group")),
  77. ]
  78. @api.onchange('date_range_id')
  79. def onchange_date_range_id(self):
  80. self.date_from = self.date_range_id.date_start
  81. self.date_to = self.date_range_id.date_end
  82. @api.multi
  83. def button_export_html(self):
  84. self.ensure_one()
  85. action = self.env.ref(
  86. 'account_financial_report.action_report_journal_ledger')
  87. vals = action.read()[0]
  88. context1 = vals.get('context', {})
  89. if isinstance(context1, pycompat.string_types):
  90. context1 = safe_eval(context1)
  91. model = self.env['report_journal_ledger']
  92. report = model.create(self._prepare_report_journal_ledger())
  93. report.compute_data_for_report()
  94. context1['active_id'] = report.id
  95. context1['active_ids'] = report.ids
  96. vals['context'] = context1
  97. return vals
  98. @api.multi
  99. def button_export_pdf(self):
  100. self.ensure_one()
  101. report_type = 'qweb-pdf'
  102. return self._export(report_type)
  103. @api.multi
  104. def button_export_xlsx(self):
  105. self.ensure_one()
  106. report_type = 'xlsx'
  107. return self._export(report_type)
  108. @api.multi
  109. def _prepare_report_journal_ledger(self):
  110. self.ensure_one()
  111. return {
  112. 'date_from': self.date_from,
  113. 'date_to': self.date_to,
  114. 'move_target': self.move_target,
  115. 'foreign_currency': self.foreign_currency,
  116. 'company_id': self.company_id.id,
  117. 'journal_ids': [(6, 0, self.journal_ids.ids)],
  118. 'sort_option': self.sort_option,
  119. 'group_option': self.group_option,
  120. 'with_account_name': self.with_account_name,
  121. }
  122. def _export(self, report_type):
  123. """Default export is PDF."""
  124. self.ensure_one()
  125. model = self.env['report_journal_ledger']
  126. report = model.create(self._prepare_report_journal_ledger())
  127. report.compute_data_for_report()
  128. return report.print_report(report_type)