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.

98 lines
3.6 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(related="worker_store", string="Worker", readonly=False)
  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("cooperative_status_ids")
  24. def _compute_can_shop(self):
  25. """
  26. Shopping authorisation may vary on the can_shop status of the
  27. cooperative.status but also other parameters.
  28. Overwrite this function to change the default behavior.
  29. """
  30. for rec in self:
  31. if rec.cooperative_status_ids:
  32. rec.can_shop = rec.cooperative_status_ids.can_shop
  33. else:
  34. rec.can_shop = True
  35. @api.multi
  36. def coop_subscribe(self):
  37. return {
  38. 'name': _('Subscribe Cooperator'),
  39. 'type': 'ir.actions.act_window',
  40. 'view_type': 'form',
  41. 'view_mode': 'form',
  42. 'res_model': 'beesdoo.shift.subscribe',
  43. 'target': 'new',
  44. }
  45. @api.multi
  46. def coop_unsubscribe(self):
  47. res = self.coop_subscribe()
  48. res['context'] = {'default_unsubscribed': True}
  49. return res
  50. @api.multi
  51. def manual_extension(self):
  52. return {
  53. 'name': _('Manual Extension'),
  54. 'type': 'ir.actions.act_window',
  55. 'view_type': 'form',
  56. 'view_mode': 'form',
  57. 'res_model': 'beesdoo.shift.extension',
  58. 'target': 'new',
  59. }
  60. @api.multi
  61. def auto_extension(self):
  62. res = self.manual_extension()
  63. res['context'] = {'default_auto': True}
  64. res['name'] = _('Trigger Grace Delay')
  65. return res
  66. @api.multi
  67. def register_holiday(self):
  68. return {
  69. 'name': _('Register Holiday'),
  70. 'type': 'ir.actions.act_window',
  71. 'view_type': 'form',
  72. 'view_mode': 'form',
  73. 'res_model': 'beesdoo.shift.holiday',
  74. 'target': 'new',
  75. }
  76. @api.multi
  77. def temporary_exempt(self):
  78. return {
  79. 'name': _('Temporary Exemption'),
  80. 'type': 'ir.actions.act_window',
  81. 'view_type': 'form',
  82. 'view_mode': 'form',
  83. 'res_model': 'beesdoo.shift.temporary_exemption',
  84. 'target': 'new',
  85. }
  86. #TODO access right + vue on res.partner