Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace if_18f_employee field with property #1078

Merged
merged 5 commits into from
May 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tock/employees/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,17 @@ class UserDataAdmin(admin.ModelAdmin):
'start_date',
'end_date',
'get_organization_name',
'billable_expectation',
'unit_info',
'current_employee',
'is_18f_employee',
'is_billable',
'is_aws_eligible',
)
list_filter = (
'current_employee',
'is_18f_employee',
'is_aws_eligible',
'organization__name',
'unit',
)
search_fields = ('user__username',)

Expand Down
2 changes: 1 addition & 1 deletion tock/employees/fixtures/user_data.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"model": "employees.userdata", "pk": 1, "fields": {"user": 1, "start_date": "2013-06-17", "end_date": "2015-05-29", "current_employee": true, "is_18f_employee": true, "unit": null, "billable_expectation": 0.80}}]
[{"model": "employees.userdata", "pk": 1, "fields": {"user": 1, "start_date": "2013-06-17", "end_date": "2015-05-29", "current_employee": true, "unit": null, "billable_expectation": 0.80}}]
17 changes: 17 additions & 0 deletions tock/employees/migrations/0029_remove_userdata_is_18f_employee.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 2.2.12 on 2020-05-05 01:48

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('employees', '0028_remove_userdata_is_billable'),
]

operations = [
migrations.RemoveField(
model_name='userdata',
name='is_18f_employee',
),
]
20 changes: 20 additions & 0 deletions tock/employees/migrations/0030_auto_20200505_0925.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 2.2.12 on 2020-05-05 13:25

from decimal import Decimal
import django.core.validators
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('employees', '0029_remove_userdata_is_18f_employee'),
]

operations = [
migrations.AlterField(
model_name='userdata',
name='billable_expectation',
field=models.DecimalField(decimal_places=2, default=Decimal('0.8000000000000000444089209850062616169452667236328125'), help_text='Percentage of hours (expressed as a decimal) expected to be billable each week', max_digits=3, validators=[django.core.validators.MaxValueValidator(limit_value=1)]),
),
]
12 changes: 10 additions & 2 deletions tock/employees/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from django.core.validators import MaxValueValidator
from django.db import IntegrityError, models
from django.db.models import Q
from django.utils.functional import cached_property
from organizations.models import Organization, Unit
from projects.models import ProfitLossAccount
from rest_framework.authtoken.models import Token
Expand Down Expand Up @@ -81,10 +82,9 @@ class UserData(models.Model):
start_date = models.DateField(blank=True, null=True, verbose_name='Employee start date')
end_date = models.DateField(blank=True, null=True, verbose_name='Employee end date')
current_employee = models.BooleanField(default=True, verbose_name='Is Current Employee')
is_18f_employee = models.BooleanField(default=True, verbose_name='Is 18F Employee')
billable_expectation = models.DecimalField(validators=[MaxValueValidator(limit_value=1)],
default=Decimal(settings.DEFAULT_BILLABLE_EXPECTATION), decimal_places=2, max_digits=3,
verbose_name="Percentage of hours (expressed as a decimal) expected to be billable each week")
help_text="Percentage of hours (expressed as a decimal) expected to be billable each week")
profit_loss_account = models.ForeignKey(
ProfitLossAccount,
on_delete=models.CASCADE,
Expand All @@ -110,6 +110,14 @@ class Meta:
def __str__(self):
return '{0}'.format(self.user)

@cached_property
def is_18f_employee(self):
"""
True if user's current organization is 18F
False if no organization or not named '18F'
"""
return bool(self.organization and self.organization.name == "18F")

@property
def is_active(self):
return self.user.is_active
Expand Down
1 change: 0 additions & 1 deletion tock/employees/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ def test_user_data_form(self):
'start_date': datetime.date.today(),
'end_date': '',
'current_employee': '',
'is_18f_employee': '',
'unit': '',
'profit_loss_account': ProfitLossAccount.objects.first().id,
'billable_expectation': settings.DEFAULT_BILLABLE_EXPECTATION
Expand Down
26 changes: 22 additions & 4 deletions tock/employees/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ def setUp(self):
user=self.regular_user,
start_date= datetime.date(2014, 1, 1),
end_date=datetime.date(2100, 1, 1),
is_18f_employee=True,
current_employee=True,
organization=self.regular_user_org,
unit=self.regular_user_unit
Expand All @@ -88,7 +87,6 @@ def setUp(self):
user=self.inactive_user,
start_date= datetime.date(2014, 1, 1),
end_date=datetime.date(2100, 1, 1),
is_18f_employee=True,
current_employee=True,
organization=self.regular_user_org,
unit=self.regular_user_unit
Expand Down Expand Up @@ -147,7 +145,6 @@ def test_organization_name(self):
"""
userdata = self.regular_user_userdata
self.assertEqual(userdata.organization.name, '18F')
self.assertEqual(userdata.organization_name, '18F')
self.assertEqual(userdata.unit.name, 'Engineering')

def test_organization_name_empty(self):
Expand All @@ -165,7 +162,6 @@ def test_organization_name_empty(self):
start_date= datetime.date(2014, 1, 1),
end_date=datetime.date(2100, 1, 1),
unit=self.regular_user_unit,
is_18f_employee=True,
current_employee=True
)
self.assertEqual(userdata1.organization_name, '')
Expand Down Expand Up @@ -212,3 +208,25 @@ def test_token_is_delete_on_active_is_false(self):
except Token.DoesNotExist:
token_after_save = None
self.assertNotEqual(token_before_save, token_after_save)

def test_is_18f_employee_false_if_no_org(self):
"""False if no org or not named 18F"""
self.regular_user_userdata.organization = None
self.regular_user_userdata.save()
self.assertFalse(self.regular_user_userdata.is_18f_employee)

def test_is_18f_employee_false_if_not_18f(self):
"""False if org not named 18F"""
not_18f = Organization.objects.create(
name='not_18f',
description='not_18f',
active=True
)
self.regular_user_userdata.organization = not_18f
self.regular_user_userdata.save()
self.assertFalse(self.regular_user_userdata.is_18f_employee)

def test_is_18f_employee_true_if_18f(self):
"""True if org is named 18F"""
# Org for `UserData` here defined in UserDataTests.setUp
self.assertTrue(self.regular_user_userdata.is_18f_employee)
Jkrzy marked this conversation as resolved.
Show resolved Hide resolved
Loading