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.

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