Pie chart for ageing analysis in accounts receivale/payable

This commit is contained in:
Nabin Hait 2016-05-20 11:43:30 +05:30
parent 8ed2f87480
commit 28bdff5a55

View File

@ -16,7 +16,10 @@ class ReceivablePayableReport(object):
def run(self, args):
party_naming_by = frappe.db.get_value(args.get("naming_by")[0], None, args.get("naming_by")[1])
return self.get_columns(party_naming_by, args), self.get_data(party_naming_by, args)
columns = self.get_columns(party_naming_by, args)
data = self.get_data(party_naming_by, args)
graph_data = self.get_graph_data(columns, data)
return columns, data, None, graph_data
def get_columns(self, party_naming_by, args):
columns = [_("Posting Date") + ":Date:80", _(args.get("party_type")) + ":Link/" + args.get("party_type") + ":200"]
@ -39,6 +42,8 @@ class ReceivablePayableReport(object):
})
columns += [_("Age (Days)") + ":Int:80"]
self.ageing_col_idx_start = len(columns)
if not "range1" in self.filters:
self.filters["range1"] = "30"
@ -46,7 +51,7 @@ class ReceivablePayableReport(object):
self.filters["range2"] = "60"
if not "range3" in self.filters:
self.filters["range3"] = "90"
for label in ("0-{range1}".format(**self.filters),
"{range1}-{range2}".format(**self.filters),
"{range2}-{range3}".format(**self.filters),
@ -250,6 +255,23 @@ class ReceivablePayableReport(object):
return self.gl_entries_map.get(party, {})\
.get(against_voucher_type, {})\
.get(against_voucher, [])
def get_graph_data(self, columns, data):
ageing_columns = columns[self.ageing_col_idx_start : self.ageing_col_idx_start+4]
range_totals = [[d.get("label")] for d in ageing_columns]
for d in data:
for i in xrange(4):
range_totals[i].append(d[self.ageing_col_idx_start + i])
return {
"data": {
'columns': range_totals,
'type': 'pie'
}
}
def execute(filters=None):
args = {