]> err.no Git - peojumk/commitdiff
Make it possible to find the sum of an invoice
authorTollef Fog Heen <tfheen@err.no>
Sun, 3 Jun 2012 13:23:41 +0000 (15:23 +0200)
committerTollef Fog Heen <tfheen@err.no>
Sun, 3 Jun 2012 13:23:41 +0000 (15:23 +0200)
invoice/models.py

index 64f07105a843085d01288c43ad308c43889d324b..ef2b8cd9912c88a2dd300f2d8c38b8e7716952fd 100644 (file)
@@ -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)