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.

80 lines
2.6 KiB

  1. import json
  2. from datetime import datetime, timedelta
  3. from odoo import _, api, fields, models
  4. from odoo.exceptions import UserError, ValidationError
  5. class Task(models.Model):
  6. _inherit = 'beesdoo.shift.shift'
  7. #################################
  8. # State Definition #
  9. #################################
  10. def _get_selection_status(self):
  11. return [
  12. ("open","Confirmed"),
  13. ("done","Attended"),
  14. ("absent_2","Absent - 2 compensations"),
  15. ("absent_1","Absent - 1 compensation"),
  16. ("absent_0","Absent - 0 compensation"),
  17. ("cancel","Cancelled")
  18. ]
  19. def _get_color_mapping(state):
  20. return {
  21. "draft": 0,
  22. "open": 1,
  23. "done": 5,
  24. "absent_2": 2,
  25. "absent_1": 7,
  26. "absent_0": 3,
  27. "cancel": 9,
  28. }[state]
  29. def _get_final_state():
  30. return ["done", "absent_2", "absent_1", "absent_0"]
  31. ##############################################
  32. # Change counter when state change #
  33. ##############################################
  34. def _get_counter_date_state_change(self, new_state):
  35. data = {}
  36. if self.worker_id.working_mode == 'regular':
  37. if not self.replaced_id: #No replacement case
  38. status = self.worker_id.cooperative_status_ids[0]
  39. else:
  40. status = self.replaced_id.cooperative_status_ids[0]
  41. if new_state == "done" and not self.is_regular:
  42. # Regular counter is always updated first
  43. if status.sr < 0:
  44. data['sr'] = 1
  45. elif status.sc < 0:
  46. data['sc'] = 1
  47. # Bonus shift case
  48. else:
  49. data['sr'] = 1
  50. if new_state == "absent_2":
  51. data['sr'] = -1
  52. data['sc'] = -1
  53. if new_state == "absent_1":
  54. data['sr'] = -1
  55. elif self.worker_id.working_mode == 'irregular':
  56. status = self.worker_id.cooperative_status_ids[0]
  57. if new_state == "done" or new_state == "absent_0":
  58. data['sr'] = 1
  59. data['irregular_absence_date'] = False
  60. data['irregular_absence_counter'] = 1 if status.irregular_absence_counter < 0 else 0
  61. if new_state == "absent_2" or new_state == "absent_1":
  62. if new_state == "absent_2":
  63. data['sr'] = -1
  64. data['irregular_absence_date'] = self.start_time.date()
  65. data['irregular_absence_counter'] = -1
  66. return data