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.

96 lines
3.5 KiB

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