Browse Source

[FIX] b_website_shift: unsubscribed worker

The user unsubscribed and resigning should not be able to subscribe to a
shift.
pull/128/head
Rémy Taymans 6 years ago
parent
commit
81e25904c0
  1. 19
      beesdoo_website_shift/controllers/main.py

19
beesdoo_website_shift/controllers/main.py

@ -33,6 +33,19 @@ class WebsiteShiftController(http.Controller):
working_mode = user.partner_id.working_mode working_mode = user.partner_id.working_mode
return working_mode == 'exempt' return working_mode == 'exempt'
def user_can_subscribe(self, user=None):
"""Return True if a user can subscribe to a shift. A user can
subiscribe if:
* the user is an irregular worker
* the user is not unsubscribed
* the user is not resigning
"""
if not user:
user = request.env['res.users'].browse(request.uid)
return (user.partner_id.working_mode == 'irregular'
and user.partner_id.state != 'unsubscribed'
and user.partner_id.state != 'resigning')
def add_days(self, datetime, days): def add_days(self, datetime, days):
""" """
Add the number of days to datetime. This take the DST in Add the number of days to datetime. This take the DST in
@ -98,7 +111,7 @@ class WebsiteShiftController(http.Controller):
Subscribe the current connected user into the given shift Subscribe the current connected user into the given shift
This is done only if : This is done only if :
* shift sign up is authorised via configuration panel * shift sign up is authorised via configuration panel
* the current connected user is an irregular worker
* the user can subscribe
* the given shift exist * the given shift exist
* the shift status is open * the shift status is open
* the shift is free for subscription * the shift is free for subscription
@ -115,7 +128,7 @@ class WebsiteShiftController(http.Controller):
request.session['success'] = False request.session['success'] = False
if (irregular_enable_sign_up if (irregular_enable_sign_up
and cur_user.partner_id.working_mode == 'irregular'
and self.user_can_subscribe()
and shift and shift
and shift.status_id == open_status and shift.status_id == open_status
and not shift.worker_id): and not shift.worker_id):
@ -174,7 +187,7 @@ class WebsiteShiftController(http.Controller):
template_context.update(self.my_shift_next_shifts()) template_context.update(self.my_shift_next_shifts())
template_context.update(self.my_shift_past_shifts()) template_context.update(self.my_shift_past_shifts())
template_context.update(self.available_shift_irregular_worker( template_context.update(self.available_shift_irregular_worker(
irregular_enable_sign_up, nexturl
irregular_enable_sign_up and self.user_can_subscribe(), nexturl
)) ))
# Add feedback about the success or the fail of the subscription # Add feedback about the success or the fail of the subscription

Loading…
Cancel
Save