Browse Source

[FIX] b_shift : automatic unsubscribe from next shifts

Doesn't unsubscribe from present shift anymore
when worker is changing to "unsubscribed" status.

You cannot change future shifts status anymore.
pull/124/head
Elouan Le Bars 5 years ago
parent
commit
d92ca20629
  1. 6
      beesdoo_shift/models/cooperative_status.py
  2. 35
      beesdoo_shift/models/task.py

6
beesdoo_shift/models/cooperative_status.py

@ -321,10 +321,10 @@ class CooperativeStatus(models.Model):
[('super_coop_id', 'in', self.cooperator_id.user_ids.ids)] [('super_coop_id', 'in', self.cooperator_id.user_ids.ids)]
) )
task_tpls.write({'super_coop_id': False}) task_tpls.write({'super_coop_id': False})
# Remove worker for future task (remove also supercoop)
# TODO: Add one day otherwise unsubscribed from the shift you were absent
# Remove worker for future tasks (remove also supercoop)
self.env['beesdoo.shift.shift'].sudo().unsubscribe_from_today( self.env['beesdoo.shift.shift'].sudo().unsubscribe_from_today(
[self.cooperator_id.id], today=fields.Date.today())
[self.cooperator_id.id], now=fields.Datetime.now()
)
def _change_counter(self, data): def _change_counter(self, data):
self.sc += data.get('sc', 0) self.sc += data.get('sc', 0)

35
beesdoo_shift/models/task.py

@ -81,6 +81,16 @@ class Task(models.Model):
"Compensation Shift." "Compensation Shift."
) )
@api.constrains("state")
def _lock_future_task(self):
start_time_dt = fields.Datetime.from_string(self.start_time)
if datetime.now() < start_time_dt:
if self.state in ["done", "absent_2", "absent_1", "absent_0"]:
raise UserError(_(
"You cannot set shift state to 'present' "
"or 'absent' for a future shift."
))
@api.constrains('is_regular', 'is_compensation') @api.constrains('is_regular', 'is_compensation')
def _check_compensation(self): def _check_compensation(self):
for task in self: for task in self:
@ -119,19 +129,32 @@ class Task(models.Model):
#TODO button to replaced someone #TODO button to replaced someone
@api.model @api.model
def unsubscribe_from_today(self, worker_ids, today=None, end_date=None):
def unsubscribe_from_today(self, worker_ids, today=None, end_date=None, now=None):
"""
Unsubscribe workers from *worker_ids* from all shift that start *today* and later.
If *end_date* is given, unsubscribe workers from shift between *today* and *end_date*.
If *now* is given workers are unsubscribed from all shifts starting *now* and later.
If *now* is given, *end_date* is not taken into account.
:type today: fields.Date
:type end_date: fields.Date
:type now: fields.Datetime
"""
if now:
if len(now) != 19:
raise UserError (_("'Now' must be a datetime."))
date_domain = [('start_time', '>', now)]
else:
today = today or fields.Date.today() today = today or fields.Date.today()
today += ' 00:00:00' today += ' 00:00:00'
date_domain = [('start_time', '>', today)]
if end_date: if end_date:
end_date += ' 23:59:59' end_date += ' 23:59:59'
# date_domain = [('worker_id', 'in', worker_ids), ('start_time', '>=', today)]
date_domain = [('start_time', '>=', today)]
if end_date:
date_domain.append(('end_time', '<=', end_date)) date_domain.append(('end_time', '<=', end_date))
to_unsubscribe = self.search([('worker_id', 'in', worker_ids)] + date_domain)
to_unsubscribe = self.search([('worker_id', 'in', worker_ids)] + date_domain)
to_unsubscribe.write({'worker_id': False}) to_unsubscribe.write({'worker_id': False})
# What about replacement ?
# Remove worker, replaced_id and regular # Remove worker, replaced_id and regular
to_unsubscribe_replace = self.search([('replaced_id', 'in', worker_ids)] + date_domain) to_unsubscribe_replace = self.search([('replaced_id', 'in', worker_ids)] + date_domain)
to_unsubscribe_replace.write({'worker_id': False, 'replaced_id': False}) to_unsubscribe_replace.write({'worker_id': False, 'replaced_id': False})

Loading…
Cancel
Save