From 28bdff5a552bfce5329b80235b63a2d149a8302a Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Fri, 20 May 2016 11:43:30 +0530 Subject: [PATCH] Pie chart for ageing analysis in accounts receivale/payable --- .../accounts_receivable.py | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/erpnext/accounts/report/accounts_receivable/accounts_receivable.py b/erpnext/accounts/report/accounts_receivable/accounts_receivable.py index 365212a163..786f904a65 100644 --- a/erpnext/accounts/report/accounts_receivable/accounts_receivable.py +++ b/erpnext/accounts/report/accounts_receivable/accounts_receivable.py @@ -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 = {