diff options
Diffstat (limited to 'app/income')
-rw-r--r-- | app/income/admin.py | 2 | ||||
-rw-r--r-- | app/income/models.py | 27 |
2 files changed, 27 insertions, 2 deletions
diff --git a/app/income/admin.py b/app/income/admin.py index 6399463..b165371 100644 --- a/app/income/admin.py +++ b/app/income/admin.py @@ -16,7 +16,7 @@ class InvoiceItemAdmin(admin.ModelAdmin): @admin.register(Invoice) class InvoiceAdmin(admin.ModelAdmin): - list_display = ('title', 'date_start', 'date_end') + list_display = ('title', 'admin_link', 'date_start', 'date_end') @admin.register(Gig) diff --git a/app/income/models.py b/app/income/models.py index 77a6d24..688d1d7 100644 --- a/app/income/models.py +++ b/app/income/models.py @@ -1,6 +1,9 @@ import datetime +from datetime import timedelta from django.db import models from django.utils import timezone +from django.urls import reverse +from django.utils.html import format_html from resume.models import PubItem, Publisher @@ -49,12 +52,17 @@ class Gig(models.Model): class Invoice(models.Model): title = models.CharField(max_length=200) + slug = models.SlugField() date_start = models.DateField(null=True, blank=True) date_end = models.DateField(null=True, blank=True) def __str__(self): return self.title + def admin_link(self): + return format_html('<a href="/admin/income/invoice/monthlyview/%s/">View Invoice</a>' % (self.slug)) + admin_link.short_description = 'Invoice' + class InvoiceItem(models.Model): time_start = models.DateTimeField(null=True, blank=True) @@ -62,8 +70,25 @@ class InvoiceItem(models.Model): work_done = models.TextField(null=True, blank=True) def __str__(self): - return self.time_start + return str(self.time_start) @property def total(self): return self.time_end - self.time_start + + @property + def rounded_total(self): + """ + Rounds the given timedelta by the given timedelta period + :param td: `timedelta` to round + :param period: `timedelta` period to round by. + """ + period = timedelta(minutes=15) + td = self.total + period_seconds = period.total_seconds() + half_period_seconds = period_seconds / 2 + remainder = td.total_seconds() % period_seconds + if remainder >= half_period_seconds: + return timedelta(seconds=td.total_seconds() + (period_seconds - remainder)) + else: + return timedelta(seconds=td.total_seconds() - remainder) |