-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: wire up dashboard summary numbers
- Loading branch information
1 parent
e847150
commit 29aa6b4
Showing
5 changed files
with
151 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from django.contrib.auth import get_user_model | ||
from django.db.models import Sum | ||
from django.utils import timezone | ||
|
||
from fahari.ops.models import DailyUpdate | ||
|
||
from .constants import WHITELIST_COUNTIES | ||
from .models import Facility | ||
|
||
User = get_user_model() | ||
|
||
|
||
def get_fahari_facilities_queryset(): | ||
return Facility.objects.filter( | ||
is_fahari_facility=True, | ||
operation_status="Operational", | ||
county__in=WHITELIST_COUNTIES, | ||
active=True, | ||
) | ||
|
||
|
||
def get_active_facility_count(user): | ||
return ( | ||
get_fahari_facilities_queryset() | ||
.filter( | ||
organisation=user.organisation, | ||
) | ||
.count() | ||
) | ||
|
||
|
||
def get_open_ticket_count(user): | ||
from fahari.ops.models import FacilitySystemTicket | ||
|
||
return FacilitySystemTicket.objects.filter( | ||
resolved__isnull=True, | ||
active=True, | ||
organisation=user.organisation, | ||
).count() | ||
|
||
|
||
def get_active_user_count(user): | ||
return User.objects.filter( | ||
is_approved=True, | ||
approval_notified=True, | ||
organisation=user.organisation, | ||
).count() | ||
|
||
|
||
def get_appointments_mtd(user): | ||
today = timezone.datetime.today() | ||
year = today.year | ||
month = today.month | ||
qs = DailyUpdate.objects.filter( | ||
active=True, | ||
date__year=year, | ||
date__month=month, | ||
organisation=user.organisation, | ||
).aggregate(Sum("total")) | ||
return qs["total__sum"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import random | ||
|
||
import pytest | ||
from django.contrib.auth import get_user_model | ||
from django.utils import timezone | ||
from model_bakery import baker | ||
|
||
from fahari.common.constants import WHITELIST_COUNTIES | ||
from fahari.common.dashboard import ( | ||
get_active_facility_count, | ||
get_active_user_count, | ||
get_appointments_mtd, | ||
get_open_ticket_count, | ||
) | ||
from fahari.common.models import Facility | ||
from fahari.ops.models import DailyUpdate, FacilitySystemTicket | ||
|
||
User = get_user_model() | ||
|
||
pytestmark = pytest.mark.django_db | ||
|
||
|
||
def test_get_active_facility_count(user): | ||
baker.make( | ||
Facility, | ||
is_fahari_facility=True, | ||
operation_status="Operational", | ||
county=random.choice(WHITELIST_COUNTIES), | ||
active=True, | ||
organisation=user.organisation, | ||
) | ||
assert get_active_facility_count(user) == 1 | ||
|
||
|
||
def test_get_open_ticket_count(user): | ||
baker.make( | ||
FacilitySystemTicket, | ||
resolved=None, | ||
active=True, | ||
organisation=user.organisation, | ||
) | ||
assert get_open_ticket_count(user) == 1 | ||
|
||
|
||
def test_get_active_user_count(user): | ||
baker.make( | ||
User, | ||
is_approved=True, | ||
approval_notified=True, | ||
organisation=user.organisation, | ||
) | ||
assert get_active_user_count(user) >= 1 | ||
|
||
|
||
def test_get_appointments_mtd(user): | ||
today = timezone.datetime.today() | ||
baker.make( | ||
DailyUpdate, | ||
active=True, | ||
date=today, | ||
total=999, | ||
organisation=user.organisation, | ||
) | ||
assert get_appointments_mtd(user) == 999 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters