Refactor the Employee tab of profile view, per better patterns

learned some things from the Personal tab overhaul
This commit is contained in:
Lance Edgar 2021-10-05 08:25:33 -04:00
parent 6386b34516
commit e7fb1559f5
2 changed files with 161 additions and 225 deletions

View file

@ -441,6 +441,7 @@ class PersonView(MasterView):
'customers_data': self.get_context_customers(person),
'members_data': self.get_context_members(person),
'employee': employee,
'employee_data': self.get_context_employee(employee) if employee else {},
'employee_view_url': self.request.route_url('employees.view', uuid=employee.uuid) if employee else None,
'employee_history': employee.get_current_history() if employee else None,
'employee_history_data': self.get_context_employee_history(employee),
@ -581,6 +582,7 @@ class PersonView(MasterView):
app = self.get_rattail_app()
handler = app.get_employment_handler()
context = handler.get_context_employee(employee)
context['view_url'] = self.request.route_url('employees.view', uuid=employee.uuid)
return context
def get_context_employee_history(self, employee):
@ -884,6 +886,7 @@ class PersonView(MasterView):
start_date = datetime.datetime.strptime(data['start_date'], '%Y-%m-%d').date()
employee = handler.begin_employment(person, start_date,
employee_id=data['id'])
self.Session.flush()
return self.profile_start_employee_result(employee, start_date)
def profile_start_employee_result(self, employee, start_date):
@ -912,6 +915,7 @@ class PersonView(MasterView):
employee = handler.get_employee(person)
handler.end_employment(employee, end_date,
revoke_access=data.get('revoke_access'))
self.Session.flush()
return self.profile_end_employee_result(employee, end_date)
def profile_end_employee_result(self, employee, end_date):
@ -948,9 +952,9 @@ class PersonView(MasterView):
self.Session.flush()
current_history = employee.get_current_history()
return {
'success': True,
'employee': self.get_context_employee(employee),
'start_date': six.text_type(current_history.start_date),
'end_date': six.text_type(current_history.end_date or ''),
'employee_history_data': self.get_context_employee_history(employee),