Skip to content

Commit

Permalink
Merge pull request #10 from uw-it-aca/develop
Browse files Browse the repository at this point in the history
use IsActive and EndEmploymentDate to determine active employment
  • Loading branch information
devights committed Dec 27, 2019
2 parents a3ee856 + 9f0ccbf commit ef20bac
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 24 deletions.
13 changes: 10 additions & 3 deletions uw_hrp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ def get_now():
return datetime.now(timezone.utc)


def is_future_end_date(end_date):
return end_date is None or end_date > get_now()


def date_to_str(d_obj):
if d_obj is not None:
return str(d_obj)
Expand All @@ -32,6 +36,9 @@ class EmploymentStatus(models.Model):
retirement_date = models.DateTimeField(null=True, default=None)
termination_date = models.DateTimeField(null=True, default=None)

def is_active_employment(self):
return self.is_active and is_future_end_date(self.end_emp_date)

def to_json(self):
return {'end_emp_date': date_to_str(self.end_emp_date),
'hire_date': date_to_str(self.hire_date),
Expand Down Expand Up @@ -126,7 +133,7 @@ class WorkerPosition(models.Model):
title = models.CharField(max_length=128, null=True, default=None)

def is_active_position(self):
return self.end_date is None or self.end_date > get_now()
return is_future_end_date(self.end_date)

def to_json(self):
data = {'start_date': date_to_str(self.start_date),
Expand Down Expand Up @@ -225,8 +232,8 @@ def __init__(self, *args, **kwargs):
self.employee_status = EmploymentStatus(
data=data.get("WorkerEmploymentStatus"))

if (self.employee_status.is_active or
self.employee_status.is_retired):
if self.employee_status.is_active_employment():

positions = data.get("WorkerPositions")
if positions is not None and len(positions) > 0:
for position in positions:
Expand Down
49 changes: 28 additions & 21 deletions uw_hrp/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,36 @@ def test_employment_status(self):
self.assertIsNotNone(str(emp_status))

emp_status = EmploymentStatus(
data={"IsActive": False,
"EmployeeStatus": "Terminated",
"EmployeeStatusCode": "N",
"IsTerminated": True,
"IsRetired": False,
"EndEmploymentDate": "2017-09-16T07:00:00.000Z",
"HireDate": "1980-07-01T07:00:00.000Z",
"RetirementDate": "2017-09-16T07:00:00.000Z",
"TerminationDate": "2017-09-16T07:00:00.000Z"})
data={
"HireDate": "2016-03-01T08:00:00.000Z",
"OriginalHireDate": "1982-12-31T08:00:00.000Z",
"EndEmploymentDate": "2019-05-30T07:00:00.000Z",
"FirstDayOfWork": "2016-03-01T08:00:00.000Z",
"ActiveStatusDate": "2016-03-01T08:00:00.000Z",
"IsActive": True,
"EmployeeStatus": "Active",
"EmployeeStatusCode": "A",
"IsTerminated": False,
"TerminationDate": None,
"IsRetired": False,
"RetirementDate": None,
"EstimatedLastDayOfLeave": None,
"FirstDayOfLeave": None,
"LastDayOfWorkForLeave": None})
self.assertIsNotNone(str(emp_status))
self.assertTrue(emp_status.is_terminated)
self.assertFalse(emp_status.is_active)
self.assertFalse(emp_status.is_terminated)
self.assertFalse(emp_status.is_active_employment())
self.assertEqual(
emp_status.to_json(),
{'end_emp_date': '2017-09-16 07:00:00+00:00',
'hire_date': '1980-07-01 07:00:00+00:00',
'is_active': False,
{'end_emp_date': '2019-05-30 07:00:00+00:00',
'hire_date': '2016-03-01 08:00:00+00:00',
'is_active': True,
'is_retired': False,
'is_terminated': True,
'retirement_date': '2017-09-16 07:00:00+00:00',
'status': 'Terminated',
'status_code': 'N',
'termination_date': '2017-09-16 07:00:00+00:00'})
'is_terminated': False,
'retirement_date': None,
'status': 'Active',
'status_code': 'A',
'termination_date': None})

def test_job_profile(self):
job_prof = JobProfile(job_code="1", description="A")
Expand Down Expand Up @@ -174,6 +181,7 @@ def test_worker(self):
regid="10000000",
employee_id="100000115")
self.assertIsNotNone(str(worker))

data = {
"NetID": "webmaster",
"RegID": "10000000000000000000000000000115",
Expand Down Expand Up @@ -325,7 +333,7 @@ def test_worker(self):
"EmployeeStatus": "Terminated",
"EmployeeStatusCode": "N",
"IsTerminated": True,
"EndEmploymentDate": None,
"EndEmploymentDate": "2018-07-01T07:00:00.000Z",
"HireDate": "1980-07-01T07:00:00.000Z",
"IsRetired": False,
"RetirementDate": None,
Expand All @@ -342,7 +350,6 @@ def test_workerref(self):
regid = '10000000000000000000000000000005'
wr = WorkerRef(netid="test", regid=regid)
self.assertIsNotNone(wr)
print(wr)
wr = WorkerRef(
data={
'Href': '/hrp/v2/worker/{}.json'.format(regid),
Expand Down

0 comments on commit ef20bac

Please sign in to comment.