diff --git a/AGENTS.md b/AGENTS.md index 30bda6d..e36f2ca 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1,6 +1,6 @@ # Service Factory — ERPNext Custom App Project -> **Current Version: V0.1.0018** — 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.0019** — 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/service_factory/doctype/engagement_card/engagement_card.js b/service_factory/service_factory/service_factory/doctype/engagement_card/engagement_card.js index 53171ed..74f5364 100644 --- a/service_factory/service_factory/service_factory/doctype/engagement_card/engagement_card.js +++ b/service_factory/service_factory/service_factory/doctype/engagement_card/engagement_card.js @@ -2,10 +2,25 @@ // For license information, please see license.txt frappe.ui.form.on("Engagement Card", { + onload: function (frm) { + 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) { load_select_options(frm); + toggle_creation_fields(frm); + // Quick status actions - if (frm.doc.status === "Discovery") { + if (frm.doc.status === "Discovery" && !frm.is_new()) { frm.add_custom_button(__("Move to Delivery"), function () { frm.set_value("status", "Delivery"); frm.save(); @@ -23,43 +38,55 @@ frappe.ui.form.on("Engagement Card", { }); } - // Log Activity quick action - 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, + // 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", + }, + ], + primary_action: function () { + let data = d.get_values(); + let child = frm.add_child("activity_log"); + child.posted_by = frappe.session.user; + child.timestamp = frappe.datetime.now_datetime(); + child.activity_type = data.activity_type; + child.content = data.content; + child.is_milestone = data.is_milestone; + frm.refresh_field("activity_log"); + d.hide(); }, - { - 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(); - let child = frm.add_child("activity_log"); - child.posted_by = frappe.session.user; - child.timestamp = frappe.datetime.now_datetime(); - child.activity_type = data.activity_type; - child.content = data.content; - child.is_milestone = data.is_milestone; - frm.refresh_field("activity_log"); - d.hide(); - }, + }); + d.show(); }); - d.show(); + } + }, + // 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 }; }); }, }); @@ -75,14 +102,12 @@ function load_select_options(frm) { if (!r.message) return; let doc = r.message; - // Set task options 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"); } - // Set team options 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); @@ -92,6 +117,21 @@ function load_select_options(frm) { }); } +function toggle_creation_fields(frm) { + let hide = frm.is_new(); + let sections = [ + "section_break_desc", + "section_break_budget", + "section_break_assignments", + "section_break_activity", + "section_break_time", + "section_break_subtasks", + ]; + sections.forEach(function (section) { + frm.toggle_display(section, !hide); + }); +} + // Time log rollup frappe.ui.form.on("Engagement Card Time Log", { hours: function (frm) { 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 405b05f..de76d3b 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 @@ -61,7 +61,7 @@ "in_list_view": 1, "in_standard_filter": 1, "label": "Task", - "options": "", + "options": "\nDemo\nPOC\nDeployment\nRFP / RFI\nOther", "reqd": 1 }, { @@ -112,7 +112,7 @@ "fieldname": "team", "fieldtype": "Select", "label": "Team", - "options": "" + "options": "\n--- Configure teams in Service Factory Settings ---" }, { "fieldname": "section_break_desc",