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.

23 lines
1.3 KiB

  1. from odoo import models, fields, api, _
  2. from odoo.exceptions import ValidationError
  3. class TemporaryExemption(models.TransientModel):
  4. _name = 'beesdoo.shift.temporary_exemption'
  5. _inherit = 'beesdoo.shift.action_mixin'
  6. temporary_exempt_reason_id = fields.Many2one('cooperative.exempt.reason', 'Exempt Reason', required=True)
  7. temporary_exempt_start_date = fields.Date(default=fields.Date.today, required=True)
  8. temporary_exempt_end_date = fields.Date(required=True)
  9. @api.multi
  10. def exempt(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.temporary_exempt_end_date and status_id.temporary_exempt_end_date >= status_id.today:
  14. raise ValidationError(_("You cannot encode new temporary exemptuon since the previous one are not over yet"))
  15. status_id.sudo().write({
  16. 'temporary_exempt_start_date': self.temporary_exempt_start_date,
  17. 'temporary_exempt_end_date': self.temporary_exempt_end_date,
  18. 'temporary_exempt_reason_id': self.temporary_exempt_reason_id.id,
  19. })
  20. self.env['beesdoo.shift.shift'].sudo().unsubscribe_from_today([self.cooperator_id.id], today=self.temporary_exempt_start_date, end_date=self.temporary_exempt_end_date)