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.

83 lines
2.7 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. 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(self, 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(self):
  30. return ["done", "absent_2", "absent_1", "absent_0"]
  31. state = fields.Selection(selection=_get_selection_status)
  32. ##############################################
  33. # Change counter when state change #
  34. ##############################################
  35. def _get_counter_date_state_change(self, new_state):
  36. data = {}
  37. if self.worker_id.working_mode == "regular":
  38. if not self.replaced_id: # No replacement case
  39. status = self.worker_id.cooperative_status_ids[0]
  40. else:
  41. status = self.replaced_id.cooperative_status_ids[0]
  42. if new_state == "done" and not self.is_regular:
  43. # Regular counter is always updated first
  44. if status.sr < 0:
  45. data["sr"] = 1
  46. elif status.sc < 0:
  47. data["sc"] = 1
  48. # Bonus shift case
  49. else:
  50. data["sr"] = 1
  51. if new_state == "absent_2":
  52. data["sr"] = -1
  53. data["sc"] = -1
  54. if new_state == "absent_1":
  55. data["sr"] = -1
  56. elif self.worker_id.working_mode == "irregular":
  57. status = self.worker_id.cooperative_status_ids[0]
  58. if new_state == "done" or new_state == "absent_0":
  59. data["sr"] = 1
  60. data["irregular_absence_date"] = False
  61. data["irregular_absence_counter"] = (
  62. 1 if status.irregular_absence_counter < 0 else 0
  63. )
  64. if new_state == "absent_2" or new_state == "absent_1":
  65. if new_state == "absent_2":
  66. data["sr"] = -1
  67. data["irregular_absence_date"] = self.start_time.date()
  68. data["irregular_absence_counter"] = -1
  69. return data, status