Commit 33e5c6d2 by Damien Moulard

create a 6 month delay when suspended

parent 23dc1296
......@@ -72,4 +72,10 @@ table.dataTable.display tbody tr.row_partner_late {
}
table.dataTable.display tbody tr.row_partner_absent {
background-color: #ff847b;
}
table.dataTable.display tbody tr.row_partner_ok td,
table.dataTable.display tbody tr.row_partner_late td,
table.dataTable.display tbody tr.row_partner_absent td {
border-bottom: 1px solid rgb(100, 99, 99);
border-top: 1px solid rgb(100, 99, 99);
}
\ No newline at end of file
......@@ -13,15 +13,23 @@ function toggleHeader() {
$(document).ready(function() {
// Navbar redirections
$('#nav_home').on('click', function() {
goto('home');
if (current_location !== "home") {
goto('home');
}
});
$('#nav_my_info').on('click', function() {
goto('mes-infos');
if (current_location !== "my_info") {
goto('mes-infos');
}
});
$('#nav_my_shifts').on('click', function() {
goto('mes-services');
if (current_location !== "my_shifts") {
goto('mes-services');
}
});
$('#nav_shifts_exchange').on('click', function() {
goto('echange-de-services');
if (current_location !== "shifts_exchange") {
goto('echange-de-services');
}
});
});
......@@ -7,6 +7,51 @@ const possible_cooperative_state = {
delay: "En délai"
}
/**
* Request a 6 month delay
*/
function request_delay() {
return new Promise((resolve) => {
let today = new Date();
const delay_start = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();
let today_plus_six_month = new Date();
today_plus_six_month.setMonth(today_plus_six_month.getMonth()+6);
const diff_time = Math.abs(today_plus_six_month - today);
const diff_days = Math.ceil(diff_time / (1000 * 60 * 60 * 24));
$.ajax({
type: 'POST',
url: "/shifts/request_delay",
dataType:"json",
data: {
verif_token: partner_data.verif_token,
idPartner: partner_data.partner_id,
start_date: delay_start,
duration: diff_days
},
success: function() {
partner_data.cooperative_state = 'delay';
partner_data.date_delay_stop = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();
resolve();
},
error: function(data) {
err = {msg: "erreur serveur lors de la création du délai", ctx: 'request_delay'};
if (typeof data.responseJSON != 'undefined' && typeof data.responseJSON.error != 'undefined') {
err.msg += ' : ' + data.responseJSON.error;
}
report_JS_error(err, 'members_space.home');
closeModal();
// TODO Notify
alert('Erreur lors de la création du délai.');
}
});
});
}
function init_my_shifts_tile() {
if (incoming_shifts.length === 0) {
$("#home_tile_my_services #home_incoming_services").text("Aucun service à venir...")
......@@ -28,6 +73,8 @@ function init_my_shifts_tile() {
}
function init_my_info_tile() {
$("#home_choose_makeups").off();
// Status related
$("#home_tile_my_info #home_member_status")
.text(possible_cooperative_state[partner_data.cooperative_state])
......@@ -43,9 +90,11 @@ function init_my_info_tile() {
// If the member is suspended & doesn't have a delay
$("#home_choose_makeups").on('click', () => {
// Create 6 month delay
// Then redirect to calendar
goto('echange-de-services');
request_delay()
.then(() => {
// Then redirect to calendar
goto('echange-de-services');
})
});
} else {
$("#home_choose_makeups").on('click', () => {
......@@ -53,7 +102,6 @@ function init_my_info_tile() {
});
}
}
// date_delay_stop : if exists: 2021-09-22 ; else: False
$("#home_tile_my_info #home_member_shift_name").text(partner_data.regular_shift_name);
......
......@@ -173,21 +173,23 @@ class CagetteShift(models.Model):
coop_logger.error("Reopen shift : %s", str(e))
return response
def create_delay(self, data):
"""Create a delay for a member.
A delay is 28 days from the given start_date.
def create_delay(self, data, duration=28):
"""
Create a delay for a member.
If no duration is specified, a delay is by default 28 days from the given start_date.
If the partner already has a current extension: extend it by 28 days.
If the partner already has a current extension: extend it by [duration] days.
Else, create a 28 days delay.
Args:
idPartner: int
start_date: string date at iso format (eg. "2019-11-19")
Date from which the 28 days delay is calculated
Date from which the delay end date is calculated
(optionnal) extension_beginning: string date at iso format
If specified, will be the actual starting date of the extension.
Should be inferior than start_date.
(at creation only: odoo ignores delays if today's not inside)
duration: nb of days
"""
action = 'create'
......@@ -218,7 +220,7 @@ class CagetteShift(models.Model):
# Update current extension
if action == 'update':
ext_date_stop = datetime.datetime.strptime(extension['date_stop'], '%Y-%m-%d').date()
ext_new_date_stop = (ext_date_stop + datetime.timedelta(days=28))
ext_new_date_stop = (ext_date_stop + datetime.timedelta(days=duration))
update_data = {
'date_stop': ext_new_date_stop.isoformat()
......@@ -235,12 +237,11 @@ class CagetteShift(models.Model):
ext_type_id = val['id']
starting_date = datetime.datetime.strptime(data['start_date'], '%Y-%m-%d').date()
ending_date = (starting_date + datetime.timedelta(days=28))
ending_date = (starting_date + datetime.timedelta(days=duration))
if 'extension_beginning' in data:
starting_date = datetime.datetime.strptime(data['extension_beginning'], '%Y-%m-%d').date()
#TODO : bloquer si nextmonth > date_end_alert+5months ? (blocage js)
fields= {
"partner_id": data['idPartner'],
"type_id": ext_type_id,
......
......@@ -231,6 +231,7 @@ def add_shift(request):
def request_delay(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()
data = {
"idPartner": int(request.POST['idPartner']),
......@@ -239,10 +240,15 @@ def request_delay(request):
if ('extension_beginning' in request.POST):
data['extension_beginning'] = request.POST['extension_beginning']
if ('duration' in request.POST):
duration = int(request.POST['duration'])
else:
duration = None
response = {'result': False}
try:
new_id = cs.create_delay(data)
new_id = cs.create_delay(data, duration)
if (new_id):
response = {'result': True}
else:
......
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