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.

46 lines
1.7 KiB

4 years ago
4 years ago
4 years ago
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 exemption since the "
  27. "previous one are not over yet "
  28. )
  29. )
  30. reason = self.temporary_exempt_reason_id
  31. status_id.sudo().write(
  32. {
  33. "temporary_exempt_start_date": self.temporary_exempt_start_date,
  34. "temporary_exempt_end_date": self.temporary_exempt_end_date,
  35. "temporary_exempt_reason_id": reason.id,
  36. }
  37. )
  38. self.env["beesdoo.shift.shift"].sudo().unsubscribe_from_today(
  39. [self.cooperator_id.id],
  40. today=self.temporary_exempt_start_date,
  41. end_date=self.temporary_exempt_end_date,
  42. )