fix: trends report total mismatch with group filters

(cherry picked from commit f7d09f8760)
This commit is contained in:
diptanilsaha
2025-11-07 12:08:22 +05:30
committed by Mergify
parent 4f02677d6f
commit 7e3f30baad
8 changed files with 206 additions and 145 deletions

View File

@@ -1,32 +1,37 @@
{ {
"add_total_row": 1, "add_total_row": 0,
"apply_user_permissions": 1, "add_translate_data": 0,
"creation": "2013-06-13 18:46:55", "columns": [],
"disabled": 0, "creation": "2013-06-13 18:46:55",
"docstatus": 0, "disabled": 0,
"doctype": "Report", "docstatus": 0,
"idx": 3, "doctype": "Report",
"is_standard": "Yes", "filters": [],
"modified": "2018-02-21 01:28:31.261299", "idx": 3,
"modified_by": "Administrator", "is_standard": "Yes",
"module": "Accounts", "letterhead": null,
"name": "Purchase Invoice Trends", "modified": "2025-11-05 11:55:49.950442",
"owner": "Administrator", "modified_by": "Administrator",
"ref_doctype": "Purchase Invoice", "module": "Accounts",
"report_name": "Purchase Invoice Trends", "name": "Purchase Invoice Trends",
"report_type": "Script Report", "owner": "Administrator",
"prepared_report": 0,
"ref_doctype": "Purchase Invoice",
"report_name": "Purchase Invoice Trends",
"report_type": "Script Report",
"roles": [ "roles": [
{ {
"role": "Accounts User" "role": "Accounts User"
}, },
{ {
"role": "Purchase User" "role": "Purchase User"
}, },
{ {
"role": "Accounts Manager" "role": "Accounts Manager"
}, },
{ {
"role": "Auditor" "role": "Auditor"
} }
] ],
} "timeout": 0
}

View File

@@ -1,26 +1,31 @@
{ {
"add_total_row": 1, "add_total_row": 0,
"apply_user_permissions": 1, "add_translate_data": 0,
"creation": "2013-06-13 18:44:21", "columns": [],
"disabled": 0, "creation": "2013-06-13 18:44:21",
"docstatus": 0, "disabled": 0,
"doctype": "Report", "docstatus": 0,
"idx": 3, "doctype": "Report",
"is_standard": "Yes", "filters": [],
"modified": "2018-02-21 01:28:03.622485", "idx": 3,
"modified_by": "Administrator", "is_standard": "Yes",
"module": "Accounts", "letterhead": null,
"name": "Sales Invoice Trends", "modified": "2025-11-05 11:55:50.070651",
"owner": "Administrator", "modified_by": "Administrator",
"ref_doctype": "Sales Invoice", "module": "Accounts",
"report_name": "Sales Invoice Trends", "name": "Sales Invoice Trends",
"report_type": "Script Report", "owner": "Administrator",
"prepared_report": 0,
"ref_doctype": "Sales Invoice",
"report_name": "Sales Invoice Trends",
"report_type": "Script Report",
"roles": [ "roles": [
{ {
"role": "Accounts Manager" "role": "Accounts Manager"
}, },
{ {
"role": "Accounts User" "role": "Accounts User"
} }
] ],
} "timeout": 0
}

View File

@@ -1,29 +1,34 @@
{ {
"add_total_row": 1, "add_total_row": 0,
"apply_user_permissions": 1, "add_translate_data": 0,
"creation": "2013-06-13 18:45:01", "columns": [],
"disabled": 0, "creation": "2013-06-13 18:45:01",
"docstatus": 0, "disabled": 0,
"doctype": "Report", "docstatus": 0,
"idx": 3, "doctype": "Report",
"is_standard": "Yes", "filters": [],
"modified": "2018-02-21 01:28:37.416562", "idx": 3,
"modified_by": "Administrator", "is_standard": "Yes",
"module": "Buying", "letterhead": null,
"name": "Purchase Order Trends", "modified": "2025-11-05 11:55:50.058154",
"owner": "Administrator", "modified_by": "Administrator",
"ref_doctype": "Purchase Order", "module": "Buying",
"report_name": "Purchase Order Trends", "name": "Purchase Order Trends",
"report_type": "Script Report", "owner": "Administrator",
"prepared_report": 0,
"ref_doctype": "Purchase Order",
"report_name": "Purchase Order Trends",
"report_type": "Script Report",
"roles": [ "roles": [
{ {
"role": "Stock User" "role": "Stock User"
}, },
{ {
"role": "Purchase Manager" "role": "Purchase Manager"
}, },
{ {
"role": "Purchase User" "role": "Purchase User"
} }
] ],
} "timeout": 0
}

View File

@@ -191,6 +191,9 @@ def get_data(filters, conditions):
des[j + inc] = row1[0][j] des[j + inc] = row1[0][j]
data.append(des) data.append(des)
total_row = calculate_total_row(data1, conditions["columns"])
data.append(total_row)
else: else:
data = frappe.db.sql( data = frappe.db.sql(
""" select {} from `tab{}` t1, `tab{} Item` t2 {} """ select {} from `tab{}` t1, `tab{} Item` t2 {}
@@ -214,9 +217,32 @@ def get_data(filters, conditions):
as_list=1, as_list=1,
) )
total_row = calculate_total_row(data, conditions["columns"])
data.append(total_row)
return data 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): def get_mon(dt):
return getdate(dt).strftime("%b") return getdate(dt).strftime("%b")

View File

@@ -1,32 +1,37 @@
{ {
"add_total_row": 1, "add_total_row": 0,
"apply_user_permissions": 1, "add_translate_data": 0,
"creation": "2013-06-07 16:01:16", "columns": [],
"disabled": 0, "creation": "2013-06-07 16:01:16",
"docstatus": 0, "disabled": 0,
"doctype": "Report", "docstatus": 0,
"idx": 3, "doctype": "Report",
"is_standard": "Yes", "filters": [],
"modified": "2018-02-21 01:28:14.928929", "idx": 3,
"modified_by": "Administrator", "is_standard": "Yes",
"module": "Selling", "letterhead": null,
"name": "Quotation Trends", "modified": "2025-11-05 11:55:50.127020",
"owner": "Administrator", "modified_by": "Administrator",
"ref_doctype": "Quotation", "module": "Selling",
"report_name": "Quotation Trends", "name": "Quotation Trends",
"report_type": "Script Report", "owner": "Administrator",
"prepared_report": 0,
"ref_doctype": "Quotation",
"report_name": "Quotation Trends",
"report_type": "Script Report",
"roles": [ "roles": [
{ {
"role": "Sales User" "role": "Sales User"
}, },
{ {
"role": "Sales Manager" "role": "Sales Manager"
}, },
{ {
"role": "Maintenance Manager" "role": "Maintenance Manager"
}, },
{ {
"role": "Maintenance User" "role": "Maintenance User"
} }
] ],
} "timeout": 0
}

View File

@@ -1,35 +1,40 @@
{ {
"add_total_row": 1, "add_total_row": 0,
"apply_user_permissions": 1, "add_translate_data": 0,
"creation": "2013-06-13 18:43:30", "columns": [],
"disabled": 0, "creation": "2013-06-13 18:43:30",
"docstatus": 0, "disabled": 0,
"doctype": "Report", "docstatus": 0,
"idx": 3, "doctype": "Report",
"is_standard": "Yes", "filters": [],
"modified": "2018-02-20 08:05:46.191588", "idx": 3,
"modified_by": "Administrator", "is_standard": "Yes",
"module": "Selling", "letterhead": null,
"name": "Sales Order Trends", "modified": "2025-11-05 11:55:50.096303",
"owner": "Administrator", "modified_by": "Administrator",
"ref_doctype": "Sales Order", "module": "Selling",
"report_name": "Sales Order Trends", "name": "Sales Order Trends",
"report_type": "Script Report", "owner": "Administrator",
"prepared_report": 0,
"ref_doctype": "Sales Order",
"report_name": "Sales Order Trends",
"report_type": "Script Report",
"roles": [ "roles": [
{ {
"role": "Sales User" "role": "Sales User"
}, },
{ {
"role": "Sales Manager" "role": "Sales Manager"
}, },
{ {
"role": "Maintenance User" "role": "Maintenance User"
}, },
{ {
"role": "Accounts User" "role": "Accounts User"
}, },
{ {
"role": "Stock User" "role": "Stock User"
} }
] ],
} "timeout": 0
}

View File

@@ -1,32 +1,37 @@
{ {
"add_total_row": 1, "add_total_row": 0,
"apply_user_permissions": 1, "add_translate_data": 0,
"creation": "2013-06-13 18:42:11", "columns": [],
"disabled": 0, "creation": "2013-06-13 18:42:11",
"docstatus": 0, "disabled": 0,
"doctype": "Report", "docstatus": 0,
"idx": 3, "doctype": "Report",
"is_standard": "Yes", "filters": [],
"modified": "2018-02-21 01:28:47.049042", "idx": 3,
"modified_by": "Administrator", "is_standard": "Yes",
"module": "Stock", "letterhead": null,
"name": "Delivery Note Trends", "modified": "2025-11-05 11:55:50.114173",
"owner": "Administrator", "modified_by": "Administrator",
"ref_doctype": "Delivery Note", "module": "Stock",
"report_name": "Delivery Note Trends", "name": "Delivery Note Trends",
"report_type": "Script Report", "owner": "Administrator",
"prepared_report": 0,
"ref_doctype": "Delivery Note",
"report_name": "Delivery Note Trends",
"report_type": "Script Report",
"roles": [ "roles": [
{ {
"role": "Stock User" "role": "Stock User"
}, },
{ {
"role": "Stock Manager" "role": "Stock Manager"
}, },
{ {
"role": "Sales User" "role": "Sales User"
}, },
{ {
"role": "Accounts User" "role": "Accounts User"
} }
] ],
} "timeout": 0
}

View File

@@ -1,32 +1,37 @@
{ {
"add_total_row": 1, "add_total_row": 0,
"apply_user_permissions": 1, "add_translate_data": 0,
"creation": "2013-06-13 18:45:44", "columns": [],
"disabled": 0, "creation": "2013-06-13 18:45:44",
"docstatus": 0, "disabled": 0,
"doctype": "Report", "docstatus": 0,
"idx": 3, "doctype": "Report",
"is_standard": "Yes", "filters": [],
"modified": "2018-02-21 01:28:22.682161", "idx": 3,
"modified_by": "Administrator", "is_standard": "Yes",
"module": "Stock", "letterhead": null,
"name": "Purchase Receipt Trends", "modified": "2025-11-05 11:55:49.983683",
"owner": "Administrator", "modified_by": "Administrator",
"ref_doctype": "Purchase Receipt", "module": "Stock",
"report_name": "Purchase Receipt Trends", "name": "Purchase Receipt Trends",
"report_type": "Script Report", "owner": "Administrator",
"prepared_report": 0,
"ref_doctype": "Purchase Receipt",
"report_name": "Purchase Receipt Trends",
"report_type": "Script Report",
"roles": [ "roles": [
{ {
"role": "Stock Manager" "role": "Stock Manager"
}, },
{ {
"role": "Stock User" "role": "Stock User"
}, },
{ {
"role": "Purchase User" "role": "Purchase User"
}, },
{ {
"role": "Accounts User" "role": "Accounts User"
} }
] ],
} "timeout": 0
}