Commit 333f6a82 by Damien Moulard

block service exchange if service in less than 24h (configurable)

parent 32fe6120
Pipeline #1190 passed with stage
in 1 minute 24 seconds
......@@ -108,3 +108,6 @@ RECEPTION_PB = "Ici, vous pouvez signaler toute anomalie lors d'une réception,
# display or not column "Autres" in reception process
DISPLAY_COL_AUTRES = False
# Should block service exchange if old service is happening in less than 24h
BLOCK_SERVICE_EXCHANGE_24H_BEFORE = True
......@@ -92,3 +92,6 @@ ENTRANCE_FTOP_BUTTON_DISPLAY = False
CUSTOM_CSS_FILES = {'all': ['common_lgds.css'],
'members': ['inscription_lgds.css','member_lgds.css']}
# Should block service exchange if old service is happening in less than 24h
BLOCK_SERVICE_EXCHANGE_24H_BEFORE = False
\ No newline at end of file
......@@ -88,3 +88,6 @@ PROMOTE_SHELFS_IDS = []
DISCOUNT_SHELFS_IDS = []
FL_SHELFS = []
VRAC_SHELFS = []
# Should block service exchange if old service is happening in less than 24h
BLOCK_SERVICE_EXCHANGE_24H_BEFORE = False
\ No newline at end of file
......@@ -17,6 +17,19 @@ class CagetteShift(models.Model):
self.tz = pytz.timezone("Europe/Paris")
self.o_api = OdooAPI()
def get_shift(self, id):
"""Get one shift by id"""
cond = [['id', '=', id]]
fields = ['date_begin_tz']
listService = self.o_api.search_read('shift.shift', cond, fields)
try:
return listService[0]
except Exception as e:
print(str(e))
return None
def get_data_partner(self, id):
"""Retrieve partner data useful to make decision about shift options"""
cond = [['id', '=', id]]
......
......@@ -133,9 +133,15 @@ function changeShift(idOldRegister, idNewShift) {
);
}
},
error: function() {
error: function(error) {
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.');
if (error.status === 400) {
alert(`Désolé ! Le service que vous souhaitez échanger démarre dans moins de 24h. Il n'est plus possible de l'échanger.`)
} else {
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.');
}
// Refectch shifts anyway:
// in case an error rises but the registration/exchange was still succesful
setTimeout( // Due to chrome effect
......
from outils.common_imports import *
from outils.for_view_imports import *
from shifts.models import CagetteShift
from outils.common import Verification
from shifts.models import CagetteShift
# working_state = ['up_to_date', 'alert', 'exempted', 'delay', 'suspended']
state_shift_allowed = ["up_to_date", "alert", "delay"]
tz = pytz.timezone("Europe/Paris")
def dateIsoUTC(myDate):
tDate = tz.localize(datetime.datetime.strptime(myDate, '%Y-%m-%d %H:%M:%S'))
return tDate.isoformat()
def home(request, partner_id, hashed_date):
import hashlib
cs = CagetteShift()
......@@ -170,7 +161,24 @@ def change_shift(request):
if 'idNewShift' in request.POST and 'idOldShift' in request.POST:
idOldShift = request.POST['idOldShift']
data = {"idPartner": int(request.POST['idPartner']), "idShift":int(request.POST['idNewShift']), "in_ftop_team":request.POST['in_ftop_team']}
data = {
"idPartner": int(request.POST['idPartner']),
"idShift":int(request.POST['idNewShift']),
"in_ftop_team":request.POST['in_ftop_team']
}
should_block_service_exchange = getattr(settings, 'BLOCK_SERVICE_EXCHANGE_24H_BEFORE', False)
if should_block_service_exchange:
# Block change if old shift is to happen in less than 24 hours
now = datetime.datetime.now(tz)
old_shift = cs.get_shift(idOldShift)
day_before_old_shift_date_start = tz.localize(datetime.datetime.strptime(old_shift['date_begin_tz'], '%Y-%m-%d %H:%M:%S') - datetime.timedelta(hours=24))
if now > day_before_old_shift_date_start:
response = {'msg': "Old service in less than 24hours."}
return JsonResponse(response, status=400)
st_r_id = False
#Insertion du nouveau shift
try:
......@@ -179,7 +187,8 @@ def change_shift(request):
coop_logger.error("Change shift : %s, %s", str(e), str(data))
if st_r_id:
listRegister = [int(request.POST['idRegister'])]
# Annul l'ancien shift
# Annule l'ancien shift
response = cs.cancel_shift(listRegister)
response = {'result': True}
......
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