mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-20 23:12:15 +00:00
Increased query efficiency
This commit is contained in:
@@ -13,7 +13,8 @@ class InvoiceIndex(generic.ListView):
|
|||||||
template_name = 'RIGS/invoice_list.html'
|
template_name = 'RIGS/invoice_list.html'
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
active = self.model.objects.filter(void=False).select_related('payment_set')
|
active = self.model.objects.filter(void=False).select_related('payment_set', 'event').prefetch_related(
|
||||||
|
'event__items').defer('event__person', 'event__organisation', 'event__venue', 'event__mic')
|
||||||
set = []
|
set = []
|
||||||
for invoice in active:
|
for invoice in active:
|
||||||
if invoice.balance != 0:
|
if invoice.balance != 0:
|
||||||
|
|||||||
@@ -248,7 +248,7 @@ class Event(models.Model, RevisionMixin):
|
|||||||
@property
|
@property
|
||||||
def sum_total(self):
|
def sum_total(self):
|
||||||
total = 0
|
total = 0
|
||||||
for item in self.items.all():
|
for item in self.items.filter(cost__gt=0):
|
||||||
total += item.total_cost
|
total += item.total_cost
|
||||||
return total
|
return total
|
||||||
|
|
||||||
@@ -329,9 +329,9 @@ class Invoice(models.Model):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def payment_total(self):
|
def payment_total(self):
|
||||||
total = 0
|
total = self.payment_set.aggregate(models.Sum('amount'))
|
||||||
for payment in self.payment_set.all():
|
# for payment in self.payment_set.all():
|
||||||
total += payment.amount
|
# total += payment.amount
|
||||||
return total
|
return total
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -352,11 +352,13 @@ class Payment(models.Model):
|
|||||||
INTERNAL = 'I'
|
INTERNAL = 'I'
|
||||||
EXTERNAL = 'E'
|
EXTERNAL = 'E'
|
||||||
SUCORE = 'SU'
|
SUCORE = 'SU'
|
||||||
|
ADJUSTMENT = 'T'
|
||||||
METHODS = (
|
METHODS = (
|
||||||
(CASH, 'Cash'),
|
(CASH, 'Cash'),
|
||||||
(INTERNAL, 'Internal'),
|
(INTERNAL, 'Internal'),
|
||||||
(EXTERNAL, 'External'),
|
(EXTERNAL, 'External'),
|
||||||
(SUCORE, 'SU Core'),
|
(SUCORE, 'SU Core'),
|
||||||
|
(ADJUSTMENT, 'TEC Adjustment'),
|
||||||
)
|
)
|
||||||
|
|
||||||
invoice = models.ForeignKey('Invoice')
|
invoice = models.ForeignKey('Invoice')
|
||||||
|
|||||||
Reference in New Issue
Block a user