Skip to content

Commit

Permalink
Users can register to a shift on planning page
Browse files Browse the repository at this point in the history
  • Loading branch information
emillumine committed Dec 19, 2019
1 parent 77362b3 commit 4dc1ab7
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 6 deletions.
3 changes: 2 additions & 1 deletion intercoop_addons/coop_memberspace/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
{
'name': 'Coop Memberspace',
'description': """
Version 0.0.0.3 : inscription à un service (volant ou rattrapage) possible depuis la page planning
Version 0.0.0.2 : ajout de la page planning par Supercoop pour visualiser les prochains services confirmés avec le nombre de places disponibles
""",
'version': '0.0.0.2',
'version': '0.0.0.3',
'category': 'Custom',
'author': 'La Louve',
'website': 'http://www.lalouve.net',
Expand Down
4 changes: 3 additions & 1 deletion intercoop_addons/coop_memberspace/controllers/main.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,16 @@ def web_login(self, redirect=None, *args, **kw):

@http.route('/planning', type='http', auth='user', website=True)
def page_planning(self, **kwargs):
user = request.env.user
upcoming_shifts = request.env['shift.shift'].sudo().search([
('date_begin', '>=', datetime.now().strftime('%Y-%m-%d %H:%M:%S')),
('state', '=', 'confirm'),
], order="date_begin") or []
return request.render(
'coop_memberspace.planning',
{
'user': request.env.user,
'user': user,
'shift_type': user.partner_id.shift_type,
'upcoming_shifts': upcoming_shifts,
}
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
odoo.define('coop_memberspace.programmer_un_service', function (require) {
"use strict";

var snippet_animation = require('web_editor.snippets.animation');
var session = require('web.session');
var Model = require('web.Model');
var ajax = require("web.ajax");

snippet_animation.registry.programmer_un_service =
snippet_animation.Class.extend({
selector: '.programmer_un_service',
start: function () {
var self = this;
ajax.jsonRpc("/web/session/get_session_info", "call").then(function (sessiondata) {
self.session = sessiondata;
});
$('.fa.fa-user-plus').on('click', function() {
let shift_id = $(this).attr('data-shift-id');
self.shift_id = shift_id;
let shift_type = $(this).attr('data-shift-type');
self.shift_type = shift_type;
let time = $('#time-' + shift_id).text();
$('#modal_time').text(time);
});

$('.fa.fa-check').on('click', function(e) {
e.preventDefault();
let btn_check = this;
$(btn_check).attr("disabled", "disabled");
new Model('shift.ticket').call(
'search', [[['shift_id', '=', parseInt(self.shift_id)], ['shift_type', '=', self.shift_type]]])
.then(function(data) {
if (data.length > 0) {
let vals = {
'state': 'draft',
'partner_id': parseInt(self.session.partner_id),
'shift_id': parseInt(self.shift_id),
'shift_ticket_id': parseInt(data[0]),
'related_extension_id': false
}
new Model('shift.registration').call(
'create', [vals])
.then(function(result) {
$('#btn-add-' + self.shift_id).hide();
let no_available_seats = '#avalable-seats-' + self.shift_id;
$(no_available_seats).text(parseInt($(no_available_seats).text()) - 1);
let shift = "#shift-" + self.shift_id;
$(shift).css({'color': 'grey', 'background-color': '#e7e7e7'});
$('#programmer_modal').modal('hide');
$(btn_check).removeAttr("disabled");
})
.fail(function(error, event) {
$('#error_header').text(error.message);
$('#error_body').text(error.data.arguments[0] || '');
$('#programmer_modal').modal('hide');
$('#error_modal').modal('show');
$(btn_check).removeAttr("disabled");
});
}
else {
$(btn_check).removeAttr("disabled");
}
})
});
}
})
});
1 change: 1 addition & 0 deletions intercoop_addons/coop_memberspace/views/templates.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<script src="/coop_memberspace/static/src/js/style.js" type="text/javascript"/>
<script src="/coop_memberspace/static/src/js/programmer_un_extra.js" type="text/javascript"/>
<script src="/coop_memberspace/static/src/js/programmer_une_vacation.js" type="text/javascript"/>
<script src="/coop_memberspace/static/src/js/programmer_un_service.js" type="text/javascript"/>
<script src="/coop_memberspace/static/src/js/my_profile.js" type="text/javascript"/>
<script src="/coop_memberspace/static/src/js/statistics.js" type="text/javascript"/>
<script src="/coop_memberspace/static/src/js/exchange_shift.js" type="text/javascript"/>
Expand Down
19 changes: 15 additions & 4 deletions intercoop_addons/coop_memberspace/views/website/planning.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<div class="row">
<h1>Planning du magasin</h1>
<p>Manque de coopérateurs·trices sur les services à venir : choisir en priorité les créneaux <span style="color: #ee2c2c;">rouges</span>, puis <span style="color: #ffa500;">oranges</span>, puis <span style="color: #ffd700;">jaunes</span>, puis <span style="color: #ffe4c4;">beiges</span>...</p>
<div class="row">
<div class="row programmer_un_service">
<t t-if="upcoming_shifts">
<t t-set="week_number" t-value="dict(upcoming_shifts[0]._fields['week_number'].selection).get(upcoming_shifts[0].week_number)" />
<t t-set="date" t-value="upcoming_shifts[0].date_without_time" />
Expand All @@ -25,6 +25,7 @@
</t>
<t t-set="present" t-value="datetime.datetime.now()" />
<t t-set="availability_rate" t-value="float(shift.seats_available) / shift.seats_max" />
<t t-set="user_is_registered" t-value="user.partner_id in shift.registration_ids.mapped('partner_id')" />

<t t-set="css_color_style" t-value="''"/>
<t t-if="availability_rate >= 0.25">
Expand All @@ -39,16 +40,26 @@
<t t-if="shift.seats_available > 0 and present > (datetime.datetime.strptime(shift.date_begin_tz, '%Y-%m-%d %H:%M:%S') - datetime.timedelta(days=3))">
<t t-set="css_color_style" t-value="'color: #fbd4d4; background-color: #ee2c2c;'"/>
</t>
<t t-if="user_is_registered">
<t t-set="css_color_style" t-value="'color: grey; background-color: #e7e7e7;'"/>
</t>

<div t-attf-class="col-md-3" t-attf-style="border: 1px solid; margin: 10px; {{ css_color_style }}">
<div t-attf-id="shift-{{shift.id}}" t-attf-class="col-md-3" t-attf-style="border: 1px solid; margin: 10px; {{ css_color_style }}">
<h5><span t-esc="shift.name" /></h5>
<t t-set="date_begin" t-value="user.get_time_by_user_lang(shift.date_begin, ['%A %d %B %Hh%M', '%HH%M'], lang=user.lang + '.utf8')" />
<t t-set="date_end" t-value="user.get_time_by_user_lang(shift.date_end, ['%A %d %B %Hh%M', '%HH%M'], lang=user.lang + '.utf8')" />
<div><span t-esc="date_begin and date_begin[0] or ''" /> - <span t-esc="date_end and date_end[1] or ''" /></div>
<div><span t-attf-id="time-{{shift.id}}" t-esc="date_begin and date_begin[0] or ''" /> - <span t-esc="date_end and date_end[1] or ''" /></div>
<div><span t-esc="shift.seats_reserved" /> participants attendus</div>
<div><strong><span t-esc="shift.seats_available" /> places disponibles</strong></div>
<div>
<strong><span t-attf-id="avalable-seats-{{shift.id}}" t-esc="shift.seats_available" /> places disponibles</strong>
<t t-if="shift.seats_available > 0 and not user_is_registered">
<a><span class="fa fa-user-plus" data-toggle="modal" data-target="#programmer_modal" t-attf-id="btn-add-{{shift.id}}" t-att-data-shift-id="shift.id" t-att-data-shift-type="shift_type" /></a>
</t>
</div>
</div>
</t>
<t t-call="coop_memberspace.programmer_modal" />
<t t-call="coop_memberspace.modal_error" />
</div>
</div>
</div>
Expand Down

0 comments on commit 4dc1ab7

Please sign in to comment.