diff --git a/tock/employees/admin.py b/tock/employees/admin.py index 43910648b..741a65b04 100644 --- a/tock/employees/admin.py +++ b/tock/employees/admin.py @@ -1,11 +1,14 @@ -from django.contrib import admin from django import forms - -from .models import UserData, EmployeeGrade +from django.conf import settings +from django.contrib import admin from hours.admin import TimecardPrefillDataInline +from .models import EmployeeGrade, UserData + class UserDataForm(forms.ModelForm): + billable_expectation = forms.DecimalField(initial=settings.DEFAULT_BILLABLE_EXPECTATION) + class Meta: model = UserData exclude = [] diff --git a/tock/employees/models.py b/tock/employees/models.py index c97bcd9ad..78b9d6488 100644 --- a/tock/employees/models.py +++ b/tock/employees/models.py @@ -2,6 +2,7 @@ from decimal import Decimal from django.apps import apps +from django.conf import settings from django.contrib.auth import get_user_model from django.core.validators import MaxValueValidator from django.db import IntegrityError, models @@ -82,7 +83,7 @@ class UserData(models.Model): 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(0.80), decimal_places=2, max_digits=3, + 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") profit_loss_account = models.ForeignKey( ProfitLossAccount, diff --git a/tock/employees/tests/test_admin.py b/tock/employees/tests/test_admin.py index f6b4bb28d..2aaf1edcb 100644 --- a/tock/employees/tests/test_admin.py +++ b/tock/employees/tests/test_admin.py @@ -1,11 +1,12 @@ import datetime -from django.test import TestCase +from django.conf import settings from django.contrib.auth.models import User - +from django.test import TestCase from employees.admin import UserDataForm from projects.models import ProfitLossAccount + class TestUserDataForm(TestCase): fixtures = [ 'employees/fixtures/user_data.json', @@ -34,7 +35,7 @@ def test_user_data_form(self): 'is_18f_employee': '', 'unit': '', 'profit_loss_account': ProfitLossAccount.objects.first().id, - 'billable_expectation': 0.80 + 'billable_expectation': settings.DEFAULT_BILLABLE_EXPECTATION } form = UserDataForm(data=form_data) self.assertTrue(form.is_valid()) diff --git a/tock/hours/admin.py b/tock/hours/admin.py index 9f4ae3c81..c98a21c03 100644 --- a/tock/hours/admin.py +++ b/tock/hours/admin.py @@ -1,19 +1,16 @@ from decimal import Decimal +from django.conf import settings from django.contrib import admin from django.core.exceptions import ValidationError +from django.forms import DecimalField, ModelForm from django.forms.models import BaseInlineFormSet - -from .models import ( - HolidayPrefills, - ReportingPeriod, - Timecard, - TimecardNote, - TimecardObject, - TimecardPrefillData -) from employees.models import UserData +from .models import (HolidayPrefills, ReportingPeriod, Timecard, TimecardNote, + TimecardObject, TimecardPrefillData) + + class ReportingPeriodListFilter(admin.SimpleListFilter): parameter_name = 'reporting_period' title = 'Reporting Period' @@ -77,11 +74,20 @@ class TimecardObjectInline(admin.TabularInline): ] +class TimecardAdminForm(ModelForm): + billable_expectation = DecimalField(initial=settings.DEFAULT_BILLABLE_EXPECTATION) + + class Meta: + model = Timecard + fields = '__all__' + + class TimecardAdmin(admin.ModelAdmin): inlines = (TimecardObjectInline,) list_display = ('user', 'reporting_period', 'submitted') list_filter = (ReportingPeriodListFilter, 'reporting_period',) search_fields = ['user__username', 'reporting_period__start_date', 'reporting_period__end_date',] + form = TimecardAdminForm class TimecardNoteAdmin(admin.ModelAdmin): diff --git a/tock/hours/models.py b/tock/hours/models.py index ca18a748d..f2d43a23a 100644 --- a/tock/hours/models.py +++ b/tock/hours/models.py @@ -234,7 +234,7 @@ class Timecard(models.Model): created = models.DateTimeField(auto_now_add=True) modified = models.DateTimeField(auto_now=True) billable_expectation = models.DecimalField(validators=[MaxValueValidator(limit_value=1)], - default=Decimal(0.80), decimal_places=2, max_digits=3, + default=Decimal(settings.DEFAULT_BILLABLE_EXPECTATION), decimal_places=2, max_digits=3, verbose_name="Percentage of hours which are expected to be billable this week") # Utilization reporting diff --git a/tock/tock/settings/base.py b/tock/tock/settings/base.py index e768176d5..fdd641b71 100644 --- a/tock/tock/settings/base.py +++ b/tock/tock/settings/base.py @@ -139,3 +139,4 @@ STARTING_FY_FOR_REPORTS_PAGE = 2019 RECENT_TIMECARDS_FOR_BILLABILITY = 4 HOURS_IN_A_REGULAR_WORK_WEEK = 40 +DEFAULT_BILLABLE_EXPECTATION = 0.80