Permalink
Browse files

add time tracking app (tm) models

  • Loading branch information...
1 parent 529eed5 commit e5d9f5f2de210d71c91f0b7c384643cac5f17d5e @senko senko committed Oct 8, 2012
Showing with 65 additions and 0 deletions.
  1. +1 −0 people/settings/base.py
  2. 0 track/__init__.py
  3. +44 −0 track/models.py
  4. +20 −0 track/tests.py
View
@@ -136,6 +136,7 @@ def ensure_secret_key_file():
'core',
'pm',
'hr',
+ 'track',
)
# Get the SENTRY_DSN from your project settings page in Sentry (either self
View
No changes.
View
@@ -0,0 +1,44 @@
+from django.db import models
+import datetime
+from decimal import Decimal
+
+from core.models.base import BaseTemporalModel
+from core.models.person import Person
+from pm.models import Project
+
+__all__ = ['Activity', 'TimeEntry']
+
+
+class Activity(models.Model):
+ name = models.CharField(max_length=255, unique=True)
+ is_billable = models.BooleanField(blank=True, default=False)
+ is_active = models.BooleanField(blank=True, default=True)
+
+ def __unicode__(self):
+ return self.name # pragma: no cover
+
+
+class TimeEntry(BaseTemporalModel):
+ person = models.ForeignKey(Person, editable=False,
+ related_name='time_entries')
+ project = models.ForeignKey(Project, blank=True, null=True,
+ related_name='time_entries')
+ activity = models.ForeignKey(Activity, blank=True, null=True,
+ related_name='time_entries')
+ is_billable = models.BooleanField(blank=True, default=False)
+ description = models.CharField(max_length=255, blank=True, null=True)
+
+ # FIXME: do we want additional tagging of time entries? if so, uncomment:
+ # tags = TaggableManager()
+
+ def __unicode__(self):
+ return '%.1f' % self.hours # pragma: no cover
+
+ @property
+ def hours(self):
+ if not self.start:
+ return Decimal(0)
+
+ end = self.end if self.end else datetime.datetime.now()
+ duration = (end - self.start).total_seconds()
+ return Decimal(duration) / Decimal(3600)
View
@@ -0,0 +1,20 @@
+from django.test import TestCase
+import datetime
+from decimal import Decimal
+
+from .models import *
+
+
+class TimeEntryTest(TestCase):
+
+ def setUp(self):
+ self.now = datetime.datetime.now()
+
+ def test_hours_notstarted(self):
+ t = TimeEntry()
+ self.assertEqual(t.hours, Decimal(0))
+
+ def test_hours(self):
+ t = TimeEntry(start=self.now,
+ end=self.now + datetime.timedelta(seconds=12600))
+ self.assertEqual(t.hours, Decimal('3.5'))

0 comments on commit e5d9f5f

Please sign in to comment.