Browse Source

[ADD] beesdoo_shift: warn when assigning a second shift

Warn when adding a shift to a worker who is already subscribed to one.
pull/105/head
Augustin Borsu 5 years ago
committed by Elouan
parent
commit
c4967ddf5d
  1. 20
      beesdoo_shift/models/planning.py
  2. 12
      beesdoo_shift/wizard/subscribe.py
  3. 4
      beesdoo_shift/wizard/subscribe.xml

20
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)
}
}

12
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")

4
beesdoo_shift/wizard/subscribe.xml

@ -16,12 +16,16 @@
<field name="working_mode" />
<field name="exempt_reason_id" attrs="{'invisible':[('working_mode', '!=', 'exempt')]}"/>
<field name="shift_id" domain="[('remaining_worker', '>', 0)]" attrs="{'invisible': [('working_mode', '!=', 'regular')]}"/>
<field name="nb_shifts" attrs="{'invisible': True}"/>
<field name="irregular_start_date" attrs="{'invisible': [('working_mode', '!=', 'irregular')]}" />
<field name="super" />
<field name="reset_counter" />
<field name="reset_compensation_counter" /> <!-- TODO access right -->
</group>
<footer>
<div class="alert alert-danger" role="alert" attrs="{'invisible': [('nb_shifts', '&lt;', 2)]}">
Current worker has more than one shift, subscribing him to a new shift will erase all previous shifts.
</div>
<button type="object" name="subscribe"
string="Confirm" class="oe_highlight" attrs="{'invisible': [('unsubscribed', '=', True)]}" />
<button type="object" name="unsubscribe"

Loading…
Cancel
Save