Commit 5bd03ef4 by Thibault Grandjean

Merge branch '2249-shift-registered-associate' into 'dev_cooperatic'

2249 shift registered associate

See merge request !127
parents 72b2cf32 b9d7a4cc
Pipeline #1849 passed with stage
in 1 minute 30 seconds
......@@ -44,7 +44,7 @@ class CagetteMembersSpace(models.Model):
['state', '!=', 'replaced'],
['state', '!=', 'replacing'],
]
f = ['create_date', 'date_begin', 'shift_id', 'name', 'state', 'is_late', 'is_makeup']
f = ['create_date', 'date_begin', 'shift_id', 'name', 'state', 'is_late', 'is_makeup','associate_registered']
marshal_none_error = 'cannot marshal None unless allow_none is enabled'
try:
......
......@@ -52,7 +52,6 @@
#shifts_list {
flex-direction: column;
display: none;
width: min-content;
max-width: 100%;
white-space: nowrap;
}
......@@ -66,11 +65,13 @@
}
.selectable_shift_line {
min-width: 325px;
display: flex;
align-items: center;
margin-left: 15px;
margin: 0.75rem 0;
border-radius: 5px;
margin-right: 15px;
}
.selectable_shift_line .checkbox {
......@@ -81,6 +82,15 @@
cursor: not-allowed;
}
.affect_associate_registered {
display: flex;
align-items: center;
margin-left: 15px;
margin: 0.75rem 0;
border-radius: 5px;
}
/* -- Calendar screen, makeups message */
#need_to_select_makeups_message {
......
......@@ -66,6 +66,32 @@ function prepare_server_data(data) {
}
}
if (history_item.associate_registered == false || history_item.associate_registered == undefined) {
history_item.associate_registered = "";
}
else {
if (partner_data.associated_partner_id != "False") {
if (history_item.associate_registered==="partner") {
history_item.associate_registered = partner_data.name;
} else if (history_item.associate_registered==="associate") {
history_item.associate_registered = partner_data.associated_partner_name;
} else if (history_item.associate_registered==="both") {
history_item.associate_registered = "Les deux";
} else {
history_item.associate_registered = "";
}
} else if (partner_data.parent_id != "False") {
if (history_item.associate_registered==="partner") {
history_item.associate_registered = partner_data.parent_name;
} else if (history_item.associate_registered==="associate") {
history_item.associate_registered = partner_data.name;
} else if (history_item.associate_registered==="both") {
history_item.associate_registered = "Les deux";
} else {
history_item.associate_registered = "";
}
}
}
history_item.details = '';
if (history_item.state === 'excused' || history_item.state === 'absent') {
history_item.details = "Absent.e";
......@@ -87,7 +113,6 @@ function prepare_server_data(data) {
function init_history() {
$(".loading-history").hide();
$("#history").show();
if (partner_history.length === 0) {
$("#history").empty()
.text("Aucun historique... pour l'instant !");
......@@ -103,7 +128,7 @@ function init_history() {
{
data: "shift_name",
title: "<spans class='dt-body-center'>Service</span>",
width: "60%",
width: "50%",
orderable: false
},
{
......@@ -111,6 +136,11 @@ function init_history() {
title: "Détails",
className: "tablet-l desktop",
orderable: false
},
{
data: "associate_registered",
title: "",
orderable: false
}
],
iDisplayLength: -1,
......@@ -157,6 +187,28 @@ function init_incoming_shifts() {
for (shift of incoming_shifts) {
let shift_line_template = prepare_shift_line_template(shift.date_begin);
if (partner_data.associated_partner_id != "False") {
if (shift.associate_registered==="partner") {
shift_line_template.find(".shift_line_associate").text(' - '+partner_data.name+'');
} else if (shift.associate_registered==="associate") {
shift_line_template.find(".shift_line_associate").text(' - '+partner_data.associated_partner_name+'');
} else if (shift.associate_registered==="both") {
shift_line_template.find(".shift_line_associate").text(' - Les deux');
} else {
shift_line_template.find(".shift_line_associate").text('A définir');
}
} else if (partner_data.parent_id != "False") {
if (shift.associate_registered==="partner") {
shift_line_template.find(".shift_line_associate").text(' - '+partner_data.parent_name+'');
} else if (shift.associate_registered==="associate") {
shift_line_template.find(".shift_line_associate").text(' - '+partner_data.name+'');
} else if (shift.associate_registered==="both") {
shift_line_template.find(".shift_line_associate").text(' - Les deux');
} else {
shift_line_template.find(".shift_line_associate").text('A définir');
}
}
$("#incoming_shifts").append(shift_line_template.html());
}
}
......
......@@ -172,6 +172,30 @@ function init_shifts_list() {
shift_line_template.find(".checkbox").prop("value", shift.id);
}
if (partner_data.associated_partner_id === "False" && partner_data.parent_id === "False") {
shift_line_template.find('.affect_associate_reistered').hide();
} else {
shift_line_template.find('.affect_associate_registered').attr('id', 'shidt_id_'+shift.id);
if (shift.associate_registered==="both") {
shift_line_template.find('.affect_associate_registered').text("Les deux");
} else if (shift.associate_registered==="partner") {
if (partner_data.associated_partner_id !== "False") {
shift_line_template.find('.affect_associate_registered').text(partner_data.name);
} else {
shift_line_template.find('.affect_associate_registered').text(partner_data.parent_name);
}
} else if (shift.associate_registered==="associate") {
if (partner_data.associated_partner_id !== "False") {
shift_line_template.find('.affect_associate_registered').text(partner_data.associated_partner_name);
} else {
shift_line_template.find('.affect_associate_registered').text(partner_data.name);
}
} else {
shift_line_template.find('.affect_associate_registered').text("A déterminer");
}
}
$("#shifts_list").append(shift_line_template.html());
}
......@@ -201,9 +225,90 @@ function init_shifts_list() {
}
}
});
$(".affect_associate_registered").on("click", function() {
// Display modal
id = $(this).attr('id')
.split('_')[2];
let modal_template = $("#modal_affect_shift");
if (partner_data.associated_partner_id != "False") {
modal_template.find("#shift_partner").text(partner_data.name);
modal_template.find("#shift_associate").text(partner_data.associated_partner_name);
} else {
modal_template.find("#shift_partner").text(partner_data.associated_partner_name);
modal_template.find("#shift_associate").text(partner_data.parent_name);
}
openModal(
modal_template.html(),
() => {
modal.find(".btn-modal-ok").show();
},
"Valider", true, true,
() => {
modal.find(".btn-modal-ok").show();
}
);
modal.find('#shift_partner').on("click", function() {
affect_shift("partner", id);
});
modal.find('#shift_associate').on("click", function() {
affect_shift("associate", id);
});
modal.find('#shift_both').on("click", function() {
affect_shift("both", id);
});
modal.find(".btn-modal-ok").hide();
});
}
}
/**
* Proceed to shift modification
* @param {string} partner
* @param {string} shift_id
*/
function affect_shift(partner, shift_id) {
tData = 'idShiftRegistration=' + shift_id
+'&idPartner=' + partner_data.partner_id
+ '&affected_partner=' + partner
+ '&verif_token=' + partner_data.verif_token;
tUrl = '/shifts/affect_shift';
$.ajax({
type: 'POST',
url: tUrl,
dataType:"json",
data: tData,
timeout: 3000,
success: function() {
load_partner_shifts(partner_data.concerned_partner_id)
.then(() => {
init_shifts_list();
modal.find(".btn-modal-ok").show();
closeModal();
});
},
error: function() {
init_shifts_list();
modal.find(".btn-modal-ok").show();
closeModal();
alert(`Une erreur est survenue. ` +
`Il est néanmoins possible que la requête ait abouti, ` +
`veuillez patienter quelques secondes puis vérifier vos services enregistrés.`);
}
});
}
/**
* Inits the page when the calendar is displayed
*/
......@@ -431,7 +536,6 @@ function init_read_only_calendar_page() {
const hidden_days = days_to_hide.length > 0 ? $.map(days_to_hide.split(", "), Number) : [];
const calendarEl = document.getElementById('read_only_calendar');
console.log(calendarEl)
calendar = new FullCalendar.Calendar(calendarEl, {
locale: 'fr',
......@@ -499,6 +603,7 @@ function init_shifts_exchange() {
} else if (
partner_data.comite === "True") {
let msg_template = $("#comite_template");
$(".comite_content_msg").html(msg_template.html());
$("#comite_content").show();
init_read_only_calendar_page();
......@@ -510,7 +615,6 @@ function init_shifts_exchange() {
$(".select_makeups").on('click', () => {
openModal();
// Create 6 month delay
request_delay()
.then(() => {
......
......@@ -147,7 +147,7 @@ function prepare_shift_line_template(date_begin) {
shift_line_template.find(".shift_line_date").text(f_date_shift_start);
shift_line_template.find(".shift_line_time").text(datetime_shift_start.toLocaleTimeString("fr-fr", time_options));
return shift_line_template;
}
......
......@@ -91,7 +91,7 @@ class CagetteShift(models.Model):
def get_shift_partner(self, id):
"""Récupère les shift du membre"""
fields = ['date_begin', 'date_end','final_standard_point',
'shift_id', 'shift_type','partner_id', "id"] # res.partner
'shift_id', 'shift_type','partner_id', "id", "associate_registered"] # res.partner
cond = [['partner_id.id', '=', id],['state', '=', 'open'],
['date_begin', '>', datetime.datetime.now().isoformat()]]
shiftData = self.o_api.search_read('shift.registration', cond, fields, order ="date_begin ASC")
......@@ -174,6 +174,25 @@ class CagetteShift(models.Model):
if res:
st_r_id = True
return st_r_id
def affect_shift(self, data):
"""Affect shift to partner, his associate or both"""
response = None
cond = [['partner_id', '=', int(data['idPartner'])],
['id', '=', int(data['idShiftRegistration'])]]
fields = ['id']
try:
print(cond)
shit_to_affect = self.o_api.search_read('shift.registration', cond, fields, 1)
print(shit_to_affect)
if (len(shit_to_affect) == 1):
shift_res = shit_to_affect[0]
print(shift_res)
fieldsDatas = { "associate_registered":data['affected_partner']}
response = self.o_api.update('shift.registration', [shift_res['id']], fieldsDatas)
except Exception as e:
coop_logger.error("Reopen shift : %s", str(e))
return response
def cancel_shift(self, idsRegisteur):
"""Annule un shift"""
......
......@@ -13,6 +13,7 @@ urlpatterns = [
url(r'^get_test', views.get_test),
# url(r'^get_list', views.get_list),
url(r'^change_shift', views.change_shift),
url(r'^affect_shift', views.affect_shift),
url(r'^add_shift', views.add_shift),
url(r'^request_delay', views.request_delay),
url(r'^reset_members_positive_points', views.reset_members_positive_points)
......
......@@ -234,6 +234,34 @@ def change_shift(request):
else:
return HttpResponseForbidden()
def affect_shift(request):
if 'verif_token' in request.POST:
if Verification.verif_token(request.POST.get('verif_token'), int(request.POST.get('idPartner'))) is True:
cs = CagetteShift()
if 'idShiftRegistration' in request.POST and 'affected_partner' in request.POST:
data = {
"idPartner": int(request.POST['idPartner']),
"idShiftRegistration": int(request.POST['idShiftRegistration']),
"affected_partner": request.POST['affected_partner'],
}
try:
st_r_id = cs.affect_shift(data)
except Exception as e:
coop_logger.error("affect shift : %s, %s", str(e), str(data))
if st_r_id:
response = {'result': True}
else:
response = {'msg': "Internal Error"}
return JsonResponse(response, status=500)
return(JsonResponse({'result': True}))
else:
response = {'msg': "Bad args"}
return JsonResponse(response, status=400)
else:
return HttpResponseForbidden()
else:
return HttpResponseForbidden()
def add_shift(request):
if 'verif_token' in request.POST:
if Verification.verif_token(request.POST.get('verif_token'), int(request.POST.get('idPartner'))) is True:
......
......@@ -31,17 +31,34 @@
<div id="shift_line_template">
<div class="shift_line">
<i class="fas fa-chevron-right shift_line_chevron"></i>
<span class="shift_line_date"></span> - <span class="shift_line_time"></span>
<span class="shift_line_date"></span> - <span class="shift_line_time"></span> <span class="shift_line_associate"> </span>
</div>
</div>
<div id="selectable_shift_line_template">
<div class="selectable_shift_line btn--primary">
<input type="checkbox" class="checkbox">
<div class="selectable_shift_line_text">
<span class="shift_line_date"></span> - <span class="shift_line_time"></span>
<div class="d-flex">
<div class="selectable_shift_line btn--primary">
<input type="checkbox" class="checkbox">
<div class="selectable_shift_line_text">
<span class="shift_line_date"></span> - <span class="shift_line_time"></span>
</div>
</div>
<div class="affect_associate_registered button--warning">
</div>
</div>
</div>
<div id="modal_affect_shift">
<div>Qui sera présent.e ?</div>
<div id="shift_partner" class="btn--primary">
</div>
<div id="shift_associate" class=" btn--primary">
</div>
<div id="shift_both" class=" btn--primary">
Les deux
</div>
</div>
<div id="modal_shift_exchange_template">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment