Skip to content

Commit

Permalink
ut
Browse files Browse the repository at this point in the history
  • Loading branch information
marekbiczysko committed Dec 11, 2024
1 parent 5f3a6f1 commit d9353a3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 25 deletions.
4 changes: 2 additions & 2 deletions src/hct_mis_api/apps/grievance/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -132,7 +132,7 @@ class Meta:
)
household = None
individual = None
payment_obj = None
payment = None


class GrievanceComplaintTicketWithoutExtrasFactory(DjangoModelFactory):
Expand Down
29 changes: 6 additions & 23 deletions src/hct_mis_api/apps/payment/services/dashboard_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,19 @@ 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()
inner_params |= Q(
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()
Expand All @@ -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(
Expand All @@ -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 {
Expand Down

0 comments on commit d9353a3

Please sign in to comment.