# 175 Report law calculation bugfix
* fixes bug where amount of used laws in intervention forms would not be calculated properly
This commit is contained in:
parent
f6dcb6c6db
commit
f19ad5f639
@ -137,22 +137,36 @@ class TimespanReport:
|
|||||||
).order_by(
|
).order_by(
|
||||||
"long_name"
|
"long_name"
|
||||||
)
|
)
|
||||||
# Fetch all law ids which are used by any .legal object of an intervention object
|
|
||||||
intervention_laws_total = self.queryset.values_list("legal__laws__id")
|
evaluated_laws = []
|
||||||
intervention_laws_checked = self.queryset.filter(checked__isnull=False).values_list("legal__laws__id")
|
sum_num_checked = 0
|
||||||
intervention_laws_recorded = self.queryset.filter(recorded__isnull=False).values_list(
|
sum_num_recorded = 0
|
||||||
"legal__laws__id")
|
sum_num = 0
|
||||||
# Count how often which law id appears in the above list, return only the long_name of the law and the resulting
|
for law in laws:
|
||||||
# count (here 'num'). This is for keeping the db fetch as small as possible
|
num = self.queryset.filter(
|
||||||
# Compute the sum for total, checked and recorded
|
legal__laws__atom_id=law.atom_id
|
||||||
self.evaluated_laws = laws.annotate(
|
).count()
|
||||||
num=Count("id", filter=Q(id__in=intervention_laws_total)),
|
num_checked = self.queryset_checked.filter(
|
||||||
num_checked=Count("id", filter=Q(id__in=intervention_laws_checked)),
|
legal__laws__atom_id=law.atom_id
|
||||||
num_recorded=Count("id", filter=Q(id__in=intervention_laws_recorded)),
|
).count()
|
||||||
).values_list("short_name", "long_name", "num_checked", "num_recorded", "num", named=True)
|
num_recorded = self.queryset_recorded.filter(
|
||||||
self.law_sum = self.evaluated_laws.aggregate(sum_num=Sum("num"))["sum_num"]
|
legal__laws__atom_id=law.atom_id
|
||||||
self.law_sum_checked = self.evaluated_laws.aggregate(sum_num_checked=Sum("num_checked"))["sum_num_checked"]
|
).count()
|
||||||
self.law_sum_recorded = self.evaluated_laws.aggregate(sum_num_recorded=Sum("num_recorded"))["sum_num_recorded"]
|
evaluated_laws.append({
|
||||||
|
"short_name": law.short_name,
|
||||||
|
"long_name": law.long_name,
|
||||||
|
"num": num,
|
||||||
|
"num_checked": num_checked,
|
||||||
|
"num_recorded": num_recorded,
|
||||||
|
})
|
||||||
|
sum_num += num
|
||||||
|
sum_num_checked += num_checked
|
||||||
|
sum_num_recorded += num_recorded
|
||||||
|
|
||||||
|
self.evaluated_laws = evaluated_laws
|
||||||
|
self.law_sum = sum_num
|
||||||
|
self.law_sum_checked = sum_num_checked
|
||||||
|
self.law_sum_recorded = sum_num_recorded
|
||||||
|
|
||||||
def _evaluate_compensations(self):
|
def _evaluate_compensations(self):
|
||||||
""" Analyzes the types of compensation distribution
|
""" Analyzes the types of compensation distribution
|
||||||
|
Loading…
Reference in New Issue
Block a user