Fix potential division by zero
This commit is contained in:
parent
b8df870cca
commit
cb99d8b656
|
@ -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