From 03f7bfbbde8f6572171e61e6f828149f5a839ff5 Mon Sep 17 00:00:00 2001 From: barredterra <14891507+barredterra@users.noreply.github.com> Date: Thu, 1 Dec 2022 12:42:03 +0100 Subject: [PATCH] refactor: validate dates --- erpnext/setup/doctype/employee/employee.py | 31 +++------------------- 1 file changed, 4 insertions(+), 27 deletions(-) diff --git a/erpnext/setup/doctype/employee/employee.py b/erpnext/setup/doctype/employee/employee.py index 13a6f20db2..facefa376a 100755 --- a/erpnext/setup/doctype/employee/employee.py +++ b/erpnext/setup/doctype/employee/employee.py @@ -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: