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.

133 lines
3.8 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
  1. from odoo import _, api, fields, models
  2. class ResPartner(models.Model):
  3. """
  4. One2many relationship with CooperativeStatus should
  5. be replaced by inheritance.
  6. """
  7. _inherit = "res.partner"
  8. worker_store = fields.Boolean(default=False)
  9. is_worker = fields.Boolean(
  10. related="worker_store", string="Worker", readonly=False
  11. )
  12. can_shop = fields.Boolean(
  13. string="Is worker allowed to shop?",
  14. compute="_compute_can_shop",
  15. store=True,
  16. )
  17. cooperative_status_ids = fields.One2many(
  18. "cooperative.status", "cooperator_id", readonly=True
  19. )
  20. super = fields.Boolean(
  21. related="cooperative_status_ids.super",
  22. string="Super Cooperative",
  23. readonly=True,
  24. store=True,
  25. )
  26. info_session = fields.Boolean(
  27. related="cooperative_status_ids.info_session",
  28. string="Information Session ?",
  29. readonly=True,
  30. store=True,
  31. )
  32. info_session_date = fields.Date(
  33. related="cooperative_status_ids.info_session_date",
  34. string="Information Session Date",
  35. readonly=True,
  36. store=True,
  37. )
  38. working_mode = fields.Selection(
  39. related="cooperative_status_ids.working_mode",
  40. readonly=True,
  41. store=True,
  42. )
  43. exempt_reason_id = fields.Many2one(
  44. related="cooperative_status_ids.exempt_reason_id",
  45. readonly=True,
  46. store=True,
  47. )
  48. state = fields.Selection(
  49. related="cooperative_status_ids.status", readonly=True, store=True
  50. )
  51. extension_start_time = fields.Date(
  52. related="cooperative_status_ids.extension_start_time",
  53. string="Extension Start Day",
  54. readonly=True,
  55. store=True,
  56. )
  57. subscribed_shift_ids = fields.Many2many("beesdoo.shift.template")
  58. @api.depends("cooperative_status_ids")
  59. def _compute_can_shop(self):
  60. """
  61. Shopping authorisation may vary on the can_shop status of the
  62. cooperative.status but also other parameters.
  63. Overwrite this function to change the default behavior.
  64. """
  65. for rec in self:
  66. if rec.cooperative_status_ids:
  67. rec.can_shop = rec.cooperative_status_ids.can_shop
  68. else:
  69. rec.can_shop = True
  70. @api.multi
  71. def coop_subscribe(self):
  72. return {
  73. "name": _("Subscribe Cooperator"),
  74. "type": "ir.actions.act_window",
  75. "view_type": "form",
  76. "view_mode": "form",
  77. "res_model": "beesdoo.shift.subscribe",
  78. "target": "new",
  79. }
  80. @api.multi
  81. def coop_unsubscribe(self):
  82. res = self.coop_subscribe()
  83. res["context"] = {"default_unsubscribed": True}
  84. return res
  85. @api.multi
  86. def manual_extension(self):
  87. return {
  88. "name": _("Manual Extension"),
  89. "type": "ir.actions.act_window",
  90. "view_type": "form",
  91. "view_mode": "form",
  92. "res_model": "beesdoo.shift.extension",
  93. "target": "new",
  94. }
  95. @api.multi
  96. def auto_extension(self):
  97. res = self.manual_extension()
  98. res["context"] = {"default_auto": True}
  99. res["name"] = _("Trigger Grace Delay")
  100. return res
  101. @api.multi
  102. def register_holiday(self):
  103. return {
  104. "name": _("Register Holiday"),
  105. "type": "ir.actions.act_window",
  106. "view_type": "form",
  107. "view_mode": "form",
  108. "res_model": "beesdoo.shift.holiday",
  109. "target": "new",
  110. }
  111. @api.multi
  112. def temporary_exempt(self):
  113. return {
  114. "name": _("Temporary Exemption"),
  115. "type": "ir.actions.act_window",
  116. "view_type": "form",
  117. "view_mode": "form",
  118. "res_model": "beesdoo.shift.temporary_exemption",
  119. "target": "new",
  120. }
  121. # TODO access right + vue on res.partner