Merge pull request #21519 from nextchamp-saqib/sales-report-total-row

chore: add total row in sales analytics report
This commit is contained in:
Deepesh Garg 2020-05-11 17:07:59 +05:30 committed by GitHub
commit e684727923
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 60 additions and 20 deletions

View File

@ -1,31 +1,31 @@
{
"add_total_row": 0,
"creation": "2018-09-21 12:46:29.451048",
"disable_prepared_report": 0,
"disabled": 0,
"docstatus": 0,
"doctype": "Report",
"idx": 0,
"is_standard": "Yes",
"modified": "2019-05-24 05:37:02.866139",
"modified_by": "Administrator",
"module": "Selling",
"name": "Sales Analytics",
"owner": "Administrator",
"prepared_report": 0,
"ref_doctype": "Sales Order",
"report_name": "Sales Analytics",
"report_type": "Script Report",
"add_total_row": 0,
"creation": "2018-09-21 12:46:29.451048",
"disable_prepared_report": 0,
"disabled": 0,
"docstatus": 0,
"doctype": "Report",
"idx": 0,
"is_standard": "Yes",
"modified": "2020-04-30 19:49:02.303320",
"modified_by": "Administrator",
"module": "Selling",
"name": "Sales Analytics",
"owner": "Administrator",
"prepared_report": 0,
"ref_doctype": "Sales Order",
"report_name": "Sales Analytics",
"report_type": "Script Report",
"roles": [
{
"role": "Stock User"
},
},
{
"role": "Maintenance User"
},
},
{
"role": "Accounts User"
},
},
{
"role": "Sales Manager"
}

View File

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

View File

@ -33,6 +33,21 @@ class TestAnalytics(unittest.TestCase):
report = execute(filters)
expected_data = [
{
'entity': 'Total',
'apr_2017': 0.0,
'may_2017': 0.0,
'jun_2017': 2000.0,
'jul_2017': 1000.0,
'aug_2017': 0.0,
'sep_2017': 1500.0,
'oct_2017': 1000.0,
'nov_2017': 0.0,
'dec_2017': 0.0,
'jan_2018': 0.0,
'feb_2018': 2000.0,
'mar_2018': 0.0
},
{
"entity": "_Test Customer 1",
"entity_name": "_Test Customer 1",
@ -134,6 +149,21 @@ class TestAnalytics(unittest.TestCase):
report = execute(filters)
expected_data = [
{
'entity': 'Total',
'apr_2017': 0.0,
'may_2017': 0.0,
'jun_2017': 20.0,
'jul_2017': 10.0,
'aug_2017': 0.0,
'sep_2017': 15.0,
'oct_2017': 10.0,
'nov_2017': 0.0,
'dec_2017': 0.0,
'jan_2018': 0.0,
'feb_2018': 20.0,
'mar_2018': 0.0
},
{
"entity": "_Test Customer 1",
"entity_name": "_Test Customer 1",