diff options
author | luxagraf <sng@luxagraf.net> | 2018-09-05 10:28:10 -0500 |
---|---|---|
committer | luxagraf <sng@luxagraf.net> | 2018-09-05 10:28:10 -0500 |
commit | 7c5521b47e8fa3aa2f768571959f45e4fdcccf00 (patch) | |
tree | 68ad88c83cfba7c94e422ba88300c4a508121a02 /app/income/models.py | |
parent | d9ad3291581f8fb48e9fe6a892a498434f1e6b64 (diff) |
added total price to admin display
Diffstat (limited to 'app/income/models.py')
-rw-r--r-- | app/income/models.py | 27 |
1 files changed, 26 insertions, 1 deletions
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) |