chore: filter Opportunity by selected Customer only, disable when no Customer
This commit is contained in:
parent
276bc18c32
commit
11b1972f97
2 changed files with 25 additions and 11 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
frm.set_query("opportunity", function () {
|
||||
let filters = {};
|
||||
if (frm.doc.customer) {
|
||||
filters.customer = frm.doc.customer;
|
||||
|
||||
// Clear opportunity if customer changed
|
||||
if (frm.doc.opportunity) {
|
||||
frm.set_value("opportunity", null);
|
||||
}
|
||||
return { filters: filters };
|
||||
|
||||
// Only show opportunities linked to selected customer
|
||||
frm.set_query("opportunity", function () {
|
||||
if (!frm.doc.customer) {
|
||||
return { filters: { name: "" } };
|
||||
}
|
||||
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;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue