From 2af1a8f65c0e0b05be3e03bc66034d76055d08c2 Mon Sep 17 00:00:00 2001 From: anandbaburajan Date: Tue, 18 Jul 2023 22:03:45 +0530 Subject: [PATCH] fix: allow cross child table links in dashboard (cherry picked from commit d29b151fcdf77bb8d45518c027d6d49b2eb0f9ad) --- frappe/desk/notifications.py | 4 +- frappe/public/js/frappe/form/dashboard.js | 50 ++++++++++++++++++++--- 2 files changed, 47 insertions(+), 7 deletions(-) diff --git a/frappe/desk/notifications.py b/frappe/desk/notifications.py index 6334b18d1c..7eb597175a 100644 --- a/frappe/desk/notifications.py +++ b/frappe/desk/notifications.py @@ -269,7 +269,9 @@ def get_open_count(doctype, name, items=None): out = [] for d in items: - if d in links.get("internal_links", {}): + if d in links.get("internal_links", {}) and not links.get("non_standard_fieldnames", {}).get( + d, {} + ): continue filters = get_filters_for(d) diff --git a/frappe/public/js/frappe/form/dashboard.js b/frappe/public/js/frappe/form/dashboard.js index 0f3083ed69..b8a7f72ef2 100644 --- a/frappe/public/js/frappe/form/dashboard.js +++ b/frappe/public/js/frappe/form/dashboard.js @@ -250,6 +250,7 @@ frappe.ui.form.Dashboard = class FormDashboard { this.data = this.frm.meta.__dashboard || {}; if (!this.data.transactions) this.data.transactions = []; if (!this.data.internal_links) this.data.internal_links = {}; + this.internal_links_doctypes_to_skip = []; this.filter_permissions(); } @@ -370,10 +371,21 @@ frappe.ui.form.Dashboard = class FormDashboard { names = $link.attr("data-names") || []; if (this.data.internal_links[doctype]) { - if (names.length) { - frappe.route_options = { name: ["in", names] }; + if ( + this.internal_links_doctypes_to_skip && + this.internal_links_doctypes_to_skip.includes(doctype) && + this.data.fieldname + ) { + frappe.route_options = this.get_document_filter(doctype); + if (show_open && frappe.ui.notifications) { + frappe.ui.notifications.show_open_count_list(doctype); + } } else { - return false; + if (names.length) { + frappe.route_options = { name: ["in", names] }; + } else { + return false; + } } } else if (this.data.fieldname) { frappe.route_options = this.get_document_filter(doctype); @@ -439,11 +451,37 @@ frappe.ui.form.Dashboard = class FormDashboard { // update badges $.each(r.message.count, function (i, d) { - me.frm.dashboard.set_badge_count(d.name, cint(d.open_count), cint(d.count)); + if ( + me.data.internal_links && + Object.keys(me.data.internal_links).includes(d.name) + ) { + if (cint(d.open_count) || cint(d.count)) { + me.internal_links_doctypes_to_skip.push(d.name); + me.frm.dashboard.set_badge_count( + d.name, + cint(d.open_count), + cint(d.count), + null, + true + ); + } + } else { + me.frm.dashboard.set_badge_count( + d.name, + cint(d.open_count), + cint(d.count) + ); + } }); // update from internal links $.each(me.data.internal_links, (doctype, link) => { + if ( + me.internal_links_doctypes_to_skip && + me.internal_links_doctypes_to_skip.includes(doctype) + ) + return; + let names = []; if (typeof link === "string" || link instanceof String) { // get internal links in parent document @@ -471,7 +509,7 @@ frappe.ui.form.Dashboard = class FormDashboard { }); } - set_badge_count(doctype, open_count, count, names) { + set_badge_count(doctype, open_count, count, names, skip_internal_link_doctype) { let $link = $(this.transactions_area).find( '.document-link[data-doctype="' + doctype + '"]' ); @@ -490,7 +528,7 @@ frappe.ui.form.Dashboard = class FormDashboard { .text(count > 99 ? "99+" : count); } - if (this.data.internal_links[doctype]) { + if (this.data.internal_links[doctype] && !skip_internal_link_doctype) { if (names && names.length) { $link.attr("data-names", names ? names.join(",") : ""); } else {