fix(report): handle nonetype error in timesheet billing summary grouping logic

(cherry picked from commit 9a7209e668)
This commit is contained in:
Poovetha
2026-07-16 23:47:24 +05:30
committed by Mergify
parent 0d53f1adb7
commit b7cf3bf641

View File

@@ -116,31 +116,37 @@ def get_data(filters, group_fieldname=None):
def group_by(data, fieldname): def group_by(data, fieldname):
groups = {row.get(fieldname) for row in data} groups = {}
grouped_data = [] for row in data:
for group in sorted(groups): groups.setdefault(row.get(fieldname), []).append(row)
group_row = {
fieldname: group,
"hours": sum(row.get("hours") for row in data if row.get(fieldname) == group),
"billing_hours": sum(row.get("billing_hours") for row in data if row.get(fieldname) == group),
"billing_amount": sum(row.get("billing_amount") for row in data if row.get(fieldname) == group),
"indent": 0,
"is_group": 1,
}
if fieldname == "employee":
group_row["employee_name"] = next(
row.get("employee_name") for row in data if row.get(fieldname) == group
)
grouped_data.append(group_row) grouped_data = []
for row in data: for group in sorted(groups, key=lambda g: (g is None, g)):
if row.get(fieldname) != group: hours = billing_hours = billing_amount = 0
continue child_rows = []
for row in groups[group]:
hours += row.get("hours") or 0
billing_hours += row.get("billing_hours") or 0
billing_amount += row.get("billing_amount") or 0
_row = row.copy() _row = row.copy()
_row[fieldname] = None _row[fieldname] = None
_row["indent"] = 1 _row["indent"] = 1
_row["is_group"] = 0 _row["is_group"] = 0
grouped_data.append(_row) child_rows.append(_row)
group_row = {
fieldname: group,
"hours": hours,
"billing_hours": billing_hours,
"billing_amount": billing_amount,
"indent": 0,
"is_group": 1,
}
if fieldname == "employee":
group_row["employee_name"] = groups[group][0].get("employee_name")
grouped_data.append(group_row)
grouped_data.extend(child_rows)
return grouped_data return grouped_data