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.

55 lines
2.0 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2017 Eficent Business and IT Consulting Services S.L.
  3. # (http://www.eficent.com)
  4. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
  5. from datetime import date
  6. from odoo import api, fields, models
  7. class CustomerOutstandingStatementWizard(models.TransientModel):
  8. """Customer Outstanding Statement wizard."""
  9. _name = 'customer.outstanding.statement.wizard'
  10. _description = 'Customer Outstanding Statement 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_end = fields.Date(required=True,
  17. default=fields.Date.to_string(date.today()))
  18. show_aging_buckets = fields.Boolean(string='Include Aging Buckets',
  19. default=True)
  20. number_partner_ids = fields.Integer(
  21. default=lambda self: len(self._context['active_ids'])
  22. )
  23. filter_partners_non_due = fields.Boolean(
  24. string='Don\'t show partners with no due entries', default=True)
  25. account_type = fields.Selection(
  26. [('receivable', 'Receivable'),
  27. ('payable', 'Payable')], string='Account type', default='receivable')
  28. @api.multi
  29. def button_export_pdf(self):
  30. self.ensure_one()
  31. return self._export()
  32. def _prepare_outstanding_statement(self):
  33. self.ensure_one()
  34. return {
  35. 'date_end': self.date_end,
  36. 'company_id': self.company_id.id,
  37. 'partner_ids': self._context['active_ids'],
  38. 'show_aging_buckets': self.show_aging_buckets,
  39. 'filter_non_due_partners': self.filter_partners_non_due,
  40. 'account_type': self.account_type,
  41. }
  42. def _export(self):
  43. """Export to PDF."""
  44. data = self._prepare_outstanding_statement()
  45. return self.env['report'].with_context(landscape=True).get_action(
  46. self, 'customer_outstanding_statement.statement', data=data)