mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-17 05:22:16 +00:00
Improved person/organisation cross referencing via events
This commit is contained in:
@@ -4,6 +4,7 @@ import datetime
|
|||||||
from django.db import models
|
from django.db import models
|
||||||
from django.contrib.auth.models import AbstractUser
|
from django.contrib.auth.models import AbstractUser
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from django.utils.functional import cached_property
|
||||||
import reversion
|
import reversion
|
||||||
|
|
||||||
|
|
||||||
@@ -55,7 +56,7 @@ class Person(models.Model, RevisionMixin):
|
|||||||
@property
|
@property
|
||||||
def organisations(self):
|
def organisations(self):
|
||||||
o = []
|
o = []
|
||||||
for e in self.event_set.all():
|
for e in Event.objects.filter(person=self).select_related('organisation'):
|
||||||
if e.organisation and e.organisation not in o:
|
if e.organisation and e.organisation not in o:
|
||||||
o.append(e.organisation)
|
o.append(e.organisation)
|
||||||
return o
|
return o
|
||||||
@@ -90,7 +91,7 @@ class Organisation(models.Model, RevisionMixin):
|
|||||||
@property
|
@property
|
||||||
def persons(self):
|
def persons(self):
|
||||||
p = []
|
p = []
|
||||||
for e in self.event_set.all():
|
for e in Event.objects.filter(organisation=self).select_related('person'):
|
||||||
if e.person and e.person not in p:
|
if e.person and e.person not in p:
|
||||||
p.append(e.person)
|
p.append(e.person)
|
||||||
return p
|
return p
|
||||||
@@ -248,7 +249,7 @@ class Event(models.Model, RevisionMixin):
|
|||||||
total += item.total_cost
|
total += item.total_cost
|
||||||
return total
|
return total
|
||||||
|
|
||||||
@property
|
@cached_property
|
||||||
def vat_rate(self):
|
def vat_rate(self):
|
||||||
return VatRate.objects.find_rate(self.start_date)
|
return VatRate.objects.find_rate(self.start_date)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user