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.

44 lines
1.6 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. from odoo import _, api, fields, models
  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(
  8. "cooperative.exempt.reason", "Exempt Reason", required=True
  9. )
  10. temporary_exempt_start_date = fields.Date(
  11. default=fields.Date.today, required=True
  12. )
  13. temporary_exempt_end_date = fields.Date(required=True)
  14. @api.multi
  15. def exempt(self):
  16. self = self._check() # maybe a different group
  17. status_id = self.env["cooperative.status"].search(
  18. [("cooperator_id", "=", self.cooperator_id.id)]
  19. )
  20. if (
  21. status_id.temporary_exempt_end_date
  22. and status_id.temporary_exempt_end_date >= status_id.today
  23. ):
  24. raise ValidationError(
  25. _(
  26. "You cannot encode new temporary exemptuon since the previous one are not over yet"
  27. )
  28. )
  29. status_id.sudo().write(
  30. {
  31. "temporary_exempt_start_date": self.temporary_exempt_start_date,
  32. "temporary_exempt_end_date": self.temporary_exempt_end_date,
  33. "temporary_exempt_reason_id": self.temporary_exempt_reason_id.id,
  34. }
  35. )
  36. self.env["beesdoo.shift.shift"].sudo().unsubscribe_from_today(
  37. [self.cooperator_id.id],
  38. today=self.temporary_exempt_start_date,
  39. end_date=self.temporary_exempt_end_date,
  40. )