chore: calculate total row month-wise in sales analytics

This commit is contained in:
Saqib Ansari 2020-04-30 20:06:30 +05:30
parent 10d9974e77
commit dfa60e0ed8
2 changed files with 19 additions and 2 deletions

View File

@ -1,5 +1,5 @@
{ {
"add_total_row": 1, "add_total_row": 0,
"creation": "2018-09-21 12:46:29.451048", "creation": "2018-09-21 12:46:29.451048",
"disable_prepared_report": 0, "disable_prepared_report": 0,
"disabled": 0, "disabled": 0,
@ -7,7 +7,7 @@
"doctype": "Report", "doctype": "Report",
"idx": 0, "idx": 0,
"is_standard": "Yes", "is_standard": "Yes",
"modified": "2020-04-30 16:27:53.112907", "modified": "2020-04-30 19:49:02.303320",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Selling", "module": "Selling",
"name": "Sales Analytics", "name": "Sales Analytics",

View File

@ -194,6 +194,9 @@ class Analytics(object):
def get_rows(self): def get_rows(self):
self.data = [] self.data = []
self.get_periodic_data() self.get_periodic_data()
total_row = {
"entity": "Total",
}
for entity, period_data in iteritems(self.entity_periodic_data): for entity, period_data in iteritems(self.entity_periodic_data):
row = { row = {
@ -207,6 +210,9 @@ class Analytics(object):
row[scrub(period)] = amount row[scrub(period)] = amount
total += amount total += amount
if not total_row.get(scrub(period)): total_row[scrub(period)] = 0
total_row[scrub(period)] += amount
row["total"] = total row["total"] = total
if self.filters.tree_type == "Item": if self.filters.tree_type == "Item":
@ -214,9 +220,14 @@ class Analytics(object):
self.data.append(row) self.data.append(row)
self.data.append(total_row)
def get_rows_by_group(self): def get_rows_by_group(self):
self.get_periodic_data() self.get_periodic_data()
out = [] out = []
total_row = {
"entity": "Total",
}
for d in reversed(self.group_entries): for d in reversed(self.group_entries):
row = { row = {
@ -232,8 +243,14 @@ class Analytics(object):
self.entity_periodic_data.setdefault(d.parent, frappe._dict()).setdefault(period, 0.0) self.entity_periodic_data.setdefault(d.parent, frappe._dict()).setdefault(period, 0.0)
self.entity_periodic_data[d.parent][period] += amount self.entity_periodic_data[d.parent][period] += amount
total += amount total += amount
if not total_row.get(scrub(period)): total_row[scrub(period)] = 0
total_row[scrub(period)] += amount
row["total"] = total row["total"] = total
out = [row] + out out = [row] + out
out.append(total_row)
self.data = out self.data = out
def get_periodic_data(self): def get_periodic_data(self):