Skip to content

Commit

Permalink
Merge pull request frappe#23171 from barredterra/number-cards
Browse files Browse the repository at this point in the history
  • Loading branch information
shariquerik authored Nov 18, 2023
2 parents 6f75dd7 + 20ef733 commit 0d0ff68
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 49 deletions.
52 changes: 4 additions & 48 deletions frappe/desk/doctype/number_card/number_card.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
frappe.ui.form.on("Number Card", {
refresh: function (frm) {
if (!frappe.boot.developer_mode && frm.doc.is_standard) {
frm.disable_form();
frm.disable_save();
} else {
frm.enable_save();
}

frm.set_df_property("filters_section", "hidden", 1);
frm.set_df_property("dynamic_filters_section", "hidden", 1);
frm.trigger("set_options");
Expand All @@ -19,12 +22,7 @@ frappe.ui.form.on("Number Card", {
}

if (frm.doc.type == "Custom") {
if (!frappe.boot.developer_mode) {
frm.disable_form();
}
frm.filters = eval(frm.doc.filters_config);
frm.trigger("set_filters_description");
frm.trigger("set_method_description");
frm.trigger("render_filters_table");
}
frm.trigger("set_parent_document_type");
Expand Down Expand Up @@ -68,49 +66,7 @@ frappe.ui.form.on("Number Card", {
frm.set_df_property("dynamic_filters_section", "hidden", 1);
},

set_filters_description: function (frm) {
if (frm.doc.type == "Custom") {
frm.fields_dict.filters_config.set_description(`
Set the filters here. For example:
<pre class="small text-muted">
<code>
[{
fieldname: "company",
label: __("Company"),
fieldtype: "Link",
options: "Company",
default: frappe.defaults.get_user_default("Company"),
reqd: 1
},
{
fieldname: "account",
label: __("Account"),
fieldtype: "Link",
options: "Account",
reqd: 1
}]
</code></pre>`);
}
},

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 data for the number card in the format:
<pre class="small text-muted">
<code>
{
"value": value,
"fieldtype": "Currency",
"route_options": {"from_date": "2023-05-23"},
"route": ["query-report", "Permitted Documents For User"]
}
</code></pre>`);
}
},

type: function (frm) {
frm.trigger("set_filters_description");
if (frm.doc.type == "Report") {
frm.set_query("report_name", () => {
return {
Expand Down
5 changes: 4 additions & 1 deletion frappe/desk/doctype/number_card/number_card.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
"fieldname": "is_standard",
"fieldtype": "Check",
"label": "Is Standard",
"no_copy": 1,
"read_only_depends_on": "eval: !frappe.boot.developer_mode"
},
{
Expand Down Expand Up @@ -165,6 +166,7 @@
},
{
"depends_on": "eval: doc.type == 'Custom'",
"description": "Set the path to a whitelisted function that will return the data for the number card in the format:\n\n<pre class=\"small text-muted\"><code>\n{\n\t\"value\": value,\n\t\"fieldtype\": \"Currency\",\n\t\"route_options\": {\"from_date\": \"2023-05-23\"},\n\t\"route\": [\"query-report\", \"Permitted Documents For User\"]\n}</code></pre>",
"fieldname": "method",
"fieldtype": "Data",
"label": "Method",
Expand All @@ -177,6 +179,7 @@
"label": "Custom Configuration"
},
{
"description": "Set the filters here. For example:\n<pre class=\"small text-muted\"><code>\n[{\n\tfieldname: \"company\",\n\tlabel: __(\"Company\"),\n\tfieldtype: \"Link\",\n\toptions: \"Company\",\n\tdefault: frappe.defaults.get_user_default(\"Company\"),\n\treqd: 1\n},\n{\n\tfieldname: \"account\",\n\tlabel: __(\"Account\"),\n\tfieldtype: \"Link\",\n\toptions: \"Account\",\n\treqd: 1\n}]\n</code></pre>",
"fieldname": "filters_config",
"fieldtype": "Code",
"label": "Filters Configuration",
Expand All @@ -200,7 +203,7 @@
}
],
"links": [],
"modified": "2023-08-28 22:23:56.286804",
"modified": "2023-11-09 13:44:00.280846",
"modified_by": "Administrator",
"module": "Desk",
"name": "Number Card",
Expand Down

0 comments on commit 0d0ff68

Please sign in to comment.