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.

106 lines
4.2 KiB

  1. # -*- coding: utf-8 -*-
  2. # Author: Damien Crier
  3. # Author: Julien Coux
  4. # Copyright 2016 Camptocamp SA
  5. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  6. from openerp import models, fields, api
  7. class GeneralLedgerReportWizard(models.TransientModel):
  8. """General ledger report wizard."""
  9. _name = "general.ledger.report.wizard"
  10. _description = "General Ledger Report Wizard"
  11. company_id = fields.Many2one(
  12. comodel_name='res.company',
  13. default=lambda self: self.env.user.company_id
  14. )
  15. date_range_id = fields.Many2one(comodel_name='date.range', required=True)
  16. date_from = fields.Date(required=True)
  17. date_to = fields.Date(required=True)
  18. fy_start_date = fields.Date(required=True)
  19. target_move = fields.Selection([('posted', 'All Posted Entries'),
  20. ('all', 'All Entries')],
  21. string='Target Moves',
  22. required=True,
  23. default='all')
  24. account_ids = fields.Many2many(
  25. comodel_name='account.account',
  26. string='Filter accounts',
  27. )
  28. centralize = fields.Boolean(string='Activate centralization',
  29. default=True)
  30. hide_account_balance_at_0 = fields.Boolean(
  31. string='Hide account ending balance at 0',
  32. help='Use this filter to hide an account or a partner '
  33. 'with an ending balance at 0. '
  34. 'If partners are filtered, '
  35. 'debits and credits totals will not match the trial balance.',
  36. default=False)
  37. receivable_accounts_only = fields.Boolean()
  38. payable_accounts_only = fields.Boolean()
  39. partner_ids = fields.Many2many(
  40. comodel_name='res.partner',
  41. string='Filter partners',
  42. )
  43. @api.onchange('date_range_id')
  44. def onchange_date_range_id(self):
  45. """Handle date range change."""
  46. self.date_from = self.date_range_id.date_start
  47. self.date_to = self.date_range_id.date_end
  48. if self.date_from:
  49. self.fy_start_date = self.env.user.company_id.find_daterange_fy(
  50. fields.Date.from_string(self.date_range_id.date_start)
  51. ).date_start
  52. @api.onchange('receivable_accounts_only', 'payable_accounts_only')
  53. def onchange_type_accounts_only(self):
  54. """Handle receivable/payable accounts only change."""
  55. if self.receivable_accounts_only or self.payable_accounts_only:
  56. domain = []
  57. if self.receivable_accounts_only and self.payable_accounts_only:
  58. domain += [('internal_type', 'in', ('receivable', 'payable'))]
  59. elif self.receivable_accounts_only:
  60. domain += [('internal_type', '=', 'receivable')]
  61. elif self.payable_accounts_only:
  62. domain += [('internal_type', '=', 'payable')]
  63. self.account_ids = self.env['account.account'].search(domain)
  64. else:
  65. self.account_ids = None
  66. @api.onchange('partner_ids')
  67. def onchange_partner_ids(self):
  68. """Handle partners change."""
  69. if self.partner_ids:
  70. self.receivable_accounts_only = self.payable_accounts_only = True
  71. else:
  72. self.receivable_accounts_only = self.payable_accounts_only = False
  73. @api.multi
  74. def button_export_pdf(self):
  75. self.ensure_one()
  76. return self._export()
  77. @api.multi
  78. def button_export_xlsx(self):
  79. self.ensure_one()
  80. return self._export(xlsx_report=True)
  81. def _export(self, xlsx_report=False):
  82. """Default export is PDF."""
  83. model = self.env['report_general_ledger_qweb']
  84. report = model.create({
  85. 'date_from': self.date_from,
  86. 'date_to': self.date_to,
  87. 'only_posted_moves': self.target_move == 'posted',
  88. 'hide_account_balance_at_0': self.hide_account_balance_at_0,
  89. 'company_id': self.company_id.id,
  90. 'filter_account_ids': [(6, 0, self.account_ids.ids)],
  91. 'filter_partner_ids': [(6, 0, self.partner_ids.ids)],
  92. 'centralize': self.centralize,
  93. 'fy_start_date': self.fy_start_date,
  94. })
  95. return report.print_report(xlsx_report)