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.

40 lines
1.3 KiB

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 holidays encoded are not over yet"
  24. )
  25. )
  26. status_id.sudo().write(
  27. {
  28. "holiday_start_time": self.holiday_start_day,
  29. "holiday_end_time": self.holiday_end_day,
  30. }
  31. )
  32. self.env["beesdoo.shift.shift"].sudo().unsubscribe_from_today(
  33. [self.cooperator_id.id],
  34. today=self.holiday_start_day,
  35. end_date=self.holiday_end_day,
  36. )