Skip to content

Commit

Permalink
Merge pull request #1070 from 18F/admin-input-tweaks
Browse files Browse the repository at this point in the history
Use DecimalFields for admin inputs
  • Loading branch information
Jkrzy authored Apr 24, 2020
2 parents 5dbccc0 + 2f9119b commit 9554519
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 17 deletions.
9 changes: 6 additions & 3 deletions tock/employees/admin.py
Original file line number Diff line number Diff line change
@@ -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 = []
Expand Down
3 changes: 2 additions & 1 deletion tock/employees/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 4 additions & 3 deletions tock/employees/tests/test_admin.py
Original file line number Diff line number Diff line change
@@ -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',
Expand Down Expand Up @@ -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())
Expand Down
24 changes: 15 additions & 9 deletions tock/hours/admin.py
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion tock/hours/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tock/tock/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 9554519

Please sign in to comment.