158 lines
5.7 KiB
Python
158 lines
5.7 KiB
Python
"""
|
|
Forms for HR app.
|
|
"""
|
|
|
|
from django import forms
|
|
from django.utils.translation import gettext_lazy as _
|
|
from crispy_forms.helper import FormHelper
|
|
from crispy_forms.layout import Layout, Fieldset, Row, Column, Submit
|
|
|
|
from .models import Attendance, Schedule, Holiday, LeaveRequest
|
|
|
|
|
|
class AttendanceForm(forms.ModelForm):
|
|
"""Form for creating/updating attendance records."""
|
|
|
|
class Meta:
|
|
model = Attendance
|
|
fields = [
|
|
'employee',
|
|
'date',
|
|
'check_in',
|
|
'check_out',
|
|
'status',
|
|
'notes',
|
|
]
|
|
widgets = {
|
|
'employee': forms.Select(attrs={'class': 'form-select select2', 'data-placeholder': 'Select employee'}),
|
|
'date': forms.DateInput(attrs={'class': 'form-control', 'type': 'date'}),
|
|
'check_in': forms.TimeInput(attrs={'class': 'form-control', 'type': 'time'}),
|
|
'check_out': forms.TimeInput(attrs={'class': 'form-control', 'type': 'time'}),
|
|
'status': forms.Select(attrs={'class': 'form-control'}),
|
|
'notes': forms.Textarea(attrs={'class': 'form-control', 'rows': 3}),
|
|
}
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
super().__init__(*args, **kwargs)
|
|
self.helper = FormHelper()
|
|
self.helper.form_method = 'post'
|
|
self.helper.layout = Layout(
|
|
Fieldset(
|
|
_('Attendance Information'),
|
|
Row(
|
|
Column('employee', css_class='form-group col-md-6 mb-0'),
|
|
Column('date', css_class='form-group col-md-6 mb-0'),
|
|
css_class='form-row'
|
|
),
|
|
Row(
|
|
Column('check_in', css_class='form-group col-md-4 mb-0'),
|
|
Column('check_out', css_class='form-group col-md-4 mb-0'),
|
|
Column('status', css_class='form-group col-md-4 mb-0'),
|
|
css_class='form-row'
|
|
),
|
|
'notes',
|
|
),
|
|
Submit('submit', _('Save Attendance'), css_class='btn btn-primary mt-3')
|
|
)
|
|
|
|
|
|
class ScheduleForm(forms.ModelForm):
|
|
"""Form for creating/updating work schedules."""
|
|
|
|
class Meta:
|
|
model = Schedule
|
|
fields = [
|
|
'employee',
|
|
'day_of_week',
|
|
'start_time',
|
|
'end_time',
|
|
'is_active',
|
|
]
|
|
widgets = {
|
|
'employee': forms.Select(attrs={'class': 'form-select select2', 'data-placeholder': 'Select employee'}),
|
|
'day_of_week': forms.Select(attrs={'class': 'form-control'}),
|
|
'start_time': forms.TimeInput(attrs={'class': 'form-control', 'type': 'time'}),
|
|
'end_time': forms.TimeInput(attrs={'class': 'form-control', 'type': 'time'}),
|
|
'is_active': forms.CheckboxInput(attrs={'class': 'form-check-input'}),
|
|
}
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
super().__init__(*args, **kwargs)
|
|
self.helper = FormHelper()
|
|
self.helper.form_method = 'post'
|
|
self.helper.layout = Layout(
|
|
Fieldset(
|
|
_('Schedule Information'),
|
|
Row(
|
|
Column('employee', css_class='form-group col-md-6 mb-0'),
|
|
Column('day_of_week', css_class='form-group col-md-6 mb-0'),
|
|
css_class='form-row'
|
|
),
|
|
Row(
|
|
Column('start_time', css_class='form-group col-md-5 mb-0'),
|
|
Column('end_time', css_class='form-group col-md-5 mb-0'),
|
|
Column('is_active', css_class='form-group col-md-2 mb-0'),
|
|
css_class='form-row'
|
|
),
|
|
),
|
|
Submit('submit', _('Save Schedule'), css_class='btn btn-primary mt-3')
|
|
)
|
|
|
|
|
|
class HolidayForm(forms.ModelForm):
|
|
"""Form for creating/updating holidays."""
|
|
|
|
class Meta:
|
|
model = Holiday
|
|
fields = [
|
|
'name',
|
|
'date',
|
|
'is_recurring',
|
|
'description',
|
|
]
|
|
widgets = {
|
|
'name': forms.TextInput(attrs={'class': 'form-control'}),
|
|
'date': forms.DateInput(attrs={'class': 'form-control', 'type': 'date'}),
|
|
'is_recurring': forms.CheckboxInput(attrs={'class': 'form-check-input'}),
|
|
'description': forms.Textarea(attrs={'class': 'form-control', 'rows': 3}),
|
|
}
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
super().__init__(*args, **kwargs)
|
|
self.helper = FormHelper()
|
|
self.helper.form_method = 'post'
|
|
self.helper.layout = Layout(
|
|
Fieldset(
|
|
_('Holiday Information'),
|
|
Row(
|
|
Column('name', css_class='form-group col-md-8 mb-0'),
|
|
Column('date', css_class='form-group col-md-4 mb-0'),
|
|
css_class='form-row'
|
|
),
|
|
'is_recurring',
|
|
'description',
|
|
),
|
|
Submit('submit', _('Save Holiday'), css_class='btn btn-primary mt-3')
|
|
)
|
|
|
|
|
|
class LeaveRequestForm(forms.ModelForm):
|
|
"""Form for creating/updating leave requests."""
|
|
|
|
class Meta:
|
|
model = LeaveRequest
|
|
fields = [
|
|
'leave_type',
|
|
'start_date',
|
|
'end_date',
|
|
'reason',
|
|
'attachment',
|
|
]
|
|
widgets = {
|
|
'leave_type': forms.Select(attrs={'class': 'form-select'}),
|
|
'start_date': forms.DateInput(attrs={'class': 'form-control', 'type': 'date'}),
|
|
'end_date': forms.DateInput(attrs={'class': 'form-control', 'type': 'date'}),
|
|
'reason': forms.Textarea(attrs={'class': 'form-control', 'rows': 4}),
|
|
'attachment': forms.FileInput(attrs={'class': 'form-control'}),
|
|
}
|