[FIX] EMPLOYEE: Fixed the issue in employee creation with and without selecting a company (#399 & #408)
This commit is contained in:
@@ -246,7 +246,8 @@ class EmployeeForm(ModelForm):
|
||||
"""
|
||||
badge_id = self.cleaned_data["badge_id"]
|
||||
if badge_id:
|
||||
queryset = Employee.objects.filter(badge_id=badge_id).exclude(
|
||||
all_employees = Employee.objects.get_all()
|
||||
queryset = all_employees.filter(badge_id=badge_id).exclude(
|
||||
pk=self.instance.pk if self.instance else None
|
||||
)
|
||||
if queryset.exists():
|
||||
|
||||
@@ -489,9 +489,11 @@ class Employee(models.Model):
|
||||
# Create user if no corresponding user exists
|
||||
username = self.email
|
||||
password = self.phone
|
||||
user = User.objects.create_user(
|
||||
username=username, email=username, password=password
|
||||
)
|
||||
user = User.objects.filter(username=username).first()
|
||||
if not user:
|
||||
user = User.objects.create_user(
|
||||
username=username, email=username, password=password
|
||||
)
|
||||
self.employee_user_id = user
|
||||
# default permissions
|
||||
change_ownprofile = Permission.objects.get(codename="change_ownprofile")
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
</div>
|
||||
<div class="oh-modal__dialog-body" id="uploadPhotoModalBody">
|
||||
<div class="oh-profile-section__image-container">
|
||||
<form hx-post="{% url 'update-profile-image' form.instance.id %}" hx-target="#uploadPhotoModalBody"
|
||||
<form hx-post="{% url 'update-profile-image' obj_id %}" hx-target="#uploadPhotoModalBody"
|
||||
hx-encoding="multipart/form-data" id="file-form">
|
||||
<div class="oh-profile-section__modal-avatar ">
|
||||
<img src="{{form.instance.get_avatar}}" class="oh-profile-section__modal-image preview"
|
||||
@@ -53,7 +53,7 @@
|
||||
{% csrf_token %}
|
||||
<div class="d-flex justify-content-between w-100 align-items-center mt-4">
|
||||
<button class="oh-btn oh-btn--light-danger mr-1"
|
||||
hx-delete="{% url 'remove-profile-image' form.instance.id %}"
|
||||
hx-delete="{% url 'remove-profile-image' obj_id %}"
|
||||
hx-target="#personalMessage">
|
||||
<ion-icon class="me-1" name="trash-outline"></ion-icon>
|
||||
{% trans "Delete Image" %}
|
||||
|
||||
Reference in New Issue
Block a user