Skip to content

Commit

Permalink
[ADD] b_shift,b_website_shift: unsubscribe from a compensation shift
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoLdx committed May 24, 2022
1 parent a334510 commit c10ec0e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
13 changes: 10 additions & 3 deletions beesdoo_shift/models/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,19 @@ def _compute_can_unsubscribe(self):
ICP.get_param("beesdoo_website_shift.max_hours_to_unsubscribe", 2)
)
for rec in self:
if now > rec.start_time or rec.state != "open":
rec.can_unsubscribe = False
else:
if (
rec.start_time > now
and rec.state == "open"
and (
(rec.worker_id and rec.worker_id.working_mode == "irregular")
or rec.is_compensation
)
):
delta = rec.start_time - now
delta = delta.seconds / 3600.0 + delta.days * 24
rec.can_unsubscribe = delta >= max_hours
else:
rec.can_unsubscribe = False

@api.constrains("state")
def _lock_future_task(self):
Expand Down
2 changes: 1 addition & 1 deletion beesdoo_website_shift/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def unsubscribe_to_shift(self, shift_id=-1, **kw):
# Get current user
if request.env.user.partner_id != shift.worker_id or not shift.can_unsubscribe:
raise Forbidden()
shift.worker_id = False
shift.write({"is_regular": False, "is_compensation": False, "worker_id": False})
request.session["unsubscribe_success"] = True
return request.redirect(kw["nexturl"])

Expand Down
7 changes: 3 additions & 4 deletions beesdoo_website_shift/views/my_shift_website_templates.xml
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
</t>
</div>
<div class="card-body clearfix">
<t t-esc="shift.task_template_id.name or shift.task_type_id.name" />
<t t-esc="shift.task_type_id.name" />
<button
type="button"
class="btn btn-danger btn-sm pull-right"
Expand Down Expand Up @@ -245,7 +245,7 @@
class="modal-title"
t-att-id="'subscribe-shift-%s-label' % shift.id"
>
Please confirm unsubscriptions
Please confirm unsubscription
</h4>
</div>
<div class="modal-body">
Expand All @@ -267,8 +267,7 @@
</button>
<a
class="btn btn-primary"
t-if="irregular_enable_sign_up"
t-att-href="'/shift/%s/unsubscribe?nexturl=%s' % (shift.id, nexturl)"
t-att-href="'/shift/%s/unsubscribe?nexturl=%s' % (shift.id, nexturl or '/my/shift')"
>
Unsubscribe
</a>
Expand Down

0 comments on commit c10ec0e

Please sign in to comment.