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);