Browse Source

[WIP] 2

12.0-macavrac-prod
Thibault Francois 4 years ago
parent
commit
fd3ae85656
  1. 16
      beesdoo_website_shift/views/my_shift_website_templates.xml
  2. 1
      macavrac_base/__init__.py
  3. 2
      macavrac_base/__manifest__.py
  4. 1
      macavrac_base/controllers/__init__.py
  5. 16
      macavrac_base/controllers/main.py
  6. 10
      macavrac_base/models/planning.py
  7. 51
      macavrac_base/views/shift.xml

16
beesdoo_website_shift/views/my_shift_website_templates.xml

@ -141,16 +141,6 @@
</div>
<div class="card-body clearfix">
<t t-esc="shift.task_type_id.name"/>
<button
type="button"
class="btn btn-default 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>
<button
type="button"
class="btn btn-default btn-sm pull-right"
@ -281,7 +271,7 @@
</div>
<button
type="button"
class="btn btn-default btn-sm pull-right"
class="btn btn-primary btn-sm pull-right"
data-toggle="modal"
t-att-data-target="'#subscribe-shift-%s' % shift.id"
t-if="irregular_enable_sign_up and not is_subscribed"
@ -304,10 +294,6 @@
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close"
data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title"
t-att-id="'subscribe-shift-%s-label' % shift.id">
Please confirm subscription

1
macavrac_base/__init__.py

@ -1 +1,2 @@
from . import models
from . import controllers

2
macavrac_base/__manifest__.py

@ -7,7 +7,7 @@
"author": "Patricia Daloze, Coop IT Easy SCRLfs",
"category": "Sales",
"version": "12.0.1.0.0",
"depends": ["beesdoo_shift", "contacts"],
"depends": ["beesdoo_shift", "beesdoo_website_shift", "contacts"],
"data": [
"data/mail_template.xml",
"views/res_partner.xml",

1
macavrac_base/controllers/__init__.py

@ -0,0 +1 @@
from . import main

16
macavrac_base/controllers/main.py

@ -0,0 +1,16 @@
from odoo import http
from odoo.http import request
from werkzeug.exceptions import Forbidden
class WebsiteMacavracShiftController(http.Controller):
@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"])

10
macavrac_base/models/planning.py

@ -57,9 +57,15 @@ class Task(models.Model):
return data, status
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:
print(datetime.now())
rec.can_unsubscribe = True
if now > rec.start_time or rec.state != 'open':
rec.can_unsubscribe = False
else:
delta = (now - rec.start_time).seconds / 3600.0
rec.can_unsubscribe = delta >= max_hours
def write(self, vals):

51
macavrac_base/views/shift.xml

@ -137,4 +137,55 @@
</field>
</field>
</record>
<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="after">
<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">
<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>
</odoo>
Loading…
Cancel
Save