Commit 7ce5e25b by Damien Moulard

delete shift template registration

parent c443f682
Pipeline #1942 passed with stage
in 1 minute 32 seconds
......@@ -414,7 +414,6 @@ def delete_shift_template_registration(request):
if is_connected_user is True:
try:
data = json.loads(request.body.decode())
partner_id = int(data["partner_id"])
shift_template_id = int(data["shift_template_id"])
makeups_to_do = int(data["makeups_to_do"])
......@@ -428,20 +427,18 @@ def delete_shift_template_registration(request):
target_makeup = makeups_to_do + len(partner_makeups)
if target_makeup > 2:
target_makeup = 2
print(target_makeup)
# Update partner makeups to do
res_update_makeups = cm.update_member_makeups({'target_makeups_nb': target_makeup})
print(res_update_makeups)
res["update_makeups"] = cm.update_member_makeups({'target_makeups_nb': target_makeup})
except Exception as e:
print(str(e))
# Delete all shift registrations & shift template registration
res["unsuscribe_member"] = cm.unsuscribe_member()
if permanent_unsuscribe is True:
res["set_done"] = cm.set_cooperative_state("gone")
# Récupérer nb rattrapages sélectionnés, incrémenter makeups_to_do
# Delete all shift.registration
# Delete all shift.template.registration (et .line ?)
# si permanent_unsuscribe, set special status gone
except Exception as e:
res["error"] = str(e)
response = JsonResponse(res, safe=False)
else:
......
......@@ -889,6 +889,45 @@ class CagetteMember(models.Model):
res = self.o_api.search_read("shift.registration", c, f)
return res
def unsuscribe_member(self):
res = {}
now = datetime.datetime.now().isoformat()
# Get and then delete shift template registration
c = [['partner_id', '=', self.id]]
f = ['id']
res_ids = self.o_api.search_read("shift.template.registration", c, f)
ids = [d['id'] for d in res_ids]
if ids:
res["delete_shift_template_reg"] = self.o_api.execute('shift.template.registration', 'unlink', ids)
# Get and then delete shift registrations
c = [['partner_id', '=', self.id], ['date_begin', '>', now]]
f = ['id']
res_ids = self.o_api.search_read("shift.registration", c, f)
ids = [d['id'] for d in res_ids]
if ids:
res["delete_shifts_reg"] = self.o_api.execute('shift.registration', 'unlink', ids)
# Close extensions
c = [['partner_id', '=', self.id], ['date_start', '<=', now], ['date_stop', '>=', now]]
f = ['id']
res_ids = self.o_api.search_read("shift.extension", c, f)
ids = [d['id'] for d in res_ids]
if ids:
f = {'date_stop': now}
res["close_extensions"] = self.o_api.update('shift.extension', ids, f)
return res
def set_cooperative_state(self, state):
f = {'cooperative_state': state}
return self.o_api.update('res.partner', [self.id], f)
class CagetteMembers(models.Model):
"""Class to manage operations on all members or part of them."""
......
......@@ -75,12 +75,9 @@
}
/* Actions */
#actions_on_member {
margin: 15px;
}
#remove_shift_template_button {
display: none;
margin: 15px;
}
.checkbox_area {
......
......@@ -15,8 +15,8 @@ var selected_member = null,
function remove_from_shift_template() {
let permanent_unsuscribe = modal.find("#permanent_unsuscribe").prop('checked');
// openModal();
closeModal()
openModal();
let data = {
partner_id: selected_member.id,
shift_template_id: selected_member.shift_template_id[0],
......@@ -31,7 +31,10 @@ function remove_from_shift_template() {
dataType:"json",
traditional: true,
contentType: "application/json; charset=utf-8",
success: function(data) {
success: function() {
selected_member.shift_template_id = null;
selected_member.cooperative_state = (permanent_unsuscribe === true) ? "gone" : "unsubscribed";
display_member_info();
closeModal();
},
error: function() {
......@@ -42,7 +45,7 @@ function remove_from_shift_template() {
report_JS_error(err, 'members.admin');
closeModal();
$.notify("Erreur lors de la suppression du membre du créneau.", {
$.notify("Une erreur est survenue lors du processus de suppression du membre du créneau.", {
globalPosition:"top right",
className: "error"
});
......@@ -55,17 +58,15 @@ function remove_from_shift_template() {
*/
function display_member_info() {
$('.member_name').text(`${selected_member.barcode_base} - ${selected_member.name}`);
$('.member_shift').text(selected_member.shift_template_id[1]);
$('.member_status').text(possible_cooperative_state[selected_member.cooperative_state]);
$('.member_makeups').text(selected_member.makeups_to_do);
$('#search_member_input').val();
$('#partner_data_area').css('display', 'flex');
if (selected_member.shift_template_id === undefined || selected_member.shift_template_id === null) {
$("#remove_shift_template_button").hide();
$("#remove_shift_template_button").off();
} else {
$('.member_shift').text(selected_member.shift_template_id[1]);
$("#remove_shift_template_button").show();
$("#remove_shift_template_button").off();
$("#remove_shift_template_button").on("click", () => {
......@@ -80,6 +81,9 @@ function display_member_info() {
);
});
}
$('#search_member_input').val();
$('#partner_data_area').css('display', 'flex');
}
/**
......
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