From 290f0b94e56cbe92c684fa50b19f69fdef2a8f95 Mon Sep 17 00:00:00 2001 From: Karm Soni Date: Mon, 14 Apr 2025 18:06:44 +0530 Subject: [PATCH] fix: enhance dispatch address query logic and add supplier address query (cherry picked from commit 9a859e54b62d914a574b6e0005c8daebc1f21a86) --- erpnext/public/js/controllers/buying.js | 12 +++++------- erpnext/public/js/queries.js | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/erpnext/public/js/controllers/buying.js b/erpnext/public/js/controllers/buying.js index e0ed9f2b91e..a39a4ddf13a 100644 --- a/erpnext/public/js/controllers/buying.js +++ b/erpnext/public/js/controllers/buying.js @@ -57,13 +57,11 @@ erpnext.buying = { if(this.frm.get_field('dispatch_address')) { this.frm.set_query("dispatch_address", () => { - if(this.frm.doc.supplier) { - return { - query: 'frappe.contacts.doctype.address.address.address_query', - filters: { link_doctype: 'Supplier', link_name: this.frm.doc.supplier } - }; - } else - return erpnext.queries.dispatch_address_query(this.frm.doc) + if(this.frm.doc.is_return){ + return erpnext.queries.company_address_query(this.frm.doc); + } + + return erpnext.queries.supplier_address_query(this.frm.doc); }); } } diff --git a/erpnext/public/js/queries.js b/erpnext/public/js/queries.js index 63651ec8759..cfc602acf00 100644 --- a/erpnext/public/js/queries.js +++ b/erpnext/public/js/queries.js @@ -112,6 +112,23 @@ $.extend(erpnext.queries, { }; }, + supplier_address_query: 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 { + query: "frappe.contacts.doctype.address.address.address_query", + filters: { link_doctype: "Supplier", link_name: doc.supplier }, + }; + }, + dispatch_address_query: function (doc) { var filters = { link_doctype: "Company", link_name: doc.company || "" }; var is_drop_ship = doc.items.some((item) => item.delivered_by_supplier);