From: Tollef Fog Heen Date: Sun, 3 Jun 2012 13:23:41 +0000 (+0200) Subject: Make it possible to find the sum of an invoice X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a6f5c3773a08eafc1998cfb9a92cc8960a8cb190;p=peojumk Make it possible to find the sum of an invoice --- diff --git a/invoice/models.py b/invoice/models.py index 64f0710..ef2b8cd 100644 --- a/invoice/models.py +++ b/invoice/models.py @@ -1,4 +1,5 @@ from django.db import models +from django.db.models import Sum from invoice import settings from django.utils.translation import ugettext as _ @@ -23,6 +24,11 @@ class Invoice(models.Model): date = models.DateField() currency = models.CharField(max_length = 10) + def _total_sum(self): + return self.invoiceline_set.aggregate(total=Sum("amount"))["total"] + + total_sum = property(_total_sum) + class VAT(models.Model): """ Model representing different taxes to be used in Invoices""" name = models.CharField(_('name'), max_length=255)