Merge pull request #21519 from nextchamp-saqib/sales-report-total-row
chore: add total row in sales analytics report
This commit is contained in:
commit
e684727923
@ -1,31 +1,31 @@
|
|||||||
{
|
{
|
||||||
"add_total_row": 0,
|
"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,
|
||||||
"docstatus": 0,
|
"docstatus": 0,
|
||||||
"doctype": "Report",
|
"doctype": "Report",
|
||||||
"idx": 0,
|
"idx": 0,
|
||||||
"is_standard": "Yes",
|
"is_standard": "Yes",
|
||||||
"modified": "2019-05-24 05:37:02.866139",
|
"modified": "2020-04-30 19:49:02.303320",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Selling",
|
"module": "Selling",
|
||||||
"name": "Sales Analytics",
|
"name": "Sales Analytics",
|
||||||
"owner": "Administrator",
|
"owner": "Administrator",
|
||||||
"prepared_report": 0,
|
"prepared_report": 0,
|
||||||
"ref_doctype": "Sales Order",
|
"ref_doctype": "Sales Order",
|
||||||
"report_name": "Sales Analytics",
|
"report_name": "Sales Analytics",
|
||||||
"report_type": "Script Report",
|
"report_type": "Script Report",
|
||||||
"roles": [
|
"roles": [
|
||||||
{
|
{
|
||||||
"role": "Stock User"
|
"role": "Stock User"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"role": "Maintenance User"
|
"role": "Maintenance User"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"role": "Accounts User"
|
"role": "Accounts User"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"role": "Sales Manager"
|
"role": "Sales Manager"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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,6 +220,8 @@ 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 = []
|
||||||
@ -232,8 +240,10 @@ 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
|
||||||
|
|
||||||
row["total"] = total
|
row["total"] = total
|
||||||
out = [row] + out
|
out = [row] + out
|
||||||
|
|
||||||
self.data = out
|
self.data = out
|
||||||
|
|
||||||
def get_periodic_data(self):
|
def get_periodic_data(self):
|
||||||
|
|||||||
@ -33,6 +33,21 @@ class TestAnalytics(unittest.TestCase):
|
|||||||
report = execute(filters)
|
report = execute(filters)
|
||||||
|
|
||||||
expected_data = [
|
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": "_Test Customer 1",
|
||||||
"entity_name": "_Test Customer 1",
|
"entity_name": "_Test Customer 1",
|
||||||
@ -134,6 +149,21 @@ class TestAnalytics(unittest.TestCase):
|
|||||||
report = execute(filters)
|
report = execute(filters)
|
||||||
|
|
||||||
expected_data = [
|
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": "_Test Customer 1",
|
||||||
"entity_name": "_Test Customer 1",
|
"entity_name": "_Test Customer 1",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user