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.

79 lines
2.6 KiB

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