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.

41 lines
1.4 KiB

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 ValidationError
  3. class Subscribe(models.TransientModel):
  4. _name = "beesdoo.shift.holiday"
  5. _description = "beesdoo.shift.holiday"
  6. _inherit = "beesdoo.shift.action_mixin"
  7. holiday_start_day = fields.Date(
  8. string="Start date for the holiday", default=fields.Date.today
  9. )
  10. holiday_end_day = fields.Date(string="End date for the holiday (included)")
  11. @api.multi
  12. def holidays(self):
  13. self = self._check() # maybe a different group
  14. status_id = self.env["cooperative.status"].search(
  15. [("cooperator_id", "=", self.cooperator_id.id)]
  16. )
  17. if (
  18. status_id.holiday_end_time
  19. and status_id.holiday_end_time >= status_id.today
  20. ):
  21. raise ValidationError(
  22. _(
  23. "You cannot encode new holidays since the previous "
  24. "holidays encoded are not over yet "
  25. )
  26. )
  27. status_id.sudo().write(
  28. {
  29. "holiday_start_time": self.holiday_start_day,
  30. "holiday_end_time": self.holiday_end_day,
  31. }
  32. )
  33. self.env["beesdoo.shift.shift"].sudo().unsubscribe_from_today(
  34. [self.cooperator_id.id],
  35. today=self.holiday_start_day,
  36. end_date=self.holiday_end_day,
  37. )