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.4 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. _description = '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 and 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)