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.

65 lines
2.1 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 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 "
  44. "delay has not been triggered yet "
  45. )
  46. )
  47. today_delay = (
  48. status_id.today - status_id.extension_start_time
  49. ).days - grace_delay
  50. if today_delay < 0:
  51. raise UserError(
  52. _(
  53. "You should not start a manual extension during the grace "
  54. "delay "
  55. )
  56. )
  57. status_id.sudo().write(
  58. {"time_extension": self.extension_days + today_delay}
  59. )