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.

63 lines
2.1 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. from odoo import _, api, fields, models
  2. from odoo.exceptions import UserError
  3. class Subscribe(models.TransientModel):
  4. _name = "beesdoo.shift.extension"
  5. _description = "beesdoo.shift.extension"
  6. _inherit = "beesdoo.shift.action_mixin"
  7. def _get_default_extension_delay(self):
  8. return int(
  9. self.env["ir.config_parameter"]
  10. .sudo()
  11. .get_param("default_extension_delay", 28)
  12. )
  13. extension_start_date = fields.Date(
  14. string="Start date for the extension",
  15. default=fields.Date.today,
  16. readonly=True,
  17. )
  18. auto = fields.Boolean("Auto Extension", default=False)
  19. extension_days = fields.Integer(default=_get_default_extension_delay)
  20. @api.multi
  21. def auto_ext(self):
  22. self = self._check(group="beesdoo_shift.group_shift_attendance")
  23. status_id = self.env["cooperative.status"].search(
  24. [("cooperator_id", "=", self.cooperator_id.id)]
  25. )
  26. status_id.sudo().write(
  27. {"extension_start_time": self.extension_start_date}
  28. )
  29. @api.multi
  30. def extension(self):
  31. self = self._check() # maybe a different group
  32. grace_delay = int(
  33. self.env["ir.config_parameter"]
  34. .sudo()
  35. .get_param("default_grace_delay", 10)
  36. )
  37. status_id = self.env["cooperative.status"].search(
  38. [("cooperator_id", "=", self.cooperator_id.id)]
  39. )
  40. if not status_id.extension_start_time:
  41. raise UserError(
  42. _(
  43. "You should not make a manual extension when the grace delay has not been triggered yet"
  44. )
  45. )
  46. today_delay = (
  47. status_id.today - status_id.extension_start_time
  48. ).days - grace_delay
  49. if today_delay < 0:
  50. raise UserError(
  51. _(
  52. "You should not start a manual extension during the grace delay"
  53. )
  54. )
  55. status_id.sudo().write(
  56. {"time_extension": self.extension_days + today_delay}
  57. )