fix: trends report total mismatch with group filters

This commit is contained in:
diptanilsaha
2025-11-07 12:08:22 +05:30
parent 7285eaf633
commit f7d09f8760
8 changed files with 206 additions and 145 deletions

View File

@@ -191,6 +191,9 @@ def get_data(filters, conditions):
des[j + inc] = row1[0][j]
data.append(des)
total_row = calculate_total_row(data1, conditions["columns"])
data.append(total_row)
else:
data = frappe.db.sql(
""" select {} from `tab{}` t1, `tab{} Item` t2 {}
@@ -214,9 +217,32 @@ def get_data(filters, conditions):
as_list=1,
)
total_row = calculate_total_row(data, conditions["columns"])
data.append(total_row)
return data
def calculate_total_row(data, columns):
def wrap_in_quotes(label):
return f"'{label}'"
total_values = {}
for i, col in enumerate(columns):
if "Float" in col or "Currency/currency" in col:
total_values[i] = 0
for row in data:
for i in total_values.keys():
total_values[i] += row[i] if row[i] is not None else 0
total_row = [wrap_in_quotes(_("Total"))]
for i in range(1, len(columns)):
total_row.append(total_values.get(i, None))
return total_row
def get_mon(dt):
return getdate(dt).strftime("%b")