chore: fix customer auto-select, add placeholder, clear on new forms
This commit is contained in:
parent
ce03f6d2d5
commit
589f5437f1
3 changed files with 76 additions and 23 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
# Service Factory — ERPNext Custom App Project
|
# Service Factory — ERPNext Custom App Project
|
||||||
|
|
||||||
> **Current Version: V0.1.0022** — Each completed prompt/step increments the patch number by 1 (V0.1.0000 → V0.1.0001 → V0.1.0002…). The agent automatically commits and pushes after every step.
|
> **Current Version: V0.1.0023** — Each completed prompt/step increments the patch number by 1 (V0.1.0000 → V0.1.0001 → V0.1.0002…). The agent automatically commits and pushes after every step.
|
||||||
|
|
||||||
## Project Overview
|
## Project Overview
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,27 @@
|
||||||
|
|
||||||
frappe.ui.form.on("Engagement Card", {
|
frappe.ui.form.on("Engagement Card", {
|
||||||
onload: function (frm) {
|
onload: function (frm) {
|
||||||
|
// Ensure customer starts empty on new forms
|
||||||
|
if (frm.is_new()) {
|
||||||
|
frm.set_value("customer", null);
|
||||||
|
}
|
||||||
load_select_options(frm);
|
load_select_options(frm);
|
||||||
toggle_creation_fields(frm);
|
toggle_creation_fields(frm);
|
||||||
|
|
||||||
|
// Filter opportunities by customer
|
||||||
|
frm.set_query("opportunity", function () {
|
||||||
|
let filters = {};
|
||||||
|
if (frm.doc.customer) {
|
||||||
|
filters.customer = frm.doc.customer;
|
||||||
|
}
|
||||||
|
return { filters: filters };
|
||||||
|
});
|
||||||
},
|
},
|
||||||
refresh: function (frm) {
|
refresh: function (frm) {
|
||||||
|
// Re-clear customer if awesomplete auto-selected on render
|
||||||
|
if (frm.is_new() && frm.doc.customer) {
|
||||||
|
frm.set_value("customer", null);
|
||||||
|
}
|
||||||
load_select_options(frm);
|
load_select_options(frm);
|
||||||
toggle_creation_fields(frm);
|
toggle_creation_fields(frm);
|
||||||
|
|
||||||
|
|
@ -29,15 +46,30 @@ frappe.ui.form.on("Engagement Card", {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log Activity quick action
|
// Log Activity quick action (only for saved cards)
|
||||||
if (!frm.is_new()) {
|
if (!frm.is_new()) {
|
||||||
frm.add_custom_button(__("Log Activity"), function () {
|
frm.add_custom_button(__("Log Activity"), function () {
|
||||||
let d = new frappe.ui.Dialog({
|
let d = new frappe.ui.Dialog({
|
||||||
title: __("Log Activity"),
|
title: __("Log Activity"),
|
||||||
fields: [
|
fields: [
|
||||||
{ label: "Activity Type", fieldname: "activity_type", fieldtype: "Select", options: ["Comment", "Milestone", "Note"], reqd: 1 },
|
{
|
||||||
{ label: "Content", fieldname: "content", fieldtype: "Text Editor", reqd: 1 },
|
label: "Activity Type",
|
||||||
{ label: "Mark as Milestone", fieldname: "is_milestone", fieldtype: "Check" },
|
fieldname: "activity_type",
|
||||||
|
fieldtype: "Select",
|
||||||
|
options: ["Comment", "Milestone", "Note"],
|
||||||
|
reqd: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Content",
|
||||||
|
fieldname: "content",
|
||||||
|
fieldtype: "Text Editor",
|
||||||
|
reqd: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Mark as Milestone",
|
||||||
|
fieldname: "is_milestone",
|
||||||
|
fieldtype: "Check",
|
||||||
|
},
|
||||||
],
|
],
|
||||||
primary_action: function () {
|
primary_action: function () {
|
||||||
let data = d.get_values();
|
let data = d.get_values();
|
||||||
|
|
@ -55,20 +87,35 @@ frappe.ui.form.on("Engagement Card", {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
// Re-filter opportunities when customer changes
|
||||||
|
customer: function (frm) {
|
||||||
|
frm.set_query("opportunity", function () {
|
||||||
|
let filters = {};
|
||||||
|
if (frm.doc.customer) {
|
||||||
|
filters.customer = frm.doc.customer;
|
||||||
|
}
|
||||||
|
return { filters: filters };
|
||||||
|
});
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
function load_select_options(frm) {
|
function load_select_options(frm) {
|
||||||
frappe.call({
|
frappe.call({
|
||||||
method: "frappe.client.get",
|
method: "frappe.client.get",
|
||||||
args: { doctype: "Service Factory Settings", name: "Service Factory Settings" },
|
args: {
|
||||||
|
doctype: "Service Factory Settings",
|
||||||
|
name: "Service Factory Settings",
|
||||||
|
},
|
||||||
callback: function (r) {
|
callback: function (r) {
|
||||||
if (!r.message) return;
|
if (!r.message) return;
|
||||||
let doc = r.message;
|
let doc = r.message;
|
||||||
|
|
||||||
if (doc.task_types && doc.task_types.length) {
|
if (doc.task_types && doc.task_types.length) {
|
||||||
let opts = "\n" + doc.task_types.map((t) => t.task_type_name).join("\n");
|
let opts = "\n" + doc.task_types.map((t) => t.task_type_name).join("\n");
|
||||||
frm.set_df_property("task", "options", opts);
|
frm.set_df_property("task", "options", opts);
|
||||||
frm.refresh_field("task");
|
frm.refresh_field("task");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (doc.teams && doc.teams.length) {
|
if (doc.teams && doc.teams.length) {
|
||||||
let opts = "\n" + doc.teams.map((t) => t.team_name).join("\n");
|
let opts = "\n" + doc.teams.map((t) => t.team_name).join("\n");
|
||||||
frm.set_df_property("team", "options", opts);
|
frm.set_df_property("team", "options", opts);
|
||||||
|
|
@ -94,6 +141,10 @@ function toggle_creation_fields(frm) {
|
||||||
|
|
||||||
// Time log rollup
|
// Time log rollup
|
||||||
frappe.ui.form.on("Engagement Card Time Log", {
|
frappe.ui.form.on("Engagement Card Time Log", {
|
||||||
hours: function (frm) { frm.trigger("update_total_hours"); },
|
hours: function (frm) {
|
||||||
time_log_remove: function (frm) { frm.trigger("update_total_hours"); },
|
frm.trigger("update_total_hours");
|
||||||
|
},
|
||||||
|
time_log_remove: function (frm) {
|
||||||
|
frm.trigger("update_total_hours");
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -88,21 +88,23 @@
|
||||||
"options": "Low\nNormal\nHigh\nCritical",
|
"options": "Low\nNormal\nHigh\nCritical",
|
||||||
"reqd": 1
|
"reqd": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "customer",
|
"fieldname": "customer",
|
||||||
"fieldtype": "Link",
|
"fieldtype": "Link",
|
||||||
"in_global_search": 1,
|
"in_global_search": 1,
|
||||||
"in_list_view": 1,
|
"in_list_view": 1,
|
||||||
"in_standard_filter": 1,
|
"in_standard_filter": 1,
|
||||||
"label": "Customer",
|
"label": "Customer",
|
||||||
"options": "Customer"
|
"options": "Customer",
|
||||||
},
|
"placeholder": "Search and select a Customer"
|
||||||
{
|
},
|
||||||
"fieldname": "opportunity",
|
{
|
||||||
"fieldtype": "Link",
|
"fieldname": "opportunity",
|
||||||
"label": "Opportunity",
|
"fieldtype": "Link",
|
||||||
"options": "Opportunity"
|
"label": "Opportunity",
|
||||||
},
|
"options": "Opportunity",
|
||||||
|
"reqd": 1
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "section_break_team",
|
"fieldname": "section_break_team",
|
||||||
"fieldtype": "Section Break",
|
"fieldtype": "Section Break",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue