[UPDT] EMPLOYEE: Work info,bank info forms added with as_p function

This commit is contained in:
Horilla
2025-01-14 12:13:27 +05:30
parent 4801934303
commit 2f8b80bdd1
4 changed files with 116 additions and 262 deletions

View File

@@ -266,16 +266,32 @@ class EmployeeWorkInformationForm(ModelForm):
Form for EmployeeWorkInformation model
"""
employees = Employee.objects.filter(employee_work_info=None)
employee_id = forms.ModelChoiceField(queryset=employees)
class Meta:
"""
Meta class to add the additional info
"""
model = EmployeeWorkInformation
fields = "__all__"
fields = (
"department_id",
"job_position_id",
"job_role_id",
"shift_id",
"work_type_id",
"employee_type_id",
"reporting_manager_id",
"company_id",
"location",
"email",
"mobile",
"date_joining",
"contract_end_date",
"tags",
"basic_salary",
"salary_hour",
)
exclude = ("employee_id",)
widgets = {
"date_joining": DateInput(attrs={"type": "date"}),
"contract_end_date": DateInput(attrs={"type": "date"}),
@@ -344,6 +360,10 @@ class EmployeeWorkInformationForm(ModelForm):
del self.errors["employee_id"]
return cleaned_data
def as_p(self, *args, **kwargs):
context = {"form": self}
return render_to_string("employee/create_form/personal_info_as_p.html", context)
class EmployeeWorkInformationUpdateForm(ModelForm):
"""
@@ -364,6 +384,10 @@ class EmployeeWorkInformationUpdateForm(ModelForm):
"contract_end_date": DateInput(attrs={"type": "date"}),
}
def as_p(self, *args, **kwargs):
context = {"form": self}
return render_to_string("employee/create_form/personal_info_as_p.html", context)
class EmployeeBankDetailsForm(ModelForm):
"""
@@ -378,11 +402,18 @@ class EmployeeBankDetailsForm(ModelForm):
"""
model = EmployeeBankDetails
fields = "__all__"
exclude = [
"employee_id",
"is_active",
]
fields = (
"bank_name",
"account_number",
"branch",
"any_other_code1",
"address",
"country",
"state",
"city",
"any_other_code2",
)
exclude = ["employee_id", "is_active", "additional_info"]
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
@@ -390,6 +421,10 @@ class EmployeeBankDetailsForm(ModelForm):
for visible in self.visible_fields():
visible.field.widget.attrs["class"] = "oh-input w-100"
def as_p(self, *args, **kwargs):
context = {"form": self}
return render_to_string("employee/update_form/bank_info_as_p.html", context)
class EmployeeBankDetailsUpdateForm(ModelForm):
"""
@@ -403,10 +438,7 @@ class EmployeeBankDetailsUpdateForm(ModelForm):
model = EmployeeBankDetails
fields = "__all__"
exclude = [
"employee_id",
"is_active",
]
exclude = ["employee_id", "is_active", "additional_info"]
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
@@ -415,6 +447,10 @@ class EmployeeBankDetailsUpdateForm(ModelForm):
for field in self.fields:
self.fields[field].widget.attrs["placeholder"] = self.fields[field].label
def as_p(self, *args, **kwargs):
context = {"form": self}
return render_to_string("employee/update_form/bank_info_as_p.html", context)
excel_columns = [
("badge_id", trans("Badge ID")),

View File

@@ -7,73 +7,7 @@
</div>
{% csrf_token %}
<input type="hidden" name="form" value="bank">
<div class="row">
<div class="col-12 col-sm-12 col-md-12 col-lg-6">
<div class="oh-input-group">
<label class="oh-label" for="{{bank_form.bank_name.id_for_label}}">{% trans "Bank Name" %}</label>
{{bank_form.bank_name}}
</div>
</div>
<div class="col-12 col-sm-12 col-md-12 col-lg-6">
<div class="oh-input-group">
<label class="oh-label" for="{{bank_form.account_number.id_for_label}}">{% trans "Account Number" %}</label>
{{bank_form.account_number}}
{{bank_form.account_number.errors}}
</div>
</div>
</div>
<div class="row">
<div class="col-12 col-sm-12 col-md-12 col-lg-6">
<div class="oh-input-group">
<label class="oh-label" for="{{bank_form.branch.id_for_label}}">{% trans "Branch" %}</label>
{{bank_form.branch}}
</div>
</div>
<div class="col-12 col-sm-12 col-md-12 col-lg-6">
<div class="oh-input-group">
<label class="oh-label" for="{{bank_form.any_other_code1.id_for_label}}">{% trans "Bank Code" %} #1</label>
{{bank_form.any_other_code1}}
</div>
</div>
</div>
<div class="row">
<div class="col-12 col-sm-12 col-md-12 col-lg-12">
<div class="oh-input-group">
<label class="oh-label" for="{{bank_form.address.id_for_label}}">{% trans "Bank Address" %}</label>
{{bank_form.address}}
</div>
</div>
</div>
<div class="row">
<div class="col-12 col-sm-12 col-md-12 col-lg-6">
<label class="oh-label" for="country">{% trans "Country" %}</label>
<select name="country" class="oh-select-2 w-100 country" id="country">
<option value="{{bank_form.instance.country}}" selected>{{bank_form.instance.county}}</option>
</select>
</div>
<div class="col-12 col-sm-12 col-md-12 col-lg-6">
<div class="oh-input-group">
<label class="oh-label" for="state">{% trans "State" %}</label>
<select name="state" class="oh-select-2 w-100 country" id="state">
<option value="{{bank_form.instance.state}}" selected>{{bank_form.instance.state}}</option>
</select>
</div>
</div>
</div>
<div class="row">
<div class="col-12 col-sm-12 col-md-12 col-lg-6">
<div class="oh-input-group">
<label class="oh-label" for="{{bank_form.city.id_for_label}}">{% trans "City" %}</label>
{{bank_form.city}}
</div>
</div>
<div class="col-12 col-sm-12 col-md-12 col-lg-6">
<div class="oh-input-group">
<label class="oh-label" for="{{bank_form.any_other_code2.id_for_label}}">{% trans "Bank Code" %} #2</label>
{{bank_form.any_other_code2}}
</div>
</div>
</div>
{{bank_form.as_p}}
<hr class="mt-5 mb-3">
<div class="w-100 d-flex align-items-center justify-content-end">
<button type="submit" class="oh-btn oh-btn--secondary oh-btn--w-100-resp">

View File

@@ -0,0 +1,65 @@
{% load i18n %} {% load basefilters %}{% load widget_tweaks %}
{{ form.non_field_errors }}
<div class="row">
{% for field in form %}
{% if field.label != "Employee profile" and field.label != 'Country' and field.label != 'State' and field.label != 'Address' and field.label != 'Badge id' %}
<div class="col-lg-6">
<div class="oh-input__group">
<label
class="oh-label {% if field.field.required %}required-star{% endif %}"
for="id_{{ field.name }}"
title="{{ field.help_text|safe }}"
>
{% trans field.label %}
</label>
{% if field.field.widget.input_type == 'checkbox' %}
<div class="oh-switch" style="width: 30px;">{{ field|add_class:'oh-switch__checkbox' }}</div>
{% else %}
{{ field|add_class:'form-control' }}
{% endif %}
{{ field.errors }}
</div>
</div>
{% elif field.label == 'Address' %}
<div class="col-lg-12">
<div class="oh-input__group">
<label
class="oh-label {% if field.field.required %}required-star{% endif %}"
for="id_{{ field.name }}"
title="{{ field.help_text|safe }}"
>
{% trans field.label %}
</label>
{{ field }}
{{ field.errors }}
</div>
</div>
{% elif field.label == 'Country' %}
<div class="row">
<div class="col-lg-6">
<label class="oh-label" for="country">{% trans "Country" %}</label>
<select name="country" class="w-100 oh-select-2" id="country">
<option value="{{form.instance.country}}" selected>{{form.instance.country}}</option>
</select>
{{form.country.errors}}
<span class="dropdown-wrapper" aria-hidden="true"></span>
</span>
</div>
<div class="col-lg-6">
<label class="oh-label d-block" for="state">{% trans "State" %}</label>
<select name="state" class="w-100 oh-select-2" id="state">
<option value="{{form.instance.state}}" selected>{{form.instance.state}}</option>
</select>
{{form.state.errors}}
</div>
</div>
{% endif %}
{% endfor %}
</div>

View File

@@ -82,188 +82,7 @@
{{history_form.as_history_modal}}
{% endif %}
{% csrf_token %}
<div class="row" data-select2-id="select2-data-27-19z8">
<div class="col-12 col-sm-12 col-md-12 col-lg-6">
<div class="oh-input-group">
<label
class="oh-label"
for="{{work_form.department_id.id_for_label}}"
>{% trans "Department" %}</label
>
{{work_form.department_id}}
</div>
</div>
<div
class="col-12 col-sm-12 col-md-12 col-lg-6"
data-select2-id="select2-data-26-o2rs"
>
<div class="oh-input-group" data-select2-id="select2-data-25-5380">
<label
class="oh-label"
for="{{work_form.job_position_id.id_for_label}}"
>{% trans "Job Position" %}</label
>
{{work_form.job_position_id}}
</div>
</div>
</div>
<div class="row">
<div class="col-12 col-sm-12 col-md-12 col-lg-6">
<div class="oh-input-group">
<label
class="oh-label"
for="{{work_form.job_role_id.id_for_label}}"
>{% trans "Job Role" %}</label
>
{{work_form.job_role_id}}
</div>
</div>
<div class="col-12 col-sm-12 col-md-12 col-lg-6">
<div class="oh-input-group">
<label class="oh-label" for="{{work_form.shift_id.id_for_label}}"
>{% trans "Shift Information" %}</label
>
{{work_form.shift_id}}
</div>
</div>
</div>
<div class="row" data-select2-id="select2-data-27-95a0">
<div class="col-12 col-sm-12 col-md-12 col-lg-6">
<div class="oh-input-group">
<label
class="oh-label"
for="{{work_form.work_type_id.id_for_label}}"
>{% trans "Work Type" %}</label
>
{{work_form.work_type_id}}
</div>
</div>
<div
class="col-12 col-sm-12 col-md-12 col-lg-6"
data-select2-id="select2-data-26-u84a"
>
<div class="oh-input-group" data-select2-id="select2-data-25-5l0x">
<label
class="oh-label"
for="{{work_form.employee_type_id.id_for_label}}"
>{% trans "Employee Type" %}</label
>
{{work_form.employee_type_id}}
</div>
</div>
</div>
<div class="row" data-select2-id="select2-data-39-3q9c">
<div
class="col-12 col-sm-12 col-md-12 col-lg-6"
data-select2-id="select2-data-38-ofph"
>
<div class="oh-input-group" data-select2-id="select2-data-37-p4f9">
<label
class="oh-label"
for="{{work_form.reporting_manager_id.id_for_label}}"
>{% trans "Reporting Manager" %}</label
>
{{work_form.reporting_manager_id}}
</div>
</div>
<div class="col-12 col-sm-12 col-md-12 col-lg-6">
<div class="oh-input-group">
<label
class="oh-label"
for="{{work_form.company_id.id_for_label}}"
>{% trans "Company" %}</label
>
{{work_form.company_id}}
</div>
</div>
</div>
<div class="row">
<div class="col-12 col-sm-12 col-md-12 col-lg-6">
<div class="oh-input-group">
<label class="oh-label" for="{{work_form.location.id_for_label}}"
>{% trans "Work Location" %}</label
>
{{work_form.location}}
</div>
</div>
<div class="col-12 col-sm-12 col-md-12 col-lg-6">
<div class="oh-input-group">
<label
class="oh-label"
for="{{work_form.email.id_for_label}}"
for="workEmail"
>{% trans "Work Email" %}</label
>
{{work_form.email}}
</div>
</div>
</div>
<div class="row">
<div class="col-12 col-sm-12 col-md-12 col-lg-6">
<div class="oh-input-group">
<label
class="oh-label"
for="{{work_form.mobile.id_for_label}}"
>{% trans "Work Phone" %}</label
>
{{work_form.mobile}}
</div>
</div>
<div class="col-12 col-sm-12 col-md-12 col-lg-6">
<div class="oh-input-group">
<label
class="oh-label"
for="{{work_form.date_joining.id_for_label}}"
for="startDate"
>{% trans "Joining Date" %}</label
>
{{work_form.date_joining}}
</div>
</div>
<div class="col-12 col-sm-12 col-md-12 col-lg-6">
<div class="oh-input-group">
<label
class="oh-label"
for="{{work_form.contract_end_date.id_for_label}}"
for="endDate"
>{% trans "Contract End Date" %}</label
>
{{work_form.contract_end_date}}
</div>
</div>
<div class="col-12 col-sm-12 col-md-12 col-lg-6">
<div class="oh-input-group">
<label class="oh-label" for="{{work_form.tags.id_for_label}}"
>{% trans "Employee Tag" %}</label
>
{{work_form.tags}}
</div>
</div>
</div>
<div class="row">
<div class="col-12 col-sm-12 col-md-12 col-lg-6">
<div class="oh-input-group">
<label
class="oh-label"
for="{{work_form.basic_salary.id_for_label}}"
>{% trans "Basic Salary" %}</label
>
{{work_form.basic_salary}}
</div>
</div>
<div class="col-12 col-sm-12 col-md-12 col-lg-6">
<div class="oh-input-group">
<label
class="oh-label"
for="{{work_form.salary_hour.id_for_label}}"
for="workEmail"
>{% trans "Salary Per Hour" %}</label
>
{{work_form.salary_hour}}
</div>
</div>
</div>
{{work_form.as_p}}
<hr class="mt-5 mb-3" />
<div class="w-100 d-flex align-items-center justify-content-end">
<button