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
|
||||
|
||||
> **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
|
||||
|
||||
|
|
|
|||
|
|
@ -3,10 +3,27 @@
|
|||
|
||||
frappe.ui.form.on("Engagement Card", {
|
||||
onload: function (frm) {
|
||||
// Ensure customer starts empty on new forms
|
||||
if (frm.is_new()) {
|
||||
frm.set_value("customer", null);
|
||||
}
|
||||
load_select_options(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) {
|
||||
// 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);
|
||||
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()) {
|
||||
frm.add_custom_button(__("Log Activity"), function () {
|
||||
let d = new frappe.ui.Dialog({
|
||||
title: __("Log Activity"),
|
||||
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: "Mark as Milestone", fieldname: "is_milestone", fieldtype: "Check" },
|
||||
{
|
||||
label: "Activity Type",
|
||||
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 () {
|
||||
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) {
|
||||
frappe.call({
|
||||
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) {
|
||||
if (!r.message) return;
|
||||
let doc = r.message;
|
||||
|
||||
if (doc.task_types && doc.task_types.length) {
|
||||
let opts = "\n" + doc.task_types.map((t) => t.task_type_name).join("\n");
|
||||
frm.set_df_property("task", "options", opts);
|
||||
frm.refresh_field("task");
|
||||
}
|
||||
|
||||
if (doc.teams && doc.teams.length) {
|
||||
let opts = "\n" + doc.teams.map((t) => t.team_name).join("\n");
|
||||
frm.set_df_property("team", "options", opts);
|
||||
|
|
@ -94,6 +141,10 @@ function toggle_creation_fields(frm) {
|
|||
|
||||
// Time log rollup
|
||||
frappe.ui.form.on("Engagement Card Time Log", {
|
||||
hours: function (frm) { frm.trigger("update_total_hours"); },
|
||||
time_log_remove: function (frm) { frm.trigger("update_total_hours"); },
|
||||
hours: function (frm) {
|
||||
frm.trigger("update_total_hours");
|
||||
},
|
||||
time_log_remove: function (frm) {
|
||||
frm.trigger("update_total_hours");
|
||||
},
|
||||
});
|
||||
|
|
|
|||
|
|
@ -95,13 +95,15 @@
|
|||
"in_list_view": 1,
|
||||
"in_standard_filter": 1,
|
||||
"label": "Customer",
|
||||
"options": "Customer"
|
||||
"options": "Customer",
|
||||
"placeholder": "Search and select a Customer"
|
||||
},
|
||||
{
|
||||
"fieldname": "opportunity",
|
||||
"fieldtype": "Link",
|
||||
"label": "Opportunity",
|
||||
"options": "Opportunity"
|
||||
"options": "Opportunity",
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "section_break_team",
|
||||
|
|
|
|||
Loading…
Reference in a new issue