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.

137 lines
4.0 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
  1. import logging
  2. from datetime import datetime, timedelta
  3. from odoo import _, api, fields, models
  4. from odoo.exceptions import UserError, ValidationError
  5. class ResPartner(models.Model):
  6. """
  7. One2many relationship with CooperativeStatus should
  8. be replaced by inheritance.
  9. """
  10. _inherit = "res.partner"
  11. worker_store = fields.Boolean(default=False)
  12. is_worker = fields.Boolean(
  13. related="worker_store", string="Worker", readonly=False
  14. )
  15. can_shop = fields.Boolean(
  16. string="Is worker allowed to shop?",
  17. compute="_compute_can_shop",
  18. store=True,
  19. )
  20. cooperative_status_ids = fields.One2many(
  21. "cooperative.status", "cooperator_id", 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