refactor: validate dates

This commit is contained in:
barredterra 2022-12-01 12:42:03 +01:00
parent 5b1798363c
commit 03f7bfbbde

View File

@ -145,33 +145,10 @@ class Employee(NestedSet):
if self.date_of_birth and getdate(self.date_of_birth) > getdate(today()):
throw(_("Date of Birth cannot be greater than today."))
if (
self.date_of_birth
and self.date_of_joining
and getdate(self.date_of_birth) >= getdate(self.date_of_joining)
):
throw(_("Date of Joining must be greater than Date of Birth"))
elif (
self.date_of_retirement
and self.date_of_joining
and (getdate(self.date_of_retirement) <= getdate(self.date_of_joining))
):
throw(_("Date Of Retirement must be greater than Date of Joining"))
elif (
self.relieving_date
and self.date_of_joining
and (getdate(self.relieving_date) < getdate(self.date_of_joining))
):
throw(_("Relieving Date must be greater than or equal to Date of Joining"))
elif (
self.contract_end_date
and self.date_of_joining
and (getdate(self.contract_end_date) <= getdate(self.date_of_joining))
):
throw(_("Contract End Date must be greater than Date of Joining"))
self.validate_from_to_dates("date_of_birth", "date_of_joining")
self.validate_from_to_dates("date_of_joining", "date_of_retirement")
self.validate_from_to_dates("date_of_joining", "relieving_date")
self.validate_from_to_dates("date_of_joining", "contract_end_date")
def validate_email(self):
if self.company_email: