Skip to content

Commit

Permalink
Remove db lookup for utilization table and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Sgtpluck committed Jan 29, 2021
1 parent d022a73 commit 12dac8e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
4 changes: 2 additions & 2 deletions tock/employees/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ def test_billable_expectation(self):

def test_display_name_if_no_full_name(self):
expected = self.regular_user.username
self.assertEqual(self.regular_user_userdata.display_name, expected)
self.assertEqual(self.regular_user_userdata.display_name, expected)

def test_display_name_if_full_name(self):
self.regular_user.first_name = 'Hank'
self.regular_user.last_name = 'Venture'
Expand Down
2 changes: 1 addition & 1 deletion tock/employees/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class UserFormView(PermissionMixin, FormView):

def get_context_data(self, **kwargs):
user = User.objects.get(username=self.kwargs['username'])
kwargs['display_name'] = user.user_data.display_name
kwargs['display_name'] = user.user_data.display_name
context = super(UserFormView, self).get_context_data(**kwargs)
context.update(user_billing_context(user))
return _add_recent_tock_table(user, context)
Expand Down
7 changes: 2 additions & 5 deletions tock/utilization/unit.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import pdb
from django.conf import settings
from django.contrib.auth import get_user_model
from django.db.models import Sum, Q
from .utils import (_build_utilization_context, calculate_utilization,
utilization_report, limit_to_fy)

from employees.models import UserData

User = get_user_model()

# Building context for display of business unit level utilization data
Expand Down Expand Up @@ -52,11 +49,11 @@ def _get_unit_billing_data(users, unit, recent_periods=None, fiscal_year=False):
start, end, utilization = utilization_report(users, unit=unit)

if utilization:
data = utilization.values('user_data', 'billable', 'target')
data = utilization.values('billable', 'first_name','last_name', 'target', 'username')

# Build context for each employee
output_data = [{
'display_name': UserData.objects.get(id=employee['user_data']).display_name,
'display_name': f"{employee['first_name']} {employee['last_name']}".strip() or employee['username'],
'denominator': employee['target'],
'billable': employee['billable'],
'utilization': calculate_utilization(employee['billable'], employee['target'])
Expand Down

0 comments on commit 12dac8e

Please sign in to comment.