From 72d6782865f4cb83a260dcab03bede1cd0c057ce Mon Sep 17 00:00:00 2001 From: Raffael Meyer <14891507+barredterra@users.noreply.github.com> Date: Tue, 26 Nov 2024 20:03:06 +0100 Subject: [PATCH] fix: unify company address query in sales transactions (#44361) * fix: unify company address query in sales transactions * refactor: get the correct field label --- .../doctype/sales_invoice/sales_invoice.js | 14 -------------- erpnext/public/js/queries.js | 6 +++++- erpnext/public/js/utils/sales_common.js | 1 + erpnext/selling/doctype/quotation/quotation.js | 14 -------------- erpnext/selling/doctype/sales_order/sales_order.js | 14 -------------- 5 files changed, 6 insertions(+), 43 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js index 9dbb0a6c82..7b64b1943c 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js @@ -786,20 +786,6 @@ frappe.ui.form.on("Sales Invoice", { }; }); - frm.set_query("company_address", function (doc) { - if (!doc.company) { - frappe.throw(__("Please set Company")); - } - - return { - query: "frappe.contacts.doctype.address.address.address_query", - filters: { - link_doctype: "Company", - link_name: doc.company, - }, - }; - }); - frm.set_query("pos_profile", function (doc) { if (!doc.company) { frappe.throw(__("Please set Company")); diff --git a/erpnext/public/js/queries.js b/erpnext/public/js/queries.js index d7edac3cb9..5350f91746 100644 --- a/erpnext/public/js/queries.js +++ b/erpnext/public/js/queries.js @@ -77,9 +77,13 @@ $.extend(erpnext.queries, { }, company_address_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.address.address.address_query", - filters: { is_your_company_address: 1, link_doctype: "Company", link_name: doc.company || "" }, + filters: { link_doctype: "Company", link_name: doc.company }, }; }, diff --git a/erpnext/public/js/utils/sales_common.js b/erpnext/public/js/utils/sales_common.js index 6055ae421c..23fef95b3c 100644 --- a/erpnext/public/js/utils/sales_common.js +++ b/erpnext/public/js/utils/sales_common.js @@ -52,6 +52,7 @@ erpnext.sales_common = { me.frm.set_query("customer_address", erpnext.queries.address_query); me.frm.set_query("shipping_address_name", erpnext.queries.address_query); me.frm.set_query("dispatch_address_name", erpnext.queries.dispatch_address_query); + me.frm.set_query("company_address", erpnext.queries.company_address_query); erpnext.accounts.dimensions.setup_dimension_filters(me.frm, me.frm.doctype); diff --git a/erpnext/selling/doctype/quotation/quotation.js b/erpnext/selling/doctype/quotation/quotation.js index 94c1f414b3..d3aaaf1096 100644 --- a/erpnext/selling/doctype/quotation/quotation.js +++ b/erpnext/selling/doctype/quotation/quotation.js @@ -24,20 +24,6 @@ frappe.ui.form.on("Quotation", { frm.set_df_property("packed_items", "cannot_add_rows", true); frm.set_df_property("packed_items", "cannot_delete_rows", true); - frm.set_query("company_address", function (doc) { - if (!doc.company) { - frappe.throw(__("Please set Company")); - } - - return { - query: "frappe.contacts.doctype.address.address.address_query", - filters: { - link_doctype: "Company", - link_name: doc.company, - }, - }; - }); - frm.set_query("serial_and_batch_bundle", "packed_items", (doc, cdt, cdn) => { let row = locals[cdt][cdn]; return { diff --git a/erpnext/selling/doctype/sales_order/sales_order.js b/erpnext/selling/doctype/sales_order/sales_order.js index 24e4b4afd0..ed2a73201e 100644 --- a/erpnext/selling/doctype/sales_order/sales_order.js +++ b/erpnext/selling/doctype/sales_order/sales_order.js @@ -26,20 +26,6 @@ frappe.ui.form.on("Sales Order", { return doc.stock_qty <= doc.delivered_qty ? "green" : "orange"; }); - frm.set_query("company_address", function (doc) { - if (!doc.company) { - frappe.throw(__("Please set Company")); - } - - return { - query: "frappe.contacts.doctype.address.address.address_query", - filters: { - link_doctype: "Company", - link_name: doc.company, - }, - }; - }); - frm.set_query("bom_no", "items", function (doc, cdt, cdn) { var row = locals[cdt][cdn]; return { -- GitLab