diff --git a/erpnext/accounts/doctype/loyalty_program/test_loyalty_program.py b/erpnext/accounts/doctype/loyalty_program/test_loyalty_program.py
index bf7a0bcfa4..8a1d6a27be 100644
--- a/erpnext/accounts/doctype/loyalty_program/test_loyalty_program.py
+++ b/erpnext/accounts/doctype/loyalty_program/test_loyalty_program.py
@@ -7,6 +7,7 @@ import frappe
import unittest
from frappe.utils import today, cint, flt, getdate
from erpnext.accounts.doctype.loyalty_program.loyalty_program import get_loyalty_program_details_with_points
+from erpnext.accounts.party import get_dashboard_info
class TestLoyaltyProgram(unittest.TestCase):
@classmethod
@@ -144,6 +145,13 @@ class TestLoyaltyProgram(unittest.TestCase):
frappe.get_doc('Sales Invoice', d.name).cancel()
frappe.delete_doc('Sales Invoice', d.name)
+ def test_loyalty_points_for_dashboard(self):
+ doc = frappe.get_doc('Customer', 'Test Loyalty Customer')
+ company_wise_info = get_dashboard_info("Customer", doc.name, doc.loyalty_program)
+
+ for d in company_wise_info:
+ self.assertTrue(d.loyalty_points)
+
def get_points_earned(self):
def get_returned_amount():
returned_amount = frappe.db.sql("""
diff --git a/erpnext/accounts/party.py b/erpnext/accounts/party.py
index 1085cddab5..a69a172284 100644
--- a/erpnext/accounts/party.py
+++ b/erpnext/accounts/party.py
@@ -454,7 +454,7 @@ def get_timeline_data(doctype, name):
return out
-def get_dashboard_info(party_type, party):
+def get_dashboard_info(party_type, party, loyalty_program=None):
current_fiscal_year = get_fiscal_year(nowdate(), as_dict=True)
doctype = "Sales Invoice" if party_type=="Customer" else "Purchase Invoice"
@@ -476,6 +476,19 @@ def get_dashboard_info(party_type, party):
fields=["company", "sum(grand_total) as grand_total", "sum(base_grand_total) as base_grand_total"]
)
+ loyalty_point_details = []
+
+ if party_type == "Customer":
+ loyalty_point_details = frappe._dict(frappe.get_all("Loyalty Point Entry",
+ filters={
+ 'customer': party,
+ 'expiry_date': ('>=', getdate()),
+ },
+ group_by="company",
+ fields=["company", "sum(loyalty_points) as loyalty_points"],
+ as_list =1
+ ))
+
company_wise_billing_this_year = frappe._dict()
for d in company_wise_grand_total:
@@ -503,12 +516,18 @@ def get_dashboard_info(party_type, party):
total_unpaid = flt(company_wise_total_unpaid.get(d.company))
+ if loyalty_point_details:
+ loyalty_points = loyalty_point_details.get(d.company)
+
info = {}
info["billing_this_year"] = flt(billing_this_year) if billing_this_year else 0
info["currency"] = party_account_currency
info["total_unpaid"] = flt(total_unpaid) if total_unpaid else 0
info["company"] = d.company
+ if party_type == "Customer" and loyalty_point_details:
+ info["loyalty_points"] = loyalty_points
+
if party_type == "Supplier":
info["total_unpaid"] = -1 * info["total_unpaid"]
diff --git a/erpnext/public/js/utils.js b/erpnext/public/js/utils.js
index adb7c6dd68..64085a83cd 100755
--- a/erpnext/public/js/utils.js
+++ b/erpnext/public/js/utils.js
@@ -105,33 +105,52 @@ $.extend(erpnext.utils, {
if(frm.doc.__onload && frm.doc.__onload.dashboard_info) {
var company_wise_info = frm.doc.__onload.dashboard_info;
if(company_wise_info.length > 1) {
- frm.dashboard.stats_area.removeClass('hidden');
- frm.dashboard.stats_area_row.addClass('flex');
- frm.dashboard.stats_area_row.css('flex-wrap', 'wrap');
company_wise_info.forEach(function(info) {
- frm.dashboard.stats_area_row.append(
- '
'+
- '
'+info.company+'
'+
- '
Annual Billing: '
- +format_currency(info.billing_this_year, info.currency)+'
'+
- '
Total Unpaid: '
- +format_currency(info.total_unpaid, info.currency)+'
'+
- '
'
- );
+ erpnext.utils.add_indicator_for_multicompany(frm, info);
});
- }
- else if (company_wise_info.length === 1) {
- frm.dashboard.stats_area.removeClass('hidden');
- frm.dashboard.stats_area_row.append(
- 'Annual Billing: '
- +format_currency(company_wise_info[0].billing_this_year, company_wise_info[0].currency)+'
' +
- 'Total Unpaid: '
- +format_currency(company_wise_info[0].total_unpaid, company_wise_info[0].currency)+'
'
- );
+ } else if (company_wise_info.length === 1) {
+ frm.dashboard.add_indicator(__('Annual Billing: {0}',
+ [format_currency(company_wise_info[0].billing_this_year, company_wise_info[0].currency)]), 'blue');
+ frm.dashboard.add_indicator(__('Total Unpaid: {0}',
+ [format_currency(company_wise_info[0].total_unpaid, company_wise_info[0].currency)]),
+ company_wise_info[0].total_unpaid ? 'orange' : 'green');
+
+ if(company_wise_info[0].loyalty_points) {
+ frm.dashboard.add_indicator(__('Loyalty Points: {0}',
+ [company_wise_info[0].loyalty_points]), 'blue');
+ }
}
}
},
+ add_indicator_for_multicompany: function(frm, info) {
+ frm.dashboard.stats_area.removeClass('hidden');
+ frm.dashboard.stats_area_row.addClass('flex');
+ frm.dashboard.stats_area_row.css('flex-wrap', 'wrap');
+
+ var color = info.total_unpaid ? 'orange' : 'green';
+
+ var indicator = $(''+
+ '
'+info.company+'
'+
+
+ '
'+
+ 'Annual Billing: '+format_currency(info.billing_this_year, info.currency)+'
'+
+
+ '
'+
+ 'Total Unpaid: '
+ +format_currency(info.total_unpaid, info.currency)+'
'+
+
+
+ '
').appendTo(frm.dashboard.stats_area_row);
+
+ if(info.loyalty_points){
+ $(''+
+ 'Loyalty Points: '+info.loyalty_points+'
').appendTo(indicator);
+ }
+
+ return indicator;
+ },
+
get_party_name: function(party_type) {
var dict = {'Customer': 'customer_name', 'Supplier': 'supplier_name', 'Employee': 'employee_name',
'Member': 'member_name'};
diff --git a/erpnext/selling/doctype/customer/customer.js b/erpnext/selling/doctype/customer/customer.js
index d687c85e3a..3b0e75ff6c 100644
--- a/erpnext/selling/doctype/customer/customer.js
+++ b/erpnext/selling/doctype/customer/customer.js
@@ -113,11 +113,6 @@ frappe.ui.form.on("Customer", {
// indicator
erpnext.utils.set_party_dashboard_indicators(frm);
- //
- if (frm.doc.__onload.dashboard_info.loyalty_point) {
- frm.dashboard.add_indicator(__('Loyalty Point: {0}', [frm.doc.__onload.dashboard_info.loyalty_point]), 'blue');
- }
-
} else {
frappe.contacts.clear_address_and_contact(frm);
}
diff --git a/erpnext/selling/doctype/customer/customer.py b/erpnext/selling/doctype/customer/customer.py
index d285704eb4..0da82724ac 100644
--- a/erpnext/selling/doctype/customer/customer.py
+++ b/erpnext/selling/doctype/customer/customer.py
@@ -23,10 +23,7 @@ class Customer(TransactionBase):
self.load_dashboard_info()
def load_dashboard_info(self):
- info = get_dashboard_info(self.doctype, self.name)
- loyalty_point_details = self.get_loyalty_points()
- if loyalty_point_details and loyalty_point_details.get("loyalty_points"):
- info["loyalty_point"] = loyalty_point_details.loyalty_points
+ info = get_dashboard_info(self.doctype, self.name, self.loyalty_program)
self.set_onload('dashboard_info', info)
def autoname(self):
@@ -36,11 +33,6 @@ class Customer(TransactionBase):
else:
set_name_by_naming_series(self)
- def get_loyalty_points(self):
- if self.loyalty_program:
- from erpnext.accounts.doctype.loyalty_program.loyalty_program import get_loyalty_details
- return get_loyalty_details(self.name, self.loyalty_program)
-
def get_customer_name(self):
if frappe.db.get_value("Customer", self.customer_name):
count = frappe.db.sql("""select ifnull(MAX(CAST(SUBSTRING_INDEX(name, ' ', -1) AS UNSIGNED)), 0) from tabCustomer