Files
erpnext/erpnext/public/js/queries.js
mergify[bot] 88a36a800a fix: block disabled/frozen party on Opportunity and Request for Quotation (backport #57983) (#58034)
* fix: block disabled/frozen customers on Opportunity

Opportunity inherits TransactionBase instead of AccountsController, so
it never ran validate_party_frozen_disabled like Quotation, Sales Order
and Sales Invoice do. A disabled Customer could be saved as an
Opportunity's party and only get caught later at Quotation stage.

Also fixes the party_name Link query on the client: it referenced
erpnext.queries.customer, which was never defined, so disabled
customers showed up in the picker.

(cherry picked from commit 90937ce6d9)

# Conflicts:
#	erpnext/crm/doctype/opportunity/test_opportunity.py

* fix: block disabled/frozen suppliers on Request for Quotation

Request for Quotation overrides validate() entirely and never calls
super().validate(), so it never goes through AccountsController's
party validation. Suppliers also sit in a child table, so the shared
PartyValidator wouldn't have caught it anyway (it only checks a single
top-level party field). A disabled or frozen Supplier could be added
to an RFQ and the RFQ submitted without any warning.

Also filters the suppliers grid's supplier Link field to disabled=0,
matching the same client-side fix applied to Opportunity's party_name.

(cherry picked from commit 4bf65ffc1d)

# Conflicts:
#	erpnext/buying/doctype/request_for_quotation/request_for_quotation.py
#	erpnext/buying/doctype/request_for_quotation/test_request_for_quotation.py

* fix: scope Opportunity party validation to Customer only

validate_party_frozen_disabled only enforces Customer/Supplier/Employee,
so passing opportunity_from straight through silently no-op'd for Lead
and Prospect. Made the Customer-only scope explicit instead of relying
on that implicit fallthrough.

Lead.disabled is not enforced anywhere else in the codebase (lead_query,
the picker used for this same field, only filters status/docstatus), so
deliberately not extending validation to Lead-sourced Opportunities.

(cherry picked from commit 8c0a945417)

* refactor: move RFQ supplier disabled filter to link_filters

Static filters with no doc-dependent values belong on the field
definition, not in JS. Matches the existing pattern used for
Warehouse/Item link_filters elsewhere (e.g. job_card_item.json,
product_bundle_item.json).

(cherry picked from commit 6b35c51ff1)

* fix: resolve backport conflicts for disabled/frozen party validation

The automated backport left unresolved merge conflict markers committed
in request_for_quotation.py, test_request_for_quotation.py and
test_opportunity.py. Also fixes validate_party_frozen_disabled being
called with 3 args here, this branch's version only takes
(party_type, party_name), unlike develop's (company, party_type, party_name).

Dropped test_duplicate_supplier_rejected, test_rfq_blocked_for_supplier_with_prevent_rfqs
and test_rfq_status_lifecycle from the conflict resolution, they don't exist on
this branch and aren't part of this backport.

---------

Co-authored-by: Jatin3128 <jatinsarna8@gmail.com>
2026-08-19 16:58:21 +05:30

240 lines
5.9 KiB
JavaScript

// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
// License: GNU General Public License v3. See license.txt
// searches for enabled users
frappe.provide("erpnext.queries");
$.extend(erpnext.queries, {
user: function () {
return { query: "frappe.core.doctype.user.user.user_query" };
},
lead: function () {
return { query: "erpnext.controllers.queries.lead_query" };
},
customer: function () {
return { filters: { disabled: 0 } };
},
item: function (filters) {
var args = { query: "erpnext.controllers.queries.item_query" };
if (filters) args["filters"] = filters;
return args;
},
bom: function () {
return { query: "erpnext.controllers.queries.bom" };
},
task: function () {
return { query: "erpnext.projects.utils.query_task" };
},
customer_filter: function (doc) {
if (!doc.customer) {
cur_frm.scroll_to_field("customer");
frappe.show_alert({
message: __("Please set {0} first.", [
__(frappe.meta.get_label(doc.doctype, "customer", doc.name)),
]),
indicator: "orange",
});
}
return { filters: { customer: doc.customer } };
},
contact_query: function (doc) {
if (frappe.dynamic_link) {
if (!doc[frappe.dynamic_link.fieldname]) {
cur_frm.scroll_to_field(frappe.dynamic_link.fieldname);
frappe.show_alert({
message: __("Please set {0} first.", [
__(frappe.meta.get_label(doc.doctype, frappe.dynamic_link.fieldname, doc.name)),
]),
indicator: "orange",
});
}
return {
query: "frappe.contacts.doctype.contact.contact.contact_query",
filters: {
link_doctype: frappe.dynamic_link.doctype,
link_name: doc[frappe.dynamic_link.fieldname],
},
};
}
},
company_contact_query: function (doc) {
if (!doc.company) {
frappe.throw(__("Please set {0}", [__(frappe.meta.get_label(doc.doctype, "company", doc.name))]));
}
return {
query: "frappe.contacts.doctype.contact.contact.contact_query",
filters: { link_doctype: "Company", link_name: doc.company },
};
},
address_query: function (doc) {
if (frappe.dynamic_link) {
if (!doc[frappe.dynamic_link.fieldname]) {
cur_frm.scroll_to_field(frappe.dynamic_link.fieldname);
frappe.show_alert({
message: __("Please set {0} first.", [
__(frappe.meta.get_label(doc.doctype, frappe.dynamic_link.fieldname, doc.name)),
]),
indicator: "orange",
});
}
return {
query: "frappe.contacts.doctype.address.address.address_query",
filters: {
link_doctype: frappe.dynamic_link.doctype,
link_name: doc[frappe.dynamic_link.fieldname],
},
};
}
},
company_address_query: function (doc) {
if (!doc.company) {
cur_frm.scroll_to_field("company");
frappe.show_alert({
message: __("Please set {0} first.", [
__(frappe.meta.get_label(doc.doctype, "company", doc.name)),
]),
indicator: "orange",
});
}
let filters = { link_doctype: "Company", link_name: doc.company || "" };
const is_drop_ship = doc.items.some((item) => item.delivered_by_supplier);
if (is_drop_ship) filters = {};
return {
query: "frappe.contacts.doctype.address.address.address_query",
filters: filters,
};
},
dispatch_address_query: function (doc) {
let filters = { link_doctype: "Company", link_name: doc.company || "" };
const is_drop_ship = doc.items.some((item) => item.delivered_by_supplier);
if (is_drop_ship) filters = {};
return {
query: "frappe.contacts.doctype.address.address.address_query",
filters: filters,
};
},
supplier_filter: function (doc) {
if (!doc.supplier) {
cur_frm.scroll_to_field("supplier");
frappe.show_alert({
message: __("Please set {0} first.", [
__(frappe.meta.get_label(doc.doctype, "supplier", doc.name)),
]),
indicator: "orange",
});
}
return { filters: { supplier: doc.supplier } };
},
lead_filter: function (doc) {
if (!doc.lead) {
cur_frm.scroll_to_field("lead");
frappe.show_alert({
message: __("Please specify a {0} first.", [
__(frappe.meta.get_label(doc.doctype, "lead", doc.name)),
]),
indicator: "orange",
});
}
return { filters: { lead: doc.lead } };
},
not_a_group_filter: function () {
return { filters: { is_group: 0 } };
},
employee: function () {
return { query: "erpnext.controllers.queries.employee_query" };
},
warehouse: function (doc) {
return {
filters: [
["Warehouse", "company", "in", ["", cstr(doc.company)]],
["Warehouse", "is_group", "=", 0],
],
};
},
get_filtered_dimensions: function (doc, child_fields, dimension, company) {
let account = "";
child_fields.forEach((field) => {
if (!account) {
account = doc[field];
}
});
return {
query: "erpnext.controllers.queries.get_filtered_dimensions",
filters: {
dimension: dimension,
account: account,
company: company,
},
};
},
});
erpnext.queries.setup_queries = function (frm, options, query_fn) {
var me = this;
var set_query = function (doctype, parentfield) {
var link_fields = frappe.meta.get_docfields(doctype, frm.doc.name, {
fieldtype: "Link",
options: options,
});
$.each(link_fields, function (i, df) {
if (parentfield) {
frm.set_query(df.fieldname, parentfield, query_fn);
} else {
frm.set_query(df.fieldname, query_fn);
}
});
};
set_query(frm.doc.doctype);
// warehouse field in tables
$.each(
frappe.meta.get_docfields(frm.doc.doctype, frm.doc.name, { fieldtype: "Table" }),
function (i, df) {
set_query(df.options, df.fieldname);
}
);
};
/* if item code is selected in child table
then list down warehouses with its quantity
else apply default filters.
*/
erpnext.queries.setup_warehouse_query = function (frm) {
frm.set_query("warehouse", "items", function (doc, cdt, cdn) {
var row = locals[cdt][cdn];
var filters = erpnext.queries.warehouse(frm.doc);
if (row.item_code) {
$.extend(filters, { query: "erpnext.controllers.queries.warehouse_query" });
filters["filters"].push(["Bin", "item_code", "=", row.item_code]);
}
return filters;
});
};