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.

93 lines
2.9 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
4 years ago
4 years ago
4 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. """
  18. Set of colors:
  19. 0: none,
  20. 1: dark orange,
  21. 2: orange,
  22. 3: yellow,
  23. 4: light blue,
  24. 5: dark purple,
  25. 6: light red (pink),
  26. 7: cyan,
  27. 8: dark blue,
  28. 9: magenta (red),
  29. 10: green,
  30. 11: purple
  31. """
  32. return {
  33. "open": 0,
  34. "done": 10,
  35. "absent_2": 9,
  36. "absent_1": 2,
  37. "absent_0": 3,
  38. "cancel": 5,
  39. }[state]
  40. def _get_final_state(self):
  41. return ["done", "absent_2", "absent_1", "absent_0"]
  42. state = fields.Selection(selection=_get_selection_status)
  43. ##############################################
  44. # Change counter when state change #
  45. ##############################################
  46. def _get_counter_date_state_change(self, new_state):
  47. data = {}
  48. if self.worker_id.working_mode == "regular":
  49. if not self.replaced_id: # No replacement case
  50. status = self.worker_id.cooperative_status_ids[0]
  51. else:
  52. status = self.replaced_id.cooperative_status_ids[0]
  53. if new_state == "done" and not self.is_regular:
  54. # Regular counter is always updated first
  55. if status.sr < 0:
  56. data["sr"] = 1
  57. elif status.sc < 0:
  58. data["sc"] = 1
  59. # Bonus shift case
  60. else:
  61. data["sr"] = 1
  62. if new_state == "absent_2":
  63. data["sr"] = -1
  64. data["sc"] = -1
  65. if new_state == "absent_1":
  66. data["sr"] = -1
  67. elif self.worker_id.working_mode == "irregular":
  68. status = self.worker_id.cooperative_status_ids[0]
  69. if new_state == "done" or new_state == "absent_0":
  70. data["sr"] = 1
  71. data["irregular_absence_date"] = False
  72. data["irregular_absence_counter"] = (
  73. 1 if status.irregular_absence_counter < 0 else 0
  74. )
  75. if new_state == "absent_2" or new_state == "absent_1":
  76. if new_state == "absent_2":
  77. data["sr"] = -1
  78. data["irregular_absence_date"] = self.start_time.date()
  79. data["irregular_absence_counter"] = -1
  80. return data, status