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.

44 lines
1.4 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 dateutil.relativedelta import relativedelta
  5. from odoo import api, fields, models
  6. class ActivityStatementWizard(models.TransientModel):
  7. """Activity Statement wizard."""
  8. _inherit = 'statement.common.wizard'
  9. _name = 'activity.statement.wizard'
  10. _description = 'Activity Statement Wizard'
  11. @api.model
  12. def _get_date_start(self):
  13. return (
  14. fields.Date.context_today(self).replace(day=1) -
  15. relativedelta(days=1)
  16. ).replace(day=1)
  17. date_start = fields.Date(required=True, default=_get_date_start)
  18. @api.onchange('aging_type')
  19. def onchange_aging_type(self):
  20. super().onchange_aging_type()
  21. if self.aging_type == 'months':
  22. self.date_start = self.date_end.replace(day=1)
  23. else:
  24. self.date_start = self.date_end - relativedelta(days=30)
  25. def _export(self):
  26. """Export to PDF."""
  27. data = self._prepare_statement()
  28. return self.env.ref(
  29. 'partner_statement'
  30. '.action_print_activity_statement').report_action(
  31. self, data=data)
  32. def _prepare_statement(self):
  33. res = super()._prepare_statement()
  34. res.update({'date_start': self.date_start})
  35. return res