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 openerp import api, fields, models
  7. class CustomerActivityStatementWizard(models.TransientModel):
  8. """Customer Activity Statement wizard."""
  9. _name = 'customer.activity.statement.wizard'
  10. _description = 'Customer Activity 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_start = fields.Date(required=True,
  17. default=fields.Date.to_string(
  18. date(date.today().year, 1, 1)))
  19. date_end = fields.Date(required=True,
  20. default=fields.Date.to_string(date.today()))
  21. show_aging_buckets = fields.Boolean(string='Include Aging Buckets',
  22. default=True)
  23. number_partner_ids = fields.Integer(
  24. default=lambda self: len(self._context['active_ids'])
  25. )
  26. filter_partners_non_due = fields.Boolean(
  27. string='Don\'t show partners with no due entries', default=True)
  28. @api.multi
  29. def button_export_pdf(self):
  30. self.ensure_one()
  31. return self._export()
  32. def _prepare_activity_statement(self):
  33. self.ensure_one()
  34. return {
  35. 'date_start': self.date_start,
  36. 'date_end': self.date_end,
  37. 'company_id': self.company_id.id,
  38. 'partner_ids': self._context['active_ids'],
  39. 'show_aging_buckets': self.show_aging_buckets,
  40. 'filter_non_due_partners': self.filter_partners_non_due,
  41. }
  42. def _export(self):
  43. """Export to PDF."""
  44. data = self._prepare_activity_statement()
  45. return self.env['report'].with_context(landscape=True).get_action(
  46. self, 'customer_activity_statement.statement', data=data)