Commit e43ee267 by Damien Moulard

Merge branch 'evolution_bdm' of…

Merge branch 'evolution_bdm' of gl.cooperatic.fr:cooperatic-foodcoops/third-party into evolution_bdm
parents efa1ddd9 225b0401
......@@ -1131,24 +1131,26 @@ class CagetteServices(models.Model):
def get_services_at_time(time, tz_offset, with_members=True):
"""Retrieve present services with member linked."""
# import operator
min_before_shift_starts_delay = 20
min_after_shift_starts_delay = 20
default_acceptable_minutes_after_shift_begins = getattr(settings, 'ACCEPTABLE_ENTRANCE_MINUTES_AFTER_SHIFT_BEGINS', 15)
minutes_before_shift_starts_delay = getattr(settings, 'ACCEPTABLE_ENTRANCE_MINUTES_BEFORE_SHIFT', 15)
minutes_after_shift_starts_delay = default_acceptable_minutes_after_shift_begins
late_mode = getattr(settings, 'ENTRANCE_WITH_LATE_MODE', False)
max_duration = getattr(settings, 'MAX_DURATION', 180)
if late_mode is True:
min_before_shift_starts_delay = getattr(settings, 'ENTRANCE_VALIDATION_GRACE_DELAY', 60)
min_after_shift_starts_delay = 0
minutes_after_shift_starts_delay = getattr(settings, 'ENTRANCE_VALIDATION_GRACE_DELAY', 60)
api = OdooAPI()
now = dateutil.parser.parse(time) - datetime.timedelta(minutes=tz_offset)
start1 = now - datetime.timedelta(minutes=min_before_shift_starts_delay)
start2 = now + datetime.timedelta(minutes=min_after_shift_starts_delay)
cond = [['date_begin_tz', '>=', start1.isoformat()],
['date_begin_tz', '<=', start2.isoformat()]]
start1 = now + datetime.timedelta(minutes=minutes_before_shift_starts_delay)
start2 = now - datetime.timedelta(minutes=minutes_after_shift_starts_delay)
end = start1 + datetime.timedelta(minutes=max_duration)
cond = [['date_end_tz', '<=', end.isoformat()]]
cond.append('|')
cond.append(['date_begin_tz', '>=', start1.isoformat()])
cond.append(['date_begin_tz', '>=', start2.isoformat()])
fields = ['name', 'week_number', 'registration_ids',
'standard_registration_ids',
'shift_template_id', 'shift_ticket_ids',
'date_begin_tz', 'date_end_tz']
## return (start1.isoformat(), start2.isoformat())
services = api.search_read('shift.shift', cond, fields,order ="date_begin_tz ASC")
for s in services:
if (len(s['registration_ids']) > 0):
......@@ -1157,7 +1159,7 @@ class CagetteServices(models.Model):
now.replace(tzinfo=None)
-
dateutil.parser.parse(s['date_begin_tz']).replace(tzinfo=None)
).seconds / 60 > min_after_shift_starts_delay
).total_seconds() / 60 > default_acceptable_minutes_after_shift_begins
if with_members is True:
cond = [['id', 'in', s['registration_ids']], ['state', '!=', 'cancel']]
fields = ['partner_id', 'shift_type', 'state']
......@@ -1225,14 +1227,17 @@ class CagetteServices(models.Model):
return api.update('shift.registration', [int(reg_id)], f)
@staticmethod
def record_absences():
def record_absences(date):
"""Called by cron script."""
import dateutil.parser
now = datetime.datetime.now()
if len(date) > 0:
now = dateutil.parser.parse(date)
else:
now = datetime.datetime.now()
# now = dateutil.parser.parse('2020-09-15T15:00:00Z')
date_24h_before = now - datetime.timedelta(hours=24)
# let authorized people time to set presence for those who came in late
end_date = now - datetime.timedelta(hours=3)
end_date = now - datetime.timedelta(hours=2)
api = OdooAPI()
absence_status = 'excused'
res_c = api.search_read('ir.config_parameter',
......@@ -1264,7 +1269,10 @@ class CagetteServices(models.Model):
if int(_h) < 21:
ids.append(int(r['id']))
f = {'state': absence_status}
return {'update': api.update('shift.registration', ids, f), 'reg_shift': res}
update_shift_reg_result = {'update': api.update('shift.registration', ids, f), 'reg_shift': res}
if update_shift_reg_result['update'] is True:
update_shift_reg_result['process_status_res'] = api.execute('res.partner','run_process_target_status', [])
return update_shift_reg_result
@staticmethod
def close_ftop_service():
......
......@@ -40,7 +40,7 @@ urlpatterns = [
url(r'^save_photo/([0-9]+)$', views.save_photo, name='save_photo'),
url(r'^services_at_time/([0-9TZ\-\: \.]+)/([0-9\-]+)$', views.services_at_time),
url(r'^service_presence/$', views.record_service_presence),
url(r'^record_absences$', views.record_absences),
url(r'^record_absences/?([0-9\-\ \:]*)$', views.record_absences),
url(r'^close_ftop_service$', views.close_ftop_service),
url(r'^get_credentials$', views.get_credentials),
url(r'^remove_data_from_couchdb$', views.remove_data_from_CouchDB),
......
......@@ -281,7 +281,8 @@ def record_service_presence(request):
import re
o_date = re.search(r'/([^\/]+?)$', request.META.get('HTTP_REFERER'))
if o_date:
overrided_date = o_date.group(1)
overrided_date = re.sub(r'(%20)',' ', o_date.group(1))
# rid = 0 => C'est un rattrapage, sur le service
if sid > 0 and stid > 0:
# Add member to service and take presence into account
......@@ -289,7 +290,6 @@ def record_service_presence(request):
if res['rattrapage'] is True:
res['update'] = 'ok'
else:
if (CagetteServices.registration_done(rid, overrided_date) is True):
res['update'] = 'ok'
else:
......@@ -325,8 +325,8 @@ def easy_validate_shift_presence(request):
else:
return JsonResponse(res, safe=False)
def record_absences(request):
return JsonResponse({'res': CagetteServices.record_absences()})
def record_absences(request, date):
return JsonResponse({'res': CagetteServices.record_absences(date)})
def close_ftop_service(request):
"""Close the closest past FTOP service"""
......
......@@ -89,6 +89,15 @@ class CagetteShift(models.Model):
shiftData = self.o_api.search_read('shift.registration', cond, fields, order ="date_begin ASC")
return shiftData
def shift_is_makeup(self, id):
"""vérifie si une shift est un rattrapage"""
fields = ["is_makeup", "id"]
cond = [['id', '=', id]]
shiftData = self.o_api.search_read('shift.registration', cond, fields)
return shiftData[0]["is_makeup"]
def get_shift_calendar(self, id, start, end):
"""Récupère les shifts à partir de maintenant pour le calendier"""
cond = [['date_begin', '>', datetime.datetime.now().isoformat()],
......@@ -144,6 +153,7 @@ class CagetteShift(models.Model):
"shift_ticket_id": self.get_shift_ticket(data['idShift'], data['in_ftop_team']),
"shift_type": shift_type,
"origin": 'memberspace',
"is_makeup": data['is_makeup'],
"state": 'open'}
st_r_id = self.o_api.create('shift.registration', fieldsDatas)
......
......@@ -178,12 +178,15 @@ def change_shift(request):
if 'idNewShift' in request.POST and 'idOldShift' in request.POST:
idOldShift = request.POST['idOldShift']
listRegister = [int(request.POST['idRegister'])]
data = {
"idPartner": int(request.POST['idPartner']),
"idShift":int(request.POST['idNewShift']),
"in_ftop_team":request.POST['in_ftop_team']
"in_ftop_team":request.POST['in_ftop_team'],
"is_makeup":cs.shift_is_makeup(listRegister)
}
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
......@@ -228,7 +231,8 @@ def add_shift(request):
data = {
"idPartner": int(request.POST['idPartner']),
"idShift":int(request.POST['idNewShift']),
"in_ftop_team":request.POST['in_ftop_team']
"in_ftop_team":request.POST['in_ftop_team'],
"is_makeup":True
}
#Insertion du nouveau shift
......
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