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.

24 lines
1.3 KiB

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