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.

19 lines
1.1 KiB

  1. from odoo import models, fields, api, _
  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(string="Start date for the holiday", default=fields.Date.today)
  8. holiday_end_day = fields.Date(string="End date for the holiday (included)")
  9. @api.multi
  10. def holidays(self):
  11. self = self._check() # maybe a different group
  12. status_id = self.env['cooperative.status'].search([('cooperator_id', '=', self.cooperator_id.id)])
  13. if status_id.holiday_end_time and status_id.holiday_end_time >= status_id.today:
  14. raise ValidationError(_("You cannot encode new holidays since the previous holidays encoded are not over yet"))
  15. status_id.sudo().write({'holiday_start_time': self.holiday_start_day, 'holiday_end_time': self.holiday_end_day})
  16. self.env['beesdoo.shift.shift'].sudo().unsubscribe_from_today([self.cooperator_id.id], today=self.holiday_start_day, end_date=self.holiday_end_day)