Bugfixing Cronjob ohne try
This commit is contained in:
parent
2851cc8807
commit
6d89d5f40d
130
users/views.py
130
users/views.py
|
|
@ -1415,6 +1415,7 @@ class landingPage(TemplateView):
|
|||
'''
|
||||
def absencecheck(user, daytocheck):
|
||||
returnstat = False
|
||||
print("ABSENCECHECK")
|
||||
absencedays = Absence.objects.filter(agency=user.profile.agency, user=user, confirm_status=0) & (Absence.objects.filter(agency=user.profile.agency, user=user, start=daytocheck) | (Absence.objects.filter(agency=user.profile.agency, user=user, start__lt=daytocheck) & Absence.objects.filter(agency=user.profile.agency, user=user, end__gt=daytocheck)) | Absence.objects.filter(agency=user.profile.agency, user=user, end=daytocheck))
|
||||
if(len(absencedays) > 0):
|
||||
returnstat = True
|
||||
|
|
@ -1432,81 +1433,84 @@ def cronactionsdaily(request, code):
|
|||
today = date.today()
|
||||
for user in allusers:
|
||||
# REST URLAUB BERECHNUNG
|
||||
try:
|
||||
usertimedata = UserTime.objects.get(user=user)
|
||||
day_tocheck = usertimedata.loose_holidedate.split(".")[0]
|
||||
month_tocheck = usertimedata.loose_holidedate.split(".")[1]
|
||||
month = today.month
|
||||
#try:
|
||||
usertimedata = UserTime.objects.get(user=user)
|
||||
day_tocheck = usertimedata.loose_holidedate.split(".")[0]
|
||||
month_tocheck = usertimedata.loose_holidedate.split(".")[1]
|
||||
month = today.month
|
||||
day = today.day
|
||||
if month < 10:
|
||||
month = "0" + str(month)
|
||||
day = today.day
|
||||
if month < 10:
|
||||
month = "0" + str(month)
|
||||
day = today.day
|
||||
else:
|
||||
month = month
|
||||
else:
|
||||
month = month
|
||||
|
||||
if day < 10:
|
||||
day = "0" + str(day)
|
||||
else:
|
||||
day = day
|
||||
# Restetag erreicht, Reste ins nächste Jahr übertragen
|
||||
if(str(day_tocheck) == str(day) and str(month_tocheck) == str(month)):
|
||||
sourceyear = today.year
|
||||
this_year = list(UserYearAbsenceInfo.objects.filter(year=sourceyear, user=user))[0]
|
||||
next_year = list(UserYearAbsenceInfo.objects.filter(year=sourceyear+1, user=user))[0]
|
||||
next_year.restdays = this_year.days - this_year.days_inuse
|
||||
next_year.save()
|
||||
if day < 10:
|
||||
day = "0" + str(day)
|
||||
else:
|
||||
day = day
|
||||
|
||||
if(user.usertime.usetime):
|
||||
workdays = Workday.objects.filter(user=user, end=None)
|
||||
for wd in workdays:
|
||||
wd.end = datetime(wd.start.year, wd.start.month, wd.start.day, 23, 59)
|
||||
wd.save()
|
||||
# Restetag erreicht, Reste ins nächste Jahr übertragen
|
||||
if(str(day_tocheck) == str(day) and str(month_tocheck) == str(month)):
|
||||
sourceyear = today.year
|
||||
this_year = list(UserYearAbsenceInfo.objects.filter(year=sourceyear, user=user))[0]
|
||||
next_year = list(UserYearAbsenceInfo.objects.filter(year=sourceyear+1, user=user))[0]
|
||||
next_year.restdays = this_year.days - this_year.days_inuse
|
||||
next_year.save()
|
||||
|
||||
yesterday = date.today() - timedelta(days=1)
|
||||
weekday = yesterday.weekday()
|
||||
workdays_yesterday = len(Workday.objects.filter(user=user, start__day=yesterday.day, start__month=yesterday.month, start__year=yesterday.year))
|
||||
if(user.usertime.usetime):
|
||||
workdays = Workday.objects.filter(user=user, end=None)
|
||||
for wd in workdays:
|
||||
wd.end = datetime(wd.start.year, wd.start.month, wd.start.day, 23, 59)
|
||||
wd.save()
|
||||
|
||||
targettworktime = 0.0
|
||||
# Mitarbeiter hat für den gestrigen Tag keine Zeiten erfasst, daher automatisch auf null wenn KEINE Abwesenheit eingetragen wurde
|
||||
if(weekday == 0):
|
||||
targettworktime = user.usertime.wd_mo
|
||||
if(weekday == 1):
|
||||
targettworktime = user.usertime.wd_tu
|
||||
if(weekday == 2):
|
||||
targettworktime = user.usertime.wd_we
|
||||
if(weekday == 3):
|
||||
targettworktime = user.usertime.wd_th
|
||||
if(weekday == 4):
|
||||
targettworktime = user.usertime.wd_fr
|
||||
if(weekday == 5):
|
||||
targettworktime = user.usertime.wd_sa
|
||||
if(weekday == 6):
|
||||
targettworktime = user.usertime.wd_so
|
||||
yesterday = date.today() - timedelta(days=1)
|
||||
weekday = yesterday.weekday()
|
||||
|
||||
# Es wird nur ein Arbeitstag erstellt, wenn KEINE Abwesenheiten vorliegen und der Nutzer an diesem Tag arbeiten muss
|
||||
if(workdays_yesterday == 0 and absencecheck(user, yesterday) == False and targettworktime > 0.0 and user.usertime.usetime_start <= today):
|
||||
workdaytemp = Workday(user=user, agency=user.profile.agency, start=datetime(yesterday.year, yesterday.month, yesterday.day, 8, 0), end=datetime(yesterday.year, yesterday.month, yesterday.day, 8, 0), target=targettworktime)
|
||||
workdaytemp.save()
|
||||
workdays_yesterday = len(Workday.objects.filter(user=user, start__day=yesterday.day, start__month=yesterday.month, start__year=yesterday.year))
|
||||
|
||||
targettworktime = 0.0
|
||||
# Mitarbeiter hat für den gestrigen Tag keine Zeiten erfasst, daher automatisch auf null wenn KEINE Abwesenheit eingetragen wurde
|
||||
if(weekday == 0):
|
||||
targettworktime = user.usertime.wd_mo
|
||||
if(weekday == 1):
|
||||
targettworktime = user.usertime.wd_tu
|
||||
if(weekday == 2):
|
||||
targettworktime = user.usertime.wd_we
|
||||
if(weekday == 3):
|
||||
targettworktime = user.usertime.wd_th
|
||||
if(weekday == 4):
|
||||
targettworktime = user.usertime.wd_fr
|
||||
if(weekday == 5):
|
||||
targettworktime = user.usertime.wd_sa
|
||||
if(weekday == 6):
|
||||
targettworktime = user.usertime.wd_so
|
||||
|
||||
# Es wird nur ein Arbeitstag erstellt, wenn KEINE Abwesenheiten vorliegen und der Nutzer an diesem Tag arbeiten muss
|
||||
if(workdays_yesterday == 0 and absencecheck(user, yesterday) == False and targettworktime > 0.0 and user.usertime.usetime_start <= today):
|
||||
workdaytemp = Workday(user=user, agency=user.profile.agency, start=datetime(yesterday.year, yesterday.month, yesterday.day, 8, 0), end=datetime(yesterday.year, yesterday.month, yesterday.day, 8, 0), target=targettworktime)
|
||||
workdaytemp.save()
|
||||
|
||||
|
||||
# Erinnerungsmails/Push bei Vertretung verschicken
|
||||
one_week_later = date.today() + timedelta(days=7)
|
||||
repre_absence = Absence.objects.filter(representator=user, start=one_week_later, confirm_status=0)
|
||||
# Erinnerungsmails/Push bei Vertretung verschicken
|
||||
one_week_later = date.today() + timedelta(days=7)
|
||||
|
||||
for r in repre_absence:
|
||||
if(r.representator.usernotifications.absence_user_is_rep_reminder_mail):
|
||||
sendMailNoti(" in einer Woche startet Ihre Vertretung für " + r.user.first_name + " " + r.user.last_name + "!", user)
|
||||
repre_absence = Absence.objects.filter(representator=user, start=one_week_later, confirm_status=0)
|
||||
|
||||
if(r.representator.usernotifications.absence_user_is_rep_reminder_push):
|
||||
newnotification = UserNotification(touser=user, notificationtext="Erinnerung für Abwesenheitsvertretung!", notificationtype="", elementid=r.pk)
|
||||
newnotification.save()
|
||||
for r in repre_absence:
|
||||
if(r.representator.usernotifications.absence_user_is_rep_reminder_mail):
|
||||
sendMailNoti(" in einer Woche startet Ihre Vertretung für " + r.user.first_name + " " + r.user.last_name + "!", user)
|
||||
|
||||
channel_layer = channels.layers.get_channel_layer()
|
||||
async_to_sync(channel_layer.group_send)("user_" + str(user.pk), {'type' : 'pushhandler', 'pushtext' : "pushnotification__Abwesenheit | In einer Woche startet Ihre Vertretung für " + r.user.first_name + " " + r.user.last_name + "!"})
|
||||
if(r.representator.usernotifications.absence_user_is_rep_reminder_push):
|
||||
newnotification = UserNotification(touser=user, notificationtext="Erinnerung für Abwesenheitsvertretung!", notificationtype="", elementid=r.pk)
|
||||
newnotification.save()
|
||||
|
||||
data.update({"status " + str(user.pk) : "ok"})
|
||||
except ObjectDoesNotExist:
|
||||
data.update({"status" + str(user.pk) : "no usertime found for " + user.get_full_name()})
|
||||
channel_layer = channels.layers.get_channel_layer()
|
||||
async_to_sync(channel_layer.group_send)("user_" + str(user.pk), {'type' : 'pushhandler', 'pushtext' : "pushnotification__Abwesenheit | In einer Woche startet Ihre Vertretung für " + r.user.first_name + " " + r.user.last_name + "!"})
|
||||
|
||||
data.update({"status " + str(user.pk) : "ok"})
|
||||
#except ObjectDoesNotExist:
|
||||
# data.update({"status" + str(user.pk) : "no usertime found for " + user.get_full_name()})
|
||||
else:
|
||||
print("API CODE FAILED")
|
||||
data.update({"status" : "failed"})
|
||||
|
|
|
|||
Loading…
Reference in New Issue