diff --git a/frappe/desk/doctype/number_card/number_card.js b/frappe/desk/doctype/number_card/number_card.js index b0c5456268..ac881d47cf 100644 --- a/frappe/desk/doctype/number_card/number_card.js +++ b/frappe/desk/doctype/number_card/number_card.js @@ -96,12 +96,14 @@ frappe.ui.form.on("Number Card", { set_method_description: function (frm) { if (frm.doc.type == "Custom") { frm.fields_dict.method.set_description(` - Set the path to a whitelisted function that will return the number on the card in the format: + Set the path to a whitelisted function that will return the data for the number card in the format:
{
"value": value,
- "fieldtype": "Currency"
+ "fieldtype": "Currency",
+ "route_options": {"from_date": "2023-05-23"},
+ "route": ["query-report", "Permitted Documents For User"]
}
`);
}
diff --git a/frappe/public/js/frappe/widgets/number_card_widget.js b/frappe/public/js/frappe/widgets/number_card_widget.js
index 6b3e89d539..5f54151ddc 100644
--- a/frappe/public/js/frappe/widgets/number_card_widget.js
+++ b/frappe/public/js/frappe/widgets/number_card_widget.js
@@ -64,12 +64,17 @@ export default class NumberCardWidget extends Widget {
set_events() {
$(this.body).click(() => {
- if (this.in_customize_mode || this.card_doc.type == "Custom") return;
+ if (this.in_customize_mode) return;
this.set_route();
});
}
set_route() {
+ if (this.card_doc.type === "Custom") {
+ this.set_route_for_custom_card();
+ return;
+ }
+
const is_document_type = this.card_doc.type !== "Report";
const name = is_document_type ? this.card_doc.document_type : this.card_doc.report_name;
const route = frappe.utils.generate_route({
@@ -90,6 +95,16 @@ export default class NumberCardWidget extends Widget {
frappe.set_route(route);
}
+ set_route_for_custom_card() {
+ if (!this.data?.route) return;
+
+ if (this.data.route_options) {
+ frappe.route_options = this.data.route_options;
+ }
+
+ frappe.set_route(this.data.route);
+ }
+
set_doc_args() {
this.card_doc = Object.assign(
{},
@@ -139,7 +154,7 @@ export default class NumberCardWidget extends Widget {
return frappe.dashboard_utils.get_all_filters(this.card_doc);
}
- render_card() {
+ async render_card() {
this.prepare_actions();
this.set_title();
this.set_loading_state();
@@ -149,8 +164,10 @@ export default class NumberCardWidget extends Widget {
}
this.settings = this.get_settings(this.card_doc.type);
+ this.data = await this.get_data();
- frappe.run_serially([() => this.render_number(), () => this.render_stats()]);
+ this.render_number();
+ this.render_stats();
}
set_loading_state() {
@@ -159,10 +176,8 @@ export default class NumberCardWidget extends Widget {
`);
}
- get_number() {
- return frappe.xcall(this.settings.method, this.settings.args).then((res) => {
- return this.settings.get_number(res);
- });
+ get_data() {
+ return frappe.xcall(this.settings.method, this.settings.args);
}
get_number_for_custom_card(res) {
@@ -212,15 +227,15 @@ export default class NumberCardWidget extends Widget {
}
render_number() {
- return this.get_number().then(() => {
- $(this.body).html(``);
- });
+ this.settings.get_number(this.data);
+
+ $(this.body).html(``);
}
render_stats() {
- if (this.card_doc.type !== "Document Type") {
+ if (this.card_doc.type !== "Document Type" || !this.card_doc.show_percentage_stats) {
return;
}