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.

103 lines
3.8 KiB

  1. from odoo import models, fields, api, _
  2. from odoo.exceptions import ValidationError, UserError
  3. from datetime import timedelta, datetime
  4. import logging
  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(string="Worker", compute="_compute_is_worker", store=True)
  13. can_shop = fields.Boolean(string="Is worker allowed to shop?", compute="_compute_can_shop", store=True)
  14. cooperative_status_ids = fields.One2many('cooperative.status', 'cooperator_id', readonly=True)
  15. super = fields.Boolean(related='cooperative_status_ids.super', string="Super Cooperative", readonly=True, store=True)
  16. info_session = fields.Boolean(related='cooperative_status_ids.info_session', string='Information Session ?', readonly=True, store=True)
  17. info_session_date = fields.Date(related='cooperative_status_ids.info_session_date', string='Information Session Date', readonly=True, store=True)
  18. working_mode = fields.Selection(related='cooperative_status_ids.working_mode', readonly=True, store=True)
  19. exempt_reason_id = fields.Many2one(related='cooperative_status_ids.exempt_reason_id', readonly=True, store=True)
  20. state = fields.Selection(related='cooperative_status_ids.status', readonly=True, store=True)
  21. extension_start_time = fields.Date(related='cooperative_status_ids.extension_start_time', string="Extension Start Day", readonly=True, store=True)
  22. subscribed_shift_ids = fields.Many2many('beesdoo.shift.template')
  23. @api.depends("worker_store")
  24. def _compute_is_worker(self):
  25. for rec in self:
  26. rec.is_worker = rec.worker_store
  27. @api.depends("cooperative_status_ids")
  28. def _compute_can_shop(self):
  29. """
  30. Shopping authorisation may vary on the can_shop status of the
  31. cooperative.status but also other parameters.
  32. Overwrite this function to change the default behavior.
  33. """
  34. for rec in self:
  35. if rec.cooperative_status_ids:
  36. rec.can_shop = rec.cooperative_status_ids.can_shop
  37. else:
  38. rec.can_shop = True
  39. @api.multi
  40. def coop_subscribe(self):
  41. return {
  42. 'name': _('Subscribe Cooperator'),
  43. 'type': 'ir.actions.act_window',
  44. 'view_type': 'form',
  45. 'view_mode': 'form',
  46. 'res_model': 'beesdoo.shift.subscribe',
  47. 'target': 'new',
  48. }
  49. @api.multi
  50. def coop_unsubscribe(self):
  51. res = self.coop_subscribe()
  52. res['context'] = {'default_unsubscribed': True}
  53. return res
  54. @api.multi
  55. def manual_extension(self):
  56. return {
  57. 'name': _('Manual Extension'),
  58. 'type': 'ir.actions.act_window',
  59. 'view_type': 'form',
  60. 'view_mode': 'form',
  61. 'res_model': 'beesdoo.shift.extension',
  62. 'target': 'new',
  63. }
  64. @api.multi
  65. def auto_extension(self):
  66. res = self.manual_extension()
  67. res['context'] = {'default_auto': True}
  68. res['name'] = _('Trigger Grace Delay')
  69. return res
  70. @api.multi
  71. def register_holiday(self):
  72. return {
  73. 'name': _('Register Holiday'),
  74. 'type': 'ir.actions.act_window',
  75. 'view_type': 'form',
  76. 'view_mode': 'form',
  77. 'res_model': 'beesdoo.shift.holiday',
  78. 'target': 'new',
  79. }
  80. @api.multi
  81. def temporary_exempt(self):
  82. return {
  83. 'name': _('Temporary Exemption'),
  84. 'type': 'ir.actions.act_window',
  85. 'view_type': 'form',
  86. 'view_mode': 'form',
  87. 'res_model': 'beesdoo.shift.temporary_exemption',
  88. 'target': 'new',
  89. }
  90. #TODO access right + vue on res.partner