Fix potential division by zero
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
e7ed349356
commit
cdc6ca1324
|
@ -304,9 +304,17 @@ def stats(request, year: int = 0):
|
||||||
purchased_unfinished = all_purchased_without_refunded_this_year.filter(
|
purchased_unfinished = all_purchased_without_refunded_this_year.filter(
|
||||||
date_finished__isnull=True
|
date_finished__isnull=True
|
||||||
)
|
)
|
||||||
unfinished_purchases_percent = int(
|
if (
|
||||||
purchased_unfinished.count() / all_purchased_refunded_this_year.count() * 100
|
purchased_unfinished.count() == 0
|
||||||
)
|
or all_purchased_refunded_this_year.count() == 0
|
||||||
|
):
|
||||||
|
unfinished_purchases_percent = 0
|
||||||
|
else:
|
||||||
|
unfinished_purchases_percent = int(
|
||||||
|
purchased_unfinished.count()
|
||||||
|
/ all_purchased_refunded_this_year.count()
|
||||||
|
* 100
|
||||||
|
)
|
||||||
|
|
||||||
all_finished_this_year = Purchase.objects.filter(date_finished__year=year).order_by(
|
all_finished_this_year = Purchase.objects.filter(date_finished__year=year).order_by(
|
||||||
"date_finished"
|
"date_finished"
|
||||||
|
|
Loading…
Reference in New Issue