diff options
author | luxagraf <sng@luxagraf.net> | 2015-11-20 14:21:49 -0500 |
---|---|---|
committer | luxagraf <sng@luxagraf.net> | 2015-11-20 14:21:49 -0500 |
commit | 9412a3793b298daa14179c4f3789fe3ffc46ecba (patch) | |
tree | 68b439a9174522ed96e9262a209032cfd6e11016 /app/income | |
parent | 1167d8086a826a4896cdcb5b36e78eeb1e6e8fb0 (diff) |
About halfway through adding income by month section to admin.
Diffstat (limited to 'app/income')
-rw-r--r-- | app/income/admin.py | 52 |
1 files changed, 49 insertions, 3 deletions
diff --git a/app/income/admin.py b/app/income/admin.py index d8430be..02c01ef 100644 --- a/app/income/admin.py +++ b/app/income/admin.py @@ -1,9 +1,17 @@ +import datetime from django.contrib import admin +from django.db.models import Sum +from django.contrib.admin import helpers +from django.contrib.gis.admin import OSMGeoAdmin +from django.conf.urls import patterns +from django.conf.urls import url +from django.shortcuts import render + from .models import Gig -class GigAdmin(admin.ModelAdmin): +class GigAdmin(OSMGeoAdmin): list_display = ('title', 'status', 'payment_status', 'invoice_date', 'payment', 'publisher', 'pub_date', 'word_count') list_filter = ('publisher', 'status', 'payment_status') fieldsets = ( @@ -11,8 +19,8 @@ class GigAdmin(admin.ModelAdmin): 'fields': ( 'title', 'pitch', - ('payment', 'pay_type','payment_status', 'invoice_date'), - ('status', 'pub_date', 'word_count' ), + ('payment', 'pay_type', 'payment_status', 'invoice_date'), + ('status', 'pub_date', 'word_count'), 'publisher', 'pub_item' ), @@ -24,4 +32,42 @@ class GigAdmin(admin.ModelAdmin): } ), ) + + def get_urls(self): + urls = super(GigAdmin, self).get_urls() + custom_urls = patterns('', + url(r'^monthly/$', + self.admin_site.admin_view(self.get_monthly), + name='monthly_admin') + ) + return custom_urls + urls + + def get_monthly(self, request): + context = { + 'title': ("This month's income"), + 'app_label': self.model._meta.app_label, + 'opts': self.model._meta, + 'has_change_permission': self.has_change_permission(request) + } + try: + year = request.GET["m"].split("-")[0] + month = request.GET["m"].split("-")[1] + except: + year = datetime.datetime.now().strftime('%Y') + month = datetime.datetime.now().strftime('%m') + qs = self.model.objects.filter( + created__year=year, + created__month=month, + status__in=[1, 2, 3] + ) + context['date'] = datetime.datetime.now() + context['billed'] = qs.filter(payment_status=1) + context['billed_total'] = qs.filter(payment_status=1).aggregate(total_payment=Sum('payment')) + context['unbilled'] = qs.filter(payment_status=0) + context['unbilled_total'] = qs.filter(payment_status=0).aggregate(total_payment=Sum('payment')) + context['total_outstanding'] = qs.aggregate(total_payment=Sum('payment')) + context['months'] = self.model.objects.dates('created', 'month') + return render(request, 'admin/income_month.html', context) + + admin.site.register(Gig, GigAdmin) |