Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADD] beesdoo_shift_website_unsubscribe: add module #305

Open
wants to merge 1 commit into
base: 12.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions polln_shift/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import main
16 changes: 16 additions & 0 deletions polln_shift/controllers/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

from odoo import http
from odoo.http import request

from werkzeug.exceptions import Forbidden

class WebsiteMacavracShiftController(http.Controller):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a better name ?


@http.route("/shift/<int:shift_id>/unsubscribe", auth="user", website=True)
def unsubscribe_to_shift(self, shift_id=-1, **kw):
shift = request.env["beesdoo.shift.shift"].sudo().browse(shift_id)
# Get current user
if request.env.user.partner_id != shift.worker_id or not shift.can_unsubscribe:
raise Forbidden()
shift.worker_id = False
return request.redirect(kw["nexturl"])
14 changes: 14 additions & 0 deletions polln_shift/models/planning.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,20 @@ class Task(models.Model):

_period = 28

can_unsubscribe = fields.Boolean(compute="_compute_can_unsubscribe")

def _compute_can_unsubscribe(self):
now = datetime.now()
ICP = self.env["ir.config_parameter"].sudo()
max_hours = int(ICP.get_param("max_hours_to_unsubscribe", 2))
for rec in self:
if now > rec.start_time or rec.state != 'open':
rec.can_unsubscribe = False
else:
delta = (rec.start_time - now)
delta = delta.seconds / 3600.0 + delta.days * 24
rec.can_unsubscribe = delta >= max_hours

def _get_selection_status(self):
return [
("open", _("Confirmed")),
Expand Down
52 changes: 52 additions & 0 deletions polln_shift/views/shift.xml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,58 @@
<xpath expr="//p[hasclass('h_irreg_autoextension')]" position="replace" />
</template>

<template id="my_shift" name="Shifts for Irregular Workers"
inherit_id="beesdoo_website_shift.my_shift_next_shifts">
<xpath expr="//t[@t-esc='shift.task_type_id.name']" position="replace">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of replace, could you rather

  • submit a PR to beesdoo_shift to replace <t t-esc="shift.task_type_id.name" /> by <t t-esc="shift.task_template_id.name or shift.task_type_id.name" />
  • than adding the button with a <xpath ... position="after">

<t t-esc="shift.task_template_id.name or shift.task_type_id.name" />
<button type="button"
class="btn btn-danger btn-sm pull-right"
data-toggle="modal"
t-att-data-target="'#unsubscribe-shift-%s' % shift.id"
t-if="shift.can_unsubscribe" >
<span class="fa fa-user-plus" aria-hidden="true"></span>
Unsubscribe
</button>
</xpath>
<xpath expr="//div[@t-if='shift.super_coop_id.name']/.." position="after">
<t t-foreach="subscribed_shifts" t-as="shift">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL modals for confirmation popups: nice 🙏 @remytms fyi

<div class="modal fade"
t-att-id="'unsubscribe-shift-%s' % shift.id" tabindex="-1"
role="dialog"
t-att-aria-labelledby="'unsubscribe-shift-%s-label' % shift.id">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title"
t-att-id="'subscribe-shift-%s-label' % shift.id">
Please confirm unsubscriptions
</h4>
</div>
<div class="modal-body">
<span t-field="shift.start_time"/>
-
<span t-field="shift.end_time"
t-options='{"format": "HH:mm"}'/>
<br/>
<t t-esc="shift.task_type_id.name"/>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default"
data-dismiss="modal">Close
</button>
<a class="btn btn-primary"
t-if="irregular_enable_sign_up"
t-att-href="'/shift/%s/unsubscribe?nexturl=%s' % (shift.id, nexturl)">
Unsubscribe
</a>
</div>
</div>
</div>
</div>
</t>
</xpath>
</template>

<record model="ir.ui.view" id="subscribe_coop_wizard_view_form">
<field name="name">Subscribe Cooperator</field>
<field name="model">beesdoo.shift.subscribe</field>
Expand Down