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

[WIP] 12.0 [ADD] beesdoo_website_shift_committee #438

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 beesdoo_website_shift_committee/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import controllers
20 changes: 20 additions & 0 deletions beesdoo_website_shift_committee/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2022 Coop IT Easy SC
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

{
"name": "Beesdoo Website Shift Committee",
"summary": """
Add ability for cooperators to request a counter raise
for their work in committees.""",
"author": "Coop IT Easy SC",
"license": "AGPL-3",
"version": "12.0.0.0.0",
"website": "https://github.com/beescoop/Obeesdoo",
"category": "Cooperative management",
"depends": ["beesdoo_website_shift"],
"data": [
"data/mail_template.xml",
"data/system_parameter.xml",
"views/templates.xml",
],
}
1 change: 1 addition & 0 deletions beesdoo_website_shift_committee/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import main
95 changes: 95 additions & 0 deletions beesdoo_website_shift_committee/controllers/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
from datetime import datetime

from werkzeug.exceptions import Forbidden

from odoo import _, http
from odoo.http import request

from odoo.addons.beesdoo_website_shift.controllers.main import WebsiteShiftController


class WebsiteShiftCommitteeController(WebsiteShiftController):
# Override /my/shift webpage controller
@http.route("/my/shift", auth="user", website=True)
def my_shift(self, **kw):
res = super(WebsiteShiftCommitteeController, self).my_shift()
template_context = res.qcontext

template_context["request_committee"] = False
if "request_committee" in kw:
template_context["request_committee"] = kw["request_committee"]

return request.render(res.template, template_context)

@http.route("/my/shift/request/committee/<int:shift_id>", auth="user", website=True)
def request_committee_shift(self, shift_id, **post):
user = request.env["res.users"].sudo().browse(request.uid)
asked_shift = request.env["beesdoo.shift.shift"].sudo().browse(shift_id)
if asked_shift.worker_id.id != user.partner_id.id:
raise Forbidden(
"You can't make this request on a shift you are not working on"
)

if request.httprequest.method == "POST":
reason = request.httprequest.form.get("reason")

mail_template = request.env.ref(
"beesdoo_website_shift_committee.request_committee_shift"
).sudo()
email_to = (
request.env["ir.config_parameter"]
.sudo()
.get_param("validating_user_email")
)
email_values = {
"email_to": email_to,
"reason": reason,
"shift": asked_shift,
}
mail_template.with_context(email_values).send_mail(user.partner_id.id)

request.session["success_message"] = _(
"Your request has been handed over to the members office. "
"You will be notified by email if they accept it."
)
return request.redirect("/my/shift")

return request.render("beesdoo_website_shift_committee.request_committee_shift")

@http.route(
"/validate/committee/<int:worker_id>/<int:shift_id>", auth="user", website=True
)
def validate_committee_shift(self, worker_id, shift_id):
# Check current user rights
cur_user = request.env["res.users"].sudo().browse(request.uid)
if not cur_user.has_group("beesdoo_shift.group_shift_management"):
raise Forbidden("You don't have the right to perform this operation")

asking_worker = request.env["res.partner"].sudo().browse(worker_id)
asked_shift = request.env["beesdoo.shift.shift"].sudo().browse(shift_id)

if (
asked_shift
and asked_shift.worker_id.id == asking_worker.id
and asked_shift.start_time > datetime.now()
):
asked_shift.write(
{
"is_regular": False,
"is_compensation": False,
"worker_id": False,
}
)
mail_template = request.env.ref(
"beesdoo_website_shift_committee.committee_shift_confirmation"
).sudo()
email_values = {
"partner_to": asking_worker,
"shift": asked_shift,
}
mail_template.with_context(email_values).send_mail(cur_user.partner_id.id)
return request.render(
"beesdoo_website_shift_committee.validate_request_success"
)

return request.render("beesdoo_website_shift_committee.validate_request_error")
62 changes: 62 additions & 0 deletions beesdoo_website_shift_committee/data/mail_template.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<odoo>
<data>

<!-- Contact members office to request a committee shift -->
<record id="request_committee_shift" model="mail.template">
<field
name="name"
>Contact members office to request a committee shift</field>
<field name="model_id" ref="beesdoo_shift_swap.model_res_partner" />
<field name="email_to">${ctx.get('email_to')}</field>
<field name="auto_delete" eval="False" />
<field name="subject">Committee shift request</field>
<field name="body_html">
<![CDATA[
<div style="font-family: 'Lucica Grande', Ubuntu, Arial, Verdana, sans-serif; font-size: 12px; color: rgb(34, 34, 34); background-color: #FFF; ">
Hello,
<br/><br/>
<p>
${object.name} has requested to be unsubscribed to the following shift for his or her work in a committee:
${ctx.get('shift').name}.
</p>
<p>
The following reason has been provided:
<div class="font-italic">
${ctx.get("reason")}
</div>
</p>
<p>
If you want to validate this request, please <a href="/validate/committee/${object.id}/${ctx.get('shift').id}">click here</a>.
</p>
<br/><br/>
Regards,
</div>
]]>
</field>
</record>

<!-- Contact worker when committee shift is validated -->
<record id="committee_shift_confirmation" model="mail.template">
<field name="name">Contact worker when committee shift is validated</field>
<field name="model_id" ref="beesdoo_shift_swap.model_res_partner" />
<field name="partner_to">${ctx.get('partner_to').id}</field>
<field name="auto_delete" eval="False" />
<field name="subject">Your request has been validated</field>
<field name="body_html">
<![CDATA[
<div style="font-family: 'Lucica Grande', Ubuntu, Arial, Verdana, sans-serif; font-size: 12px; color: rgb(34, 34, 34); background-color: #FFF; ">
Hello ${ctx.get('partner_to').name},
<br/><br/>
<p>
Your unsubscription request related to shift ${ctx.get('asked_shift').name} for your work in
a committee has been validated. You don't have to attend it anymore.
</p>
<br/><br/>
Regards,
</div>
]]>
</field>
</record>

</data>
</odoo>
10 changes: 10 additions & 0 deletions beesdoo_website_shift_committee/data/system_parameter.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<odoo>
<data noupdate="1">

<record id="validating_user_email" model="ir.config_parameter">
<field name="key">validating_user_email</field>
<field name="value">[email protected]</field>
</record>

</data>
</odoo>
3 changes: 3 additions & 0 deletions beesdoo_website_shift_committee/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* `Coop IT Easy SC <https://coopiteasy.be>`_:

* Mattéo Ledoux
2 changes: 2 additions & 0 deletions beesdoo_website_shift_committee/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add ability for cooperators to request a counter raise for their work in
committees.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add ability for cooperators to request a counter raise for their work in
committees.
167 changes: 167 additions & 0 deletions beesdoo_website_shift_committee/views/templates.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
<odoo>
<data>

<template
id="request_committee_shift_button"
name="Button to request a committee shift"
inherit_id="beesdoo_website_shift.my_shift_regular_worker"
>
<xpath
expr="//t[@t-call='beesdoo_website_shift.help_text_info']"
position="before"
>
<p>
<button
type="button"
class="btn btn-primary btn-sm"
data-toggle="modal"
data-target="#request_committee_modal"
>
Request a compensation for your work in a committee
</button>
<div
class="modal fade"
id="request_committee_modal"
tabindex="-1"
aria-labelledby="request_committee_modal_label"
aria-hidden="true"
>
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5
class="modal-title"
id="request_committee_modal_label"
>Request a compensation for your work in a committee</h5>
<button
type="button"
class="close"
data-dismiss="modal"
aria-label="Close"
>
<span><![CDATA[&times;]]></span>
</button>
</div>
<div class="modal-body">
*Explanatory text committee shift*
</div>
<div class="modal-footer">
<button
type="button"
class="btn btn-danger"
data-dismiss="modal"
>Cancel</button>
<a
class="btn btn-success"
href="/my/shift?request_committee=1"
>Make a request</a>
</div>
</div>
</div>
</div>
</p>
</xpath>
</template>

<template
id="committee_shift_button"
name="Committee shift button"
inherit_id="beesdoo_website_shift.my_shift_next_shifts"
>
<xpath expr="//div[hasclass('card-body', 'clearfix')]" position="inside">
<t t-if="request_committee and shift.id">
<a
class="btn btn-secondary btn-sm ml-2 pull-right"
t-att-href="'/my/shift/request/committee/%i' % shift.id"
>
Request unsubscription
</a>
</t>
</xpath>
</template>

<!-- Template for page /my/shift/request/committee -->
<template id="request_committee_shift" name="Request a committee shift">
<t t-call="portal.portal_layout">
<t t-set="no_breadcrumbs" t-value="True" />
<div class="container mt16">
<div class="row">
<div class="col text-center">
<h2
class="text-center"
>Request a compensation for your work in a committee</h2>
</div>
</div>
<div class="row">
<div class="col-12 col-lg-6 m-auto text-justify">
<form method="POST">
<div class="form-group">
<label
for="reason"
>Please motivate your request:</label>
<textarea
class="form-control"
name="reason"
rows="5"
/>
</div>
<button
type="submit"
class="btn btn-success"
>Validate request</button>
<a href="/my/shift" class="btn btn-danger">Cancel</a>
<input
type="hidden"
name="csrf_token"
t-att-value="request.csrf_token()"
/>
</form>
</div>
</div>
</div>
</t>
</template>

<!-- Validation success -->
<template
id="validate_request_success"
name="Success message after validating the request"
>
<t t-call="portal.portal_layout">
<t t-set="no_breadcrumbs" t-value="True" />
<div class="container mt16">
<div class="row">
<div class="col text-center">
<div class="alert alert-success">
<strong>Success!</strong>
The request has been accepted and the worker has been notified by email.
</div>
</div>
</div>
</div>
</t>
</template>

<!-- Validation error -->
<template
id="validate_request_error"
name="Error message when validating the request"
>
<t t-call="portal.portal_layout">
<t t-set="no_breadcrumbs" t-value="True" />
<div class="container mt16">
<div class="row">
<div class="col text-center">
<div class="alert alert-danger">
<strong>Error!</strong>
The request could not be validated. Please check that the shift
is not in the past and has not been deleted.
</div>
</div>
</div>
</div>
</t>
</template>

</data>
</odoo>
6 changes: 6 additions & 0 deletions setup/beesdoo_website_shift_committee/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)