diff --git a/AGENTS.md b/AGENTS.md index 6a2c52a..d90df59 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -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 diff --git a/service_factory/service_factory/doctype/engagement_card/engagement_card.js b/service_factory/service_factory/doctype/engagement_card/engagement_card.js index 3d766d1..335e16e 100644 --- a/service_factory/service_factory/doctype/engagement_card/engagement_card.js +++ b/service_factory/service_factory/doctype/engagement_card/engagement_card.js @@ -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"); + }, }); diff --git a/service_factory/service_factory/service_factory/doctype/engagement_card/engagement_card.json b/service_factory/service_factory/service_factory/doctype/engagement_card/engagement_card.json index de76d3b..eba574e 100644 --- a/service_factory/service_factory/service_factory/doctype/engagement_card/engagement_card.json +++ b/service_factory/service_factory/service_factory/doctype/engagement_card/engagement_card.json @@ -88,21 +88,23 @@ "options": "Low\nNormal\nHigh\nCritical", "reqd": 1 }, - { - "fieldname": "customer", - "fieldtype": "Link", - "in_global_search": 1, - "in_list_view": 1, - "in_standard_filter": 1, - "label": "Customer", - "options": "Customer" - }, - { - "fieldname": "opportunity", - "fieldtype": "Link", - "label": "Opportunity", - "options": "Opportunity" - }, + { + "fieldname": "customer", + "fieldtype": "Link", + "in_global_search": 1, + "in_list_view": 1, + "in_standard_filter": 1, + "label": "Customer", + "options": "Customer", + "placeholder": "Search and select a Customer" + }, + { + "fieldname": "opportunity", + "fieldtype": "Link", + "label": "Opportunity", + "options": "Opportunity", + "reqd": 1 + }, { "fieldname": "section_break_team", "fieldtype": "Section Break",