From 36df21067cd13eb7ffd8bc88b6eb144d016f0934 Mon Sep 17 00:00:00 2001 From: barredterra <14891507+barredterra@users.noreply.github.com> Date: Sun, 20 Mar 2022 03:58:24 +0100 Subject: [PATCH 1/3] refactor: sales analytics --- .../report/sales_analytics/sales_analytics.js | 66 +++++++------------ 1 file changed, 23 insertions(+), 43 deletions(-) diff --git a/erpnext/selling/report/sales_analytics/sales_analytics.js b/erpnext/selling/report/sales_analytics/sales_analytics.js index 6b03c7d92fe..d527e42ea4a 100644 --- a/erpnext/selling/report/sales_analytics/sales_analytics.js +++ b/erpnext/selling/report/sales_analytics/sales_analytics.js @@ -82,62 +82,42 @@ frappe.query_reports["Sales Analytics"] = { const tree_type = frappe.query_report.filters[0].value; if (data_doctype != tree_type) return; - row_name = data[2].content; - length = data.length; - - if (tree_type == "Customer") { - row_values = data - .slice(4, length - 1) - .map(function (column) { - return column.content; - }); - } else if (tree_type == "Item") { - row_values = data - .slice(5, length - 1) - .map(function (column) { - return column.content; - }); - } else { - row_values = data - .slice(3, length - 1) - .map(function (column) { - return column.content; - }); - } - - entry = { - name: row_name, - values: row_values, - }; - - let raw_data = frappe.query_report.chart.data; - let new_datasets = raw_data.datasets; - - let element_found = new_datasets.some((element, index, array)=>{ - if(element.name == row_name){ - array.splice(index, 1) - return true + const row_name = data[2].content; + const raw_data = frappe.query_report.chart.data; + const new_datasets = raw_data.datasets; + const element_found = new_datasets.some( + (element, index, array) => { + if (element.name == row_name) { + array.splice(index, 1); + return true; + } + return false; } - return false - }) + ); + const slice_at = { Customer: 4, Item: 5 }[tree_type] || 3; if (!element_found) { - new_datasets.push(entry); + new_datasets.push({ + name: row_name, + values: data + .slice(slice_at, data.length - 1) + .map(column => column.content), + }); } - let new_data = { + const new_data = { labels: raw_data.labels, datasets: new_datasets, }; - chart_options = { + + frappe.query_report.render_chart({ data: new_data, type: "line", - }; - frappe.query_report.render_chart(chart_options); + }); frappe.query_report.raw_chart_data = new_data; }, }, }); }, -} +}; From 01fd3adedf289aa18947310f06a1b6b38ba7ecd6 Mon Sep 17 00:00:00 2001 From: HarryPaulo Date: Mon, 21 Mar 2022 08:27:27 -0300 Subject: [PATCH 2/3] fix: report sales payments summary (#30264) --- .../sales_payment_summary.py | 62 +++++++++++-------- 1 file changed, 35 insertions(+), 27 deletions(-) diff --git a/erpnext/accounts/report/sales_payment_summary/sales_payment_summary.py b/erpnext/accounts/report/sales_payment_summary/sales_payment_summary.py index 3b736282cf9..d5483b5f852 100644 --- a/erpnext/accounts/report/sales_payment_summary/sales_payment_summary.py +++ b/erpnext/accounts/report/sales_payment_summary/sales_payment_summary.py @@ -199,31 +199,39 @@ def get_mode_of_payment_details(filters): invoice_list = get_invoices(filters) invoice_list_names = ",".join('"' + invoice['name'] + '"' for invoice in invoice_list) if invoice_list: - inv_mop_detail = frappe.db.sql("""select a.owner, a.posting_date, - ifnull(b.mode_of_payment, '') as mode_of_payment, sum(b.base_amount) as paid_amount - from `tabSales Invoice` a, `tabSales Invoice Payment` b - where a.name = b.parent - and a.docstatus = 1 - and a.name in ({invoice_list_names}) - group by a.owner, a.posting_date, mode_of_payment - union - select a.owner,a.posting_date, - ifnull(b.mode_of_payment, '') as mode_of_payment, sum(b.base_paid_amount) as paid_amount - from `tabSales Invoice` a, `tabPayment Entry` b,`tabPayment Entry Reference` c - where a.name = c.reference_name - and b.name = c.parent - and b.docstatus = 1 - and a.name in ({invoice_list_names}) - group by a.owner, a.posting_date, mode_of_payment - union - select a.owner, a.posting_date, - ifnull(a.voucher_type,'') as mode_of_payment, sum(b.credit) - from `tabJournal Entry` a, `tabJournal Entry Account` b - where a.name = b.parent - and a.docstatus = 1 - and b.reference_type = "Sales Invoice" - and b.reference_name in ({invoice_list_names}) - group by a.owner, a.posting_date, mode_of_payment + inv_mop_detail = frappe.db.sql(""" + select t.owner, + t.posting_date, + t.mode_of_payment, + sum(t.paid_amount) as paid_amount + from ( + select a.owner, a.posting_date, + ifnull(b.mode_of_payment, '') as mode_of_payment, sum(b.base_amount) as paid_amount + from `tabSales Invoice` a, `tabSales Invoice Payment` b + where a.name = b.parent + and a.docstatus = 1 + and a.name in ({invoice_list_names}) + group by a.owner, a.posting_date, mode_of_payment + union + select a.owner,a.posting_date, + ifnull(b.mode_of_payment, '') as mode_of_payment, sum(c.allocated_amount) as paid_amount + from `tabSales Invoice` a, `tabPayment Entry` b,`tabPayment Entry Reference` c + where a.name = c.reference_name + and b.name = c.parent + and b.docstatus = 1 + and a.name in ({invoice_list_names}) + group by a.owner, a.posting_date, mode_of_payment + union + select a.owner, a.posting_date, + ifnull(a.voucher_type,'') as mode_of_payment, sum(b.credit) + from `tabJournal Entry` a, `tabJournal Entry Account` b + where a.name = b.parent + and a.docstatus = 1 + and b.reference_type = "Sales Invoice" + and b.reference_name in ({invoice_list_names}) + group by a.owner, a.posting_date, mode_of_payment + ) t + group by t.owner, t.posting_date, t.mode_of_payment """.format(invoice_list_names=invoice_list_names), as_dict=1) inv_change_amount = frappe.db.sql("""select a.owner, a.posting_date, @@ -231,7 +239,7 @@ def get_mode_of_payment_details(filters): from `tabSales Invoice` a, `tabSales Invoice Payment` b where a.name = b.parent and a.name in ({invoice_list_names}) - and b.mode_of_payment = 'Cash' + and b.type = 'Cash' and a.base_change_amount > 0 group by a.owner, a.posting_date, mode_of_payment""".format(invoice_list_names=invoice_list_names), as_dict=1) @@ -244,4 +252,4 @@ def get_mode_of_payment_details(filters): for d in inv_mop_detail: mode_of_payment_details.setdefault(d["owner"]+cstr(d["posting_date"]), []).append((d.mode_of_payment,d.paid_amount)) - return mode_of_payment_details + return mode_of_payment_details \ No newline at end of file From 3eb5440aa968960528379930cc3c2ba4a4ee544a Mon Sep 17 00:00:00 2001 From: HarryPaulo Date: Tue, 22 Mar 2022 03:09:15 -0300 Subject: [PATCH 3/3] fix: linters erros on report sales payments summary (#30345) * fix: wrong values for report and get change amout based on payment TYPE. * charcase for select field. * fix: linter check erros * fix: linters errors Co-authored-by: Ankush Menat --- .../report/sales_payment_summary/sales_payment_summary.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/erpnext/accounts/report/sales_payment_summary/sales_payment_summary.py b/erpnext/accounts/report/sales_payment_summary/sales_payment_summary.py index d5483b5f852..904513c39f7 100644 --- a/erpnext/accounts/report/sales_payment_summary/sales_payment_summary.py +++ b/erpnext/accounts/report/sales_payment_summary/sales_payment_summary.py @@ -200,9 +200,9 @@ def get_mode_of_payment_details(filters): invoice_list_names = ",".join('"' + invoice['name'] + '"' for invoice in invoice_list) if invoice_list: inv_mop_detail = frappe.db.sql(""" - select t.owner, + select t.owner, t.posting_date, - t.mode_of_payment, + t.mode_of_payment, sum(t.paid_amount) as paid_amount from ( select a.owner, a.posting_date, @@ -230,7 +230,7 @@ def get_mode_of_payment_details(filters): and b.reference_type = "Sales Invoice" and b.reference_name in ({invoice_list_names}) group by a.owner, a.posting_date, mode_of_payment - ) t + ) t group by t.owner, t.posting_date, t.mode_of_payment """.format(invoice_list_names=invoice_list_names), as_dict=1) @@ -252,4 +252,4 @@ def get_mode_of_payment_details(filters): for d in inv_mop_detail: mode_of_payment_details.setdefault(d["owner"]+cstr(d["posting_date"]), []).append((d.mode_of_payment,d.paid_amount)) - return mode_of_payment_details \ No newline at end of file + return mode_of_payment_details