diff --git a/AGENTS.md b/AGENTS.md index 44c62a4..8085053 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1,6 +1,6 @@ # Service Factory — ERPNext Custom App Project -> **Current Version: V0.1.0025** — 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.0026** — 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 f2a5b73..ed6c37f 100644 --- a/service_factory/service_factory/doctype/engagement_card/engagement_card.js +++ b/service_factory/service_factory/doctype/engagement_card/engagement_card.js @@ -9,14 +9,14 @@ frappe.ui.form.on("Engagement Card", { } load_select_options(frm); toggle_creation_fields(frm); + update_opportunity_state(frm); - // Filter opportunities by customer + // Filter opportunities by selected customer only frm.set_query("opportunity", function () { - let filters = {}; - if (frm.doc.customer) { - filters.customer = frm.doc.customer; + if (!frm.doc.customer) { + return { filters: { name: "" } }; } - return { filters: filters }; + return { filters: { customer: frm.doc.customer } }; }); }, refresh: function (frm) { @@ -26,6 +26,7 @@ frappe.ui.form.on("Engagement Card", { } load_select_options(frm); toggle_creation_fields(frm); + update_opportunity_state(frm); // Quick status actions if (frm.doc.status === "Discovery" && !frm.is_new()) { @@ -87,19 +88,32 @@ frappe.ui.form.on("Engagement Card", { }); } }, - // Re-filter opportunities when customer changes + // When customer changes, clear and re-filter opportunity customer: function (frm) { frm._cust_user_selected = true; + + // Clear opportunity if customer changed + if (frm.doc.opportunity) { + frm.set_value("opportunity", null); + } + + // Only show opportunities linked to selected customer frm.set_query("opportunity", function () { - let filters = {}; - if (frm.doc.customer) { - filters.customer = frm.doc.customer; + if (!frm.doc.customer) { + return { filters: { name: "" } }; } - return { filters: filters }; + return { filters: { customer: frm.doc.customer } }; }); + + update_opportunity_state(frm); }, }); +function update_opportunity_state(frm) { + // Enable opportunity only when a customer is selected + frm.toggle_enable("opportunity", !!frm.doc.customer); +} + function clear_customer_field(frm) { if (!frm.is_new()) return;