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.

42 lines
1.3 KiB

  1. # Copyright 2018 ForgeFlow, S.L. (http://www.forgeflow.com)
  2. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
  3. from dateutil.relativedelta import relativedelta
  4. from odoo import api, fields, models
  5. class ActivityStatementWizard(models.TransientModel):
  6. """Activity Statement wizard."""
  7. _inherit = "statement.common.wizard"
  8. _name = "activity.statement.wizard"
  9. _description = "Activity Statement Wizard"
  10. @api.model
  11. def _get_date_start(self):
  12. return (
  13. fields.Date.context_today(self).replace(day=1) - relativedelta(days=1)
  14. ).replace(day=1)
  15. date_start = fields.Date(required=True, default=_get_date_start)
  16. @api.onchange("aging_type")
  17. def onchange_aging_type(self):
  18. super().onchange_aging_type()
  19. if self.aging_type == "months":
  20. self.date_start = self.date_end.replace(day=1)
  21. else:
  22. self.date_start = self.date_end - relativedelta(days=30)
  23. def _export(self):
  24. """Export to PDF."""
  25. data = self._prepare_statement()
  26. return self.env.ref(
  27. "partner_statement.action_print_activity_statement"
  28. ).report_action(self.ids, data=data)
  29. def _prepare_statement(self):
  30. res = super()._prepare_statement()
  31. res.update({"date_start": self.date_start})
  32. return res