[ADD]Translations

This commit is contained in:
NIKHIL RAVI
2023-07-26 12:15:01 +05:30
parent 1135f6f66b
commit d1b170f203
24 changed files with 2430 additions and 1266 deletions

View File

@@ -4,11 +4,12 @@ import calendar
from notifications.signals import notify
def update_rotating_work_type_assign(rotating_work_type,new_date):
def update_rotating_work_type_assign(rotating_work_type, new_date):
"""
Here will update the employee work information details and send notification
"""
from django.contrib.auth.models import User
employee = rotating_work_type.employee_id
employee_work_info = employee.employee_work_info
work_type1 = rotating_work_type.rotating_work_type_id.work_type1
@@ -26,19 +27,30 @@ def update_rotating_work_type_assign(rotating_work_type,new_date):
bot = User.objects.filter(username="Horilla Bot").first()
if bot is not None:
employee = rotating_work_type.employee_id
notify.send(bot,recipient=employee.employee_user_id,verb="Your Work Type has been changed.",icon="infinite",redirect="/employee/employee-profile")
notify.send(
bot,
recipient=employee.employee_user_id,
verb="Your Work Type has been changed.",
verb_ar="لقد تغير نوع عملك.",
verb_de="Ihre Art der Arbeit hat sich geändert.",
verb_es="Su tipo de trabajo ha sido cambiado.",
verb_fr="Votre type de travail a été modifié.",
icon="infinite",
redirect="/employee/employee-profile",
)
return
def work_type_rotate_after(rotating_work_work_type):
"""
This method for rotate work type based on after day
"""
date_today = datetime.now()
date_today = datetime.now()
switch_date = rotating_work_work_type.next_change_date
if switch_date.strftime('%Y-%m-%d') == date_today.strftime('%Y-%m-%d'):
if switch_date.strftime("%Y-%m-%d") == date_today.strftime("%Y-%m-%d"):
# calculate the next work type switch date
new_date = date_today + timedelta(days=rotating_work_work_type.rotate_after_day)
update_rotating_work_type_assign(rotating_work_work_type,new_date)
update_rotating_work_type_assign(rotating_work_work_type, new_date)
return
@@ -46,36 +58,38 @@ def work_type_rotate_weekend(rotating_work_type):
"""
This method for rotate work type based on weekend
"""
date_today = datetime.now()
date_today = datetime.now()
switch_date = rotating_work_type.next_change_date
if switch_date.strftime('%Y-%m-%d') == date_today.strftime('%Y-%m-%d'):
if switch_date.strftime("%Y-%m-%d") == date_today.strftime("%Y-%m-%d"):
# calculate the next work type switch date
day = datetime.now().strftime('%A').lower()
day = datetime.now().strftime("%A").lower()
switch_day = rotating_work_type.rotate_every_weekend
if day == switch_day:
new_date = date_today + timedelta(days=7)
update_rotating_work_type_assign(rotating_work_type,new_date)
update_rotating_work_type_assign(rotating_work_type, new_date)
return
def work_type_rotate_every(rotating_work_type):
"""
"""
This method for rotate work type based on every month
"""
date_today = datetime.now()
switch_date = rotating_work_type.next_change_date
day_date = rotating_work_type.rotate_every
if switch_date.strftime('%Y-%m-%d') == date_today.strftime('%Y-%m-%d'):
if switch_date.strftime("%Y-%m-%d") == date_today.strftime("%Y-%m-%d"):
# calculate the next work type switch date
if day_date == switch_date.strftime('%d').lstrip('0'):
if day_date == switch_date.strftime("%d").lstrip("0"):
new_date = date_today.replace(month=date_today.month + 1)
update_rotating_work_type_assign(rotating_work_type, new_date)
elif day_date == 'last':
year = date_today.strftime('%Y')
month = date_today.strftime('%m')
elif day_date == "last":
year = date_today.strftime("%Y")
month = date_today.strftime("%m")
last_day = calendar.monthrange(int(year), int(month) + 1)[1]
new_date = datetime(int(year), int(month) + 1, last_day)
update_rotating_work_type_assign(rotating_work_type, new_date)
return
return
def rotate_work_type():
"""
@@ -83,24 +97,25 @@ def rotate_work_type():
and redirect to the chunk method to execute.
"""
from base.models import RotatingWorkTypeAssign
rotating_work_types = RotatingWorkTypeAssign.objects.filter(is_active=True)
for rotating_work_type in rotating_work_types:
based_on = rotating_work_type.based_on
if based_on =='after':
if based_on == "after":
work_type_rotate_after(rotating_work_type)
elif based_on == 'weekly':
elif based_on == "weekly":
work_type_rotate_weekend(rotating_work_type)
elif based_on == 'monthly':
elif based_on == "monthly":
work_type_rotate_every(rotating_work_type)
return
def update_rotating_shift_assign(rotating_shift,new_date):
def update_rotating_shift_assign(rotating_shift, new_date):
"""
Here will update the employee work information and send notification
Here will update the employee work information and send notification
"""
from django.contrib.auth.models import User
employee = rotating_shift.employee_id
employee_work_info = employee.employee_work_info
shift1 = rotating_shift.rotating_shift_id.shift1
@@ -115,59 +130,72 @@ def update_rotating_shift_assign(rotating_shift,new_date):
rotating_shift.current_shift = new
rotating_shift.next_shift = next
rotating_shift.save()
bot = User.objects.filter(username='Horilla Bot').first()
bot = User.objects.filter(username="Horilla Bot").first()
if bot is not None:
employee = rotating_shift.employee_id
notify.send(bot,recipient=employee.employee_user_id,verb="Your shift has been changed.",icon="infinite",redirect="/employee/employee-profile")
notify.send(
bot,
recipient=employee.employee_user_id,
verb="Your shift has been changed.",
verb_ar="تم تغيير التحول الخاص بك.",
verb_de="Ihre Schicht wurde geändert.",
verb_es="Tu turno ha sido cambiado.",
verb_fr="Votre quart de travail a été modifié.",
icon="infinite",
redirect="/employee/employee-profile",
)
return
def shift_rotate_after_day(rotating_shift):
"""
This method for rotate shift based on after day
"""
date_today = datetime.now()
date_today = datetime.now()
switch_date = rotating_shift.next_change_date
if switch_date.strftime('%Y-%m-%d') == date_today.strftime('%Y-%m-%d'):
if switch_date.strftime("%Y-%m-%d") == date_today.strftime("%Y-%m-%d"):
# calculate the next work type switch date
new_date = date_today + timedelta(days=rotating_shift.rotate_after_day)
update_rotating_shift_assign(rotating_shift,new_date)
update_rotating_shift_assign(rotating_shift, new_date)
return
def shift_rotate_weekend(rotating_shift):
"""
This method for rotate shift based on weekend
"""
date_today = datetime.now()
switch_date = rotating_shift.next_change_date
if switch_date.strftime('%Y-%m-%d') == date_today.strftime('%Y-%m-%d'):
date_today = datetime.now()
switch_date = rotating_shift.next_change_date
if switch_date.strftime("%Y-%m-%d") == date_today.strftime("%Y-%m-%d"):
# calculate the next work type switch date
day = datetime.now().strftime('%A').lower()
day = datetime.now().strftime("%A").lower()
switch_day = rotating_shift.rotate_every_weekend
if day == switch_day:
new_date = date_today + timedelta(days=7)
update_rotating_shift_assign(rotating_shift,new_date)
update_rotating_shift_assign(rotating_shift, new_date)
return
def shift_rotate_every(rotating_shift):
"""
"""
This method for rotate shift based on every month
"""
date_today = datetime.now()
switch_date = rotating_shift.next_change_date
day_date = rotating_shift.rotate_every
if switch_date.strftime('%Y-%m-%d') == date_today.strftime('%Y-%m-%d'):
if switch_date.strftime("%Y-%m-%d") == date_today.strftime("%Y-%m-%d"):
# calculate the next work type switch date
if day_date == switch_date.strftime('%d').lstrip('0'):
if day_date == switch_date.strftime("%d").lstrip("0"):
new_date = date_today.replace(month=date_today.month + 1)
update_rotating_shift_assign(rotating_shift, new_date)
elif day_date == 'last':
year = date_today.strftime('%Y')
month = date_today.strftime('%m')
elif day_date == "last":
year = date_today.strftime("%Y")
month = date_today.strftime("%m")
last_day = calendar.monthrange(int(year), int(month) + 1)[1]
new_date = datetime(int(year), int(month) + 1, last_day)
update_rotating_shift_assign(rotating_shift, new_date)
return
return
def rotate_shift():
"""
@@ -175,21 +203,21 @@ def rotate_shift():
and redirect to the chunk method to execute.
"""
from base.models import RotatingShiftAssign
rotating_shifts = RotatingShiftAssign.objects.filter(is_active=True)
for rotating_shift in rotating_shifts:
based_on = rotating_shift.based_on
# after day condition
if based_on =='after':
if based_on == "after":
shift_rotate_after_day(rotating_shift)
# weekly condition
elif based_on == 'weekly':
elif based_on == "weekly":
shift_rotate_weekend(rotating_shift)
# monthly condition
elif based_on == 'monthly':
elif based_on == "monthly":
shift_rotate_every(rotating_shift)
return
def switch_shift():
@@ -199,8 +227,10 @@ def switch_shift():
from base.models import ShiftRequest
from django.contrib.auth.models import User
today =date.today()
shift_requests = ShiftRequest.objects.filter(canceled=False,approved=True,requested_date__exact=today,shift_changed=False)
today = date.today()
shift_requests = ShiftRequest.objects.filter(
canceled=False, approved=True, requested_date__exact=today, shift_changed=False
)
for request in shift_requests:
work_info = request.employee_id.employee_work_info
# updating requested shift to the employee work information.
@@ -209,12 +239,23 @@ def switch_shift():
request.approved = True
request.shift_changed = True
request.save()
bot = User.objects.filter(username='Horilla Bot').first()
bot = User.objects.filter(username="Horilla Bot").first()
if bot is not None:
employee = request.employee_id
notify.send(bot,recipient=employee.employee_user_id,verb="Shift Changes notification",icon="refresh",redirect="/employee/employee-profile")
notify.send(
bot,
recipient=employee.employee_user_id,
verb="Shift Changes notification",
verb_ar="التحول تغيير الإخطار",
verb_de="Benachrichtigung über Schichtänderungen",
verb_es="Notificación de cambios de turno",
verb_fr="Notification des changements de quart de travail",
icon="refresh",
redirect="/employee/employee-profile",
)
return
def undo_shift():
"""
This method undo previous employees shift information regards to the shift request
@@ -222,9 +263,15 @@ def undo_shift():
from base.models import ShiftRequest
from django.contrib.auth.models import User
today =date.today()
today = date.today()
# here will get all the active shift requests
shift_requests = ShiftRequest.objects.filter(canceled=False,approved=True,requested_till__lt=today,is_active=True,shift_changed=True)
shift_requests = ShiftRequest.objects.filter(
canceled=False,
approved=True,
requested_till__lt=today,
is_active=True,
shift_changed=True,
)
for request in shift_requests:
work_info = request.employee_id.employee_work_info
work_info.shift_id = request.previous_shift_id
@@ -232,22 +279,37 @@ def undo_shift():
# making the instance in-active
request.is_active = False
request.save()
bot = User.objects.filter(username='Horilla Bot').first()
bot = User.objects.filter(username="Horilla Bot").first()
if bot is not None:
employee = request.employee_id
notify.send(bot,recipient=employee.employee_user_id,verb="Shift changes notification, Requested date expired.",icon="refresh",redirect="/employee/employee-profile")
notify.send(
bot,
recipient=employee.employee_user_id,
verb="Shift changes notification, Requested date expired.",
verb_ar="التحول يغير الإخطار ، التاريخ المطلوب انتهت صلاحيته.",
verb_de="Benachrichtigung über Schichtänderungen, gewünschtes Datum abgelaufen.",
verb_es="Notificación de cambios de turno, Fecha solicitada vencida.",
verb_fr="Notification de changement d'équipe, la date demandée a expiré.",
icon="refresh",
redirect="/employee/employee-profile",
)
return
def switch_work_type():
"""
This method change employees work type information regards to the work type request
"""
from django.contrib.auth.models import User
from base.models import WorkTypeRequest
today =date.today()
work_type_requests = WorkTypeRequest.objects.filter(canceled=False,approved=True,requested_date__exact=today,work_type_changed=False)
today = date.today()
work_type_requests = WorkTypeRequest.objects.filter(
canceled=False,
approved=True,
requested_date__exact=today,
work_type_changed=False,
)
for request in work_type_requests:
work_info = request.employee_id.employee_work_info
# updating requested work type to the employee work information.
@@ -256,12 +318,23 @@ def switch_work_type():
request.approved = True
request.work_type_changed = True
request.save()
bot = User.objects.filter(username='Horilla Bot').first()
bot = User.objects.filter(username="Horilla Bot").first()
if bot is not None:
employee = request.employee_id
notify.send(bot,recipient=employee.employee_user_id,verb="Work Type Changes notification",icon="swap-horizontal",redirect="/employee/employee-profile")
notify.send(
bot,
recipient=employee.employee_user_id,
verb="Work Type Changes notification",
verb_ar="إخطار تغييرات نوع العمل",
verb_de="Benachrichtigung über Änderungen des Arbeitstyps",
verb_es="Notificación de cambios de tipo de trabajo",
verb_fr="Notification de changement de type de travail",
icon="swap-horizontal",
redirect="/employee/employee-profile",
)
return
def undo_work_type():
"""
This method undo previous employees work type information regards to the work type request
@@ -269,9 +342,15 @@ def undo_work_type():
from base.models import WorkTypeRequest
from django.contrib.auth.models import User
today =date.today()
today = date.today()
# here will get all the active work type requests
work_type_requests = WorkTypeRequest.objects.filter(canceled=False,approved=True,requested_till__lt=today,is_active=True,work_type_changed=True)
work_type_requests = WorkTypeRequest.objects.filter(
canceled=False,
approved=True,
requested_till__lt=today,
is_active=True,
work_type_changed=True,
)
for request in work_type_requests:
work_info = request.employee_id.employee_work_info
# updating employee work information's work type to previous work type
@@ -280,18 +359,28 @@ def undo_work_type():
# making the instance is in-active
request.is_active = False
request.save()
bot = User.objects.filter(username='Horilla Bot').first()
bot = User.objects.filter(username="Horilla Bot").first()
if bot is not None:
employee = request.employee_id
notify.send(bot,recipient=employee.employee_user_id,verb="Work type changes notification, Requested date expired.",icon="swap-horizontal",redirect="/employee/employee-profile")
notify.send(
bot,
recipient=employee.employee_user_id,
verb="Work type changes notification, Requested date expired.",
verb_ar="إعلام بتغيير نوع العمل ، انتهاء صلاحية التاريخ المطلوب.",
verb_de="Benachrichtigung über Änderungen des Arbeitstyps, angefordertes Datum abgelaufen.",
verb_es="Notificación de cambios de tipo de trabajo, fecha solicitada vencida.",
verb_fr="Notification de changement de type de travail, la date demandée a expiré.",
icon="swap-horizontal",
redirect="/employee/employee-profile",
)
return
scheduler = BackgroundScheduler()
scheduler.add_job(rotate_shift, 'interval', seconds=10)
scheduler.add_job(rotate_work_type, 'interval', seconds=10)
scheduler.add_job(switch_shift, 'interval', seconds=10)
scheduler.add_job(undo_shift, 'interval', seconds=10)
scheduler.add_job(switch_work_type, 'interval', seconds=10)
scheduler.add_job(undo_work_type, 'interval', seconds=10)
scheduler.start()
scheduler.add_job(rotate_shift, "interval", seconds=10)
scheduler.add_job(rotate_work_type, "interval", seconds=10)
scheduler.add_job(switch_shift, "interval", seconds=10)
scheduler.add_job(undo_shift, "interval", seconds=10)
scheduler.add_job(switch_work_type, "interval", seconds=10)
scheduler.add_job(undo_work_type, "interval", seconds=10)
scheduler.start()