From 329f4e01a3614af8cf1f1a4deadf7409399eac7b Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Wed, 29 Apr 2026 17:28:02 +0530 Subject: [PATCH] fix: correct project filter in buying doctypes (backport #54644) (#54651) fix: correct project filter in buying doctypes (#54644) (cherry picked from commit a04c0285229fe35f8ef778e0a239f06f408d77f0) Co-authored-by: Mihir Kandoi --- .../doctype/purchase_invoice/purchase_invoice.js | 6 ------ .../doctype/purchase_order/purchase_order.js | 6 ------ .../supplier_quotation/supplier_quotation.js | 6 ------ erpnext/public/js/controllers/buying.js | 16 +++++++++------- 4 files changed, 9 insertions(+), 25 deletions(-) diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js index c3836a30b63..0cb9609c6d2 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js @@ -576,12 +576,6 @@ cur_frm.fields_dict["items"].grid.get_field("cost_center").get_query = function }; }; -cur_frm.fields_dict["items"].grid.get_field("project").get_query = function (doc, cdt, cdn) { - return { - filters: [["Project", "status", "not in", "Completed, Cancelled"]], - }; -}; - frappe.ui.form.on("Purchase Invoice", { setup: function (frm) { frm.custom_make_buttons = { diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.js b/erpnext/buying/doctype/purchase_order/purchase_order.js index e77f4b3cdd7..2d1c965154e 100644 --- a/erpnext/buying/doctype/purchase_order/purchase_order.js +++ b/erpnext/buying/doctype/purchase_order/purchase_order.js @@ -793,12 +793,6 @@ cur_frm.cscript.update_status = function (label, status) { }); }; -cur_frm.fields_dict["items"].grid.get_field("project").get_query = function (doc, cdt, cdn) { - return { - filters: [["Project", "status", "not in", "Completed, Cancelled"]], - }; -}; - if (cur_frm.doc.is_old_subcontracting_flow) { cur_frm.fields_dict["items"].grid.get_field("bom").get_query = function (doc, cdt, cdn) { var d = locals[cdt][cdn]; diff --git a/erpnext/buying/doctype/supplier_quotation/supplier_quotation.js b/erpnext/buying/doctype/supplier_quotation/supplier_quotation.js index e81f9f9c988..c0fa8a54041 100644 --- a/erpnext/buying/doctype/supplier_quotation/supplier_quotation.js +++ b/erpnext/buying/doctype/supplier_quotation/supplier_quotation.js @@ -115,9 +115,3 @@ erpnext.buying.SupplierQuotationController = class SupplierQuotationController e // for backward compatibility: combine new and previous states extend_cscript(cur_frm.cscript, new erpnext.buying.SupplierQuotationController({ frm: cur_frm })); - -cur_frm.fields_dict["items"].grid.get_field("project").get_query = function (doc, cdt, cdn) { - return { - filters: [["Project", "status", "not in", "Completed, Cancelled"]], - }; -}; diff --git a/erpnext/public/js/controllers/buying.js b/erpnext/public/js/controllers/buying.js index 37c83483c18..df2355255f4 100644 --- a/erpnext/public/js/controllers/buying.js +++ b/erpnext/public/js/controllers/buying.js @@ -25,13 +25,15 @@ erpnext.buying = { }; }); - this.frm.set_query("project", function (doc) { - return { - filters: { - company: doc.company, - }, - }; - }); + const project_filters = { + query: "erpnext.controllers.queries.get_project_name", + filters: { + company: doc.company, + }, + }; + + this.frm.set_query("project", (_) => project_filters); + this.frm.set_query("project", "items", (_, __, ___) => project_filters); if (this.frm.doc.__islocal && frappe.meta.has_field(this.frm.doc.doctype, "disable_rounded_total")) {