From d9353a35a702119b29bff90ee08d8d0bd911d2d5 Mon Sep 17 00:00:00 2001 From: marekbiczysko Date: Wed, 11 Dec 2024 20:19:20 +0100 Subject: [PATCH] ut --- src/hct_mis_api/apps/grievance/fixtures.py | 4 +-- .../payment/services/dashboard_service.py | 29 ++++--------------- 2 files changed, 8 insertions(+), 25 deletions(-) diff --git a/src/hct_mis_api/apps/grievance/fixtures.py b/src/hct_mis_api/apps/grievance/fixtures.py index deaa1e5704..60cf4c7fff 100644 --- a/src/hct_mis_api/apps/grievance/fixtures.py +++ b/src/hct_mis_api/apps/grievance/fixtures.py @@ -79,7 +79,7 @@ class Meta: ) household = None individual = None - payment_obj = None + payment = None @factory.post_generation def create_extras(obj, create: bool, extracted: bool, **kwargs: Any) -> None: @@ -132,7 +132,7 @@ class Meta: ) household = None individual = None - payment_obj = None + payment = None class GrievanceComplaintTicketWithoutExtrasFactory(DjangoModelFactory): diff --git a/src/hct_mis_api/apps/payment/services/dashboard_service.py b/src/hct_mis_api/apps/payment/services/dashboard_service.py index 0cbf026faf..e11d5939bc 100644 --- a/src/hct_mis_api/apps/payment/services/dashboard_service.py +++ b/src/hct_mis_api/apps/payment/services/dashboard_service.py @@ -27,18 +27,12 @@ def payment_verification_chart_query( status_choices_mapping = dict(PaymentVerification.STATUS_CHOICES) params = Q() - params &= Q(Q(payment__delivery_date__year=year) | Q(payment_record__delivery_date__year=year)) - params &= Q( - Q(payment__business_area__slug=business_area_slug) | Q(payment_record__business_area__slug=business_area_slug) - ) - params &= Q( - Q(payment__household__collect_type=collect_type) | Q(payment_record__household__collect_type=collect_type) - ) + params &= Q(payment__delivery_date__year=year) + params &= Q(payment__business_area__slug=business_area_slug) + params &= Q(payment__household__collect_type=collect_type) if program: - params &= Q( - Q(payment__parent__program_cycle__program__id=program) | Q(payment_record__parent__program__id=program) - ) + params &= Q(payment__parent__program_cycle__program__id=program) if administrative_area: inner_params = Q() @@ -46,10 +40,6 @@ def payment_verification_chart_query( Q(payment__household__admin_area__id=administrative_area) & Q(payment__household__admin_area__area_type__area_level=2) ) - inner_params |= Q( - Q(payment_record__household__admin_area__id=administrative_area) - & Q(payment_record__household__admin_area__area_type__area_level=2) - ) params &= inner_params payment_verifications = PaymentVerification.objects.filter(params).distinct() @@ -69,9 +59,7 @@ def payment_verification_chart_query( for (dataset_percentage_value, status) in zip(dataset_percentage, status_choices_mapping.values()) ] - samples_count = payment_verifications.aggregate(payments_count=Count("payment") + Count("payment_record"))[ - "payments_count" - ] + samples_count = payment_verifications.aggregate(payments_count=Count("payment"))["payments_count"] all_payment_records_for_created_verifications = ( Payment.objects.filter(excluded=False, conflicted=False) .filter( @@ -90,12 +78,7 @@ def payment_verification_chart_query( ) households_number = ( - Household.objects.filter( - Q(pk__in=payment_verifications.values("payment__household")) - | Q(pk__in=payment_verifications.values("payment_record__household")) - ) - .distinct() - .count() + Household.objects.filter(Q(pk__in=payment_verifications.values("payment__household"))).distinct().count() ) return {