diff --git a/beesdoo_shift/models/planning.py b/beesdoo_shift/models/planning.py
index 5b6c47b..d7ea850 100644
--- a/beesdoo_shift/models/planning.py
+++ b/beesdoo_shift/models/planning.py
@@ -178,3 +178,23 @@ class TaskTemplate(models.Model):
})
return tasks
+
+ @api.onchange('worker_ids')
+ def check_for_multiple_shifts(self):
+ original_ids = {worker.id for worker in self._origin.worker_ids}
+
+ warnings = []
+ for worker in self.worker_ids:
+ if worker.id not in original_ids:
+ shifts = [shift.name for shift in worker.subscribed_shift_ids if shift.id != self.id]
+ if shifts:
+ warnings.append(
+ worker.name + _(' is already assigned to ') + ", ".join(shifts))
+
+ if warnings:
+ return {
+ 'warning': {
+ 'title': _("Warning"),
+ 'message': "\n".join(warnings)
+ }
+ }
diff --git a/beesdoo_shift/wizard/subscribe.py b/beesdoo_shift/wizard/subscribe.py
index dc80758..38053f6 100644
--- a/beesdoo_shift/wizard/subscribe.py
+++ b/beesdoo_shift/wizard/subscribe.py
@@ -41,6 +41,15 @@ class Subscribe(models.TransientModel):
.info_session)
return session_followed
+ def _get_shift(self):
+ shifts = self.env['res.partner'].browse(self._context.get('active_id')).subscribed_shift_ids
+ if shifts:
+ return shifts[0]
+ return
+
+ def _get_nb_shifts(self):
+ return len(self.env['res.partner'].browse(self._context.get('active_id')).subscribed_shift_ids)
+
def _get_super(self):
return self.env['res.partner'].browse(self._context.get('active_id')).super
@@ -62,7 +71,8 @@ class Subscribe(models.TransientModel):
], default=_get_mode
)
exempt_reason_id = fields.Many2one('cooperative.exempt.reason', 'Exempt Reason')
- shift_id = fields.Many2one('beesdoo.shift.template')
+ shift_id = fields.Many2one('beesdoo.shift.template', default=_get_shift)
+ nb_shifts = fields.Integer(string='Number of shifts', default=_get_nb_shifts)
reset_counter = fields.Boolean(default=_get_reset_counter_default)
reset_compensation_counter = fields.Boolean(default=False)
unsubscribed = fields.Boolean(default=False, string="Are you sure to unsubscribe this cooperator")
diff --git a/beesdoo_shift/wizard/subscribe.xml b/beesdoo_shift/wizard/subscribe.xml
index 3a10cb7..97b0333 100644
--- a/beesdoo_shift/wizard/subscribe.xml
+++ b/beesdoo_shift/wizard/subscribe.xml
@@ -16,12 +16,16 @@
+