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.

60 lines
2.2 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
  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(date.today().year, 1, 1)))
  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. account_type = fields.Selection(
  28. [('receivable', 'Receivable'),
  29. ('payable', 'Payable')], string='Account type', default='receivable')
  30. @api.multi
  31. def button_export_pdf(self):
  32. self.ensure_one()
  33. return self._export()
  34. def _prepare_activity_statement(self):
  35. self.ensure_one()
  36. return {
  37. 'date_start': self.date_start,
  38. 'date_end': self.date_end,
  39. 'company_id': self.company_id.id,
  40. 'partner_ids': self._context['active_ids'],
  41. 'show_aging_buckets': self.show_aging_buckets,
  42. 'filter_non_due_partners': self.filter_partners_non_due,
  43. 'account_type': self.account_type,
  44. }
  45. def _export(self):
  46. """Export to PDF."""
  47. data = self._prepare_activity_statement()
  48. return self.env.ref(
  49. 'customer_activity_statement'
  50. '.action_print_customer_activity_statement').report_action(
  51. self, data=data)