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.

56 lines
2.0 KiB

  1. # Copyright 2018 Eficent Business and IT Consulting Services S.L.
  2. # (http://www.eficent.com)
  3. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
  4. from datetime import date, timedelta
  5. from odoo import api, fields, models
  6. class CustomerActivityStatementWizard(models.TransientModel):
  7. """Customer Activity Statement wizard."""
  8. _name = 'customer.activity.statement.wizard'
  9. _description = 'Customer Activity Statement Wizard'
  10. company_id = fields.Many2one(
  11. comodel_name='res.company',
  12. default=lambda self: self.env.user.company_id,
  13. string='Company'
  14. )
  15. date_start = fields.Date(required=True,
  16. default=fields.Date.to_string(
  17. date.today()-timedelta(days=120)))
  18. date_end = fields.Date(required=True,
  19. default=fields.Date.to_string(date.today()))
  20. show_aging_buckets = fields.Boolean(string='Include Aging Buckets',
  21. default=True)
  22. number_partner_ids = fields.Integer(
  23. default=lambda self: len(self._context['active_ids'])
  24. )
  25. filter_partners_non_due = fields.Boolean(
  26. string='Don\'t show partners with no due entries', default=True)
  27. @api.multi
  28. def button_export_pdf(self):
  29. self.ensure_one()
  30. return self._export()
  31. def _prepare_activity_statement(self):
  32. self.ensure_one()
  33. return {
  34. 'date_start': self.date_start,
  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. }
  41. def _export(self):
  42. """Export to PDF."""
  43. data = self._prepare_activity_statement()
  44. return self.env.ref(
  45. 'customer_activity_statement'
  46. '.action_print_customer_activity_statement').report_action(
  47. self, data=data)