diff --git a/payroll/forms/forms.py b/payroll/forms/forms.py index 3c07d4b84..dc152558a 100644 --- a/payroll/forms/forms.py +++ b/payroll/forms/forms.py @@ -2,6 +2,7 @@ forms.py """ from django import forms +from django.forms import widgets from django.utils.translation import gettext_lazy as trans from django.template.loader import render_to_string from payroll.models.models import WorkRecord @@ -55,7 +56,12 @@ class ContractForm(ModelForm): """ ContactForm """ + verbose_name = trans("Contract") + contract_start_date = forms.DateField() + contract_end_date = forms.DateField() + + class Meta: """ Meta class for additional options @@ -69,23 +75,23 @@ class ContractForm(ModelForm): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - self.fields["contract_name"].widget.attrs["autocomplete"] = "off" - self.fields["contract_start_date"].widget.attrs["autocomplete"] = "off" - self.fields["contract_start_date"].widget.attrs["class"] = "oh-input w-100" - self.fields["contract_start_date"].widget = forms.TextInput( - attrs={"type": "date", "class": "oh-input w-100"} + self.fields["employee_id"].widget.attrs.update( + {"onchange": "contractInitial(this)"} ) - self.fields["contract_end_date"].widget.attrs["autocomplete"] = "off" - self.fields["contract_end_date"].widget.attrs["class"] = "oh-input w-100" - self.fields["contract_end_date"].widget = forms.TextInput( - attrs={"type": "date", "class": "oh-input w-100"} + self.fields["contract_start_date"].widget = widgets.DateInput( + attrs={ + "type":"date", + "class": "oh-input w-100", + "placeholder": "Select a date", + } + ) + self.fields["contract_end_date"].widget = widgets.DateInput( + attrs={ + "type":"date", + "class": "oh-input w-100", + "placeholder": "Select a date", + } ) - self.fields["employee_id"].widget.attrs["data-contract-style"] = "" - self.fields["department"].widget.attrs["data-contract-style"] = "" - self.fields["job_position"].widget.attrs["data-contract-style"] = "" - self.fields["job_role"].widget.attrs["data-contract-style"] = "" - self.fields["work_type"].widget.attrs["data-contract-style"] = "" - self.fields["shift"].widget.attrs["data-contract-style"] = "" def as_p(self): """ diff --git a/payroll/models/models.py b/payroll/models/models.py index 4ab43e8a6..6cd810455 100644 --- a/payroll/models/models.py +++ b/payroll/models/models.py @@ -484,7 +484,9 @@ class OverrideLeaveRequest(LeaveRequest): work_entry.work_record_type = status work_entry.date = date work_entry.message = ( - "Validated" if status == "ABS" else _("Half day need to validate") + "Validated" + if status == "ABS" + else _("Half day need to validate") ) work_entry.save() except: @@ -868,6 +870,16 @@ class Allowance(models.Model): def __str__(self) -> str: return str(self.title) + def save(self): + super().save() + if ( + not self.include_active_employees + and not self.specific_employees.first() + and not self.is_condition_based + ): + self.include_active_employees = True + super().save() + class Deduction(models.Model): """ @@ -1112,6 +1124,16 @@ class Deduction(models.Model): def __str__(self) -> str: return str(self.title) + def save(self): + super().save() + if ( + not self.include_active_employees + and not self.specific_employees.first() + and not self.is_condition_based + ): + self.include_active_employees = True + super().save() + class Payslip(models.Model): """ @@ -1124,7 +1146,7 @@ class Payslip(models.Model): ("confirmed", _("Confirmed")), ("paid", _("Paid")), ] - group_name = models.CharField(max_length=50,null=True,blank=True) + group_name = models.CharField(max_length=50, null=True, blank=True) reference = models.CharField(max_length=255, unique=False) employee_id = models.ForeignKey( Employee, on_delete=models.PROTECT, verbose_name=_("Employee") diff --git a/payroll/templates/payroll/common/form.html b/payroll/templates/payroll/common/form.html index dfba2086d..03c43c980 100644 --- a/payroll/templates/payroll/common/form.html +++ b/payroll/templates/payroll/common/form.html @@ -1,92 +1,64 @@ {% extends 'index.html' %} {% block content %} {% load static %} -