-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WC2-523: [WEB] NFC card field shows 0 for all beneficiaries even when card is assigned #1735
Changes from all commits
fb90b66
87de15b
7c6d429
ba47e1e
4736144
1a54b26
c331734
a5621a2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,4 +35,5 @@ export type Beneficiary = { | |
duplicates: number[]; | ||
latitude?: number; | ||
longitude?: number; | ||
nfc_cards?: number; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,9 +7,10 @@ | |
from time import gmtime, strftime | ||
from typing import Any, List, Union | ||
|
||
from iaso.models.storage import StorageDevice, StorageLogEntry | ||
import xlsxwriter # type: ignore | ||
from django.core.paginator import Paginator | ||
from django.db.models import Exists, Max, OuterRef, Q | ||
from django.db.models import Exists, Max, OuterRef, Q, Count | ||
from django.db.models.functions import Coalesce | ||
from django.http import HttpResponse, JsonResponse, StreamingHttpResponse | ||
from django.shortcuts import get_object_or_404 | ||
|
@@ -51,13 +52,15 @@ class Meta: | |
"submitter", | ||
"org_unit", | ||
"duplicates", | ||
"nfc_cards", | ||
] | ||
|
||
entity_type_name = serializers.SerializerMethodField() | ||
attributes = serializers.SerializerMethodField() | ||
submitter = serializers.SerializerMethodField() | ||
org_unit = serializers.SerializerMethodField() | ||
duplicates = serializers.SerializerMethodField() | ||
nfc_cards = serializers.SerializerMethodField() | ||
|
||
def get_attributes(self, entity: Entity): | ||
if entity.attributes: | ||
|
@@ -80,6 +83,13 @@ def get_submitter(self, entity: Entity): | |
def get_duplicates(self, entity: Entity): | ||
return _get_duplicates(entity) | ||
|
||
def get_nfc_cards(self, entity: Entity): | ||
nfc_log_entries_count = StorageDevice.objects.filter(entity=entity, type=StorageDevice.NFC).aggregate( | ||
total_logs=Count("log_entries") | ||
)["total_logs"] | ||
|
||
return nfc_log_entries_count or 0 | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should be careful to add this extra query on the EntitySerializer. I also expect the amount of records in |
||
@staticmethod | ||
def get_entity_type_name(obj: Entity): | ||
return obj.entity_type.name if obj.entity_type else None | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -388,8 +388,9 @@ def create(self, _, request): | |
concerned_orgunit = OrgUnit.objects.get(id=log_data["org_unit_id"]) | ||
|
||
concerned_entity = None | ||
if "entity_id" in log_data and log_data["entity_id"] is not None: | ||
concerned_entity = Entity.objects.get(uuid=log_data["entity_id"]) | ||
entity_id = log_data.get("entity_id") or log_data.get("entity_uuid") | ||
if entity_id: | ||
concerned_entity = Entity.objects.get(uuid=entity_id) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
||
account = user.iaso_profile.account | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Looking good to me 👍