[UPDT] EMPLOYEE: Leading zeroes on employee badge
This commit is contained in:
@@ -28,6 +28,7 @@ from django.contrib.auth.models import User
|
||||
from django.forms import DateInput, ModelChoiceField, TextInput
|
||||
from django.utils.translation import gettext as _
|
||||
from django.utils.translation import gettext_lazy as trans
|
||||
from horilla.decorators import logger
|
||||
from employee.models import (
|
||||
Actiontype,
|
||||
BonusPoint,
|
||||
@@ -158,26 +159,43 @@ class EmployeeForm(ModelForm):
|
||||
prefix = get_intial_prefix(None)["get_intial_prefix"]
|
||||
data = get_ordered_badge_ids()
|
||||
result = []
|
||||
for sublist in data:
|
||||
for item in sublist:
|
||||
if isinstance(item, str) and item.lower().startswith(prefix.lower()):
|
||||
# Find the index of the item in the sublist
|
||||
index = sublist.index(item)
|
||||
# Check if there is a next item in the sublist
|
||||
if index + 1 < len(sublist):
|
||||
result = sublist[index + 1]
|
||||
result = re.findall(r"[a-zA-Z]+|\d+|[^a-zA-Z\d\s]", result)
|
||||
try:
|
||||
for sublist in data:
|
||||
for item in sublist:
|
||||
if isinstance(item, str) and item.lower().startswith(prefix.lower()):
|
||||
# Find the index of the item in the sublist
|
||||
index = sublist.index(item)
|
||||
# Check if there is a next item in the sublist
|
||||
if index + 1 < len(sublist):
|
||||
result = sublist[index + 1]
|
||||
result = re.findall(r"[a-zA-Z]+|\d+|[^a-zA-Z\d\s]", result)
|
||||
|
||||
if result:
|
||||
prefix = []
|
||||
incremented = False
|
||||
for item in reversed(result):
|
||||
if not incremented and isinstance(eval(str(item)), int):
|
||||
item = eval(item) + 1
|
||||
incremented = True
|
||||
prefix.insert(0, str(item))
|
||||
prefix = "".join(prefix)
|
||||
if result:
|
||||
prefix = []
|
||||
incremented = False
|
||||
for item in reversed(result):
|
||||
total_letters = len(item)
|
||||
total_zero_leads = 0
|
||||
for letter in item:
|
||||
if letter == "0":
|
||||
total_zero_leads = total_zero_leads + 1
|
||||
continue
|
||||
break
|
||||
|
||||
if total_zero_leads:
|
||||
item = item[total_zero_leads:]
|
||||
if isinstance(item,list):
|
||||
item = item[-1]
|
||||
if not incremented and isinstance(eval(str(item)), int):
|
||||
item = int(item) + 1
|
||||
incremented = True
|
||||
if isinstance(item,int):
|
||||
item = "{:0{}d}".format(item,total_letters)
|
||||
prefix.insert(0, str(item))
|
||||
prefix = "".join(prefix)
|
||||
except Exception as e:
|
||||
logger.exception(e)
|
||||
prefix = get_intial_prefix(None)["get_intial_prefix"]
|
||||
return prefix
|
||||
|
||||
def clean_badge_id(self):
|
||||
@@ -430,9 +448,9 @@ class BulkUpdateFieldForm(forms.Form):
|
||||
]
|
||||
self.fields["update_fields"].choices = updated_choices
|
||||
for visible in self.visible_fields():
|
||||
visible.field.widget.attrs[
|
||||
"class"
|
||||
] = "oh-select oh-select-2 select2-hidden-accessible oh-input w-100"
|
||||
visible.field.widget.attrs["class"] = (
|
||||
"oh-select oh-select-2 select2-hidden-accessible oh-input w-100"
|
||||
)
|
||||
|
||||
|
||||
class EmployeeNoteForm(ModelForm):
|
||||
|
||||
Reference in New Issue
Block a user