From fef7cfb888bd976b3b8596bc867dc5cd0aff1e52 Mon Sep 17 00:00:00 2001 From: Raffael Meyer <14891507+barredterra@users.noreply.github.com> Date: Tue, 26 Nov 2024 21:11:27 +0100 Subject: [PATCH] fix: unify company address query in sales transactions (backport #44361) (#44366) * fix: unify company address query in sales transactions (backport #44361) * style: add whitespace --- .../doctype/sales_invoice/sales_invoice.js | 14 -------------- erpnext/public/js/queries.js | 6 +++++- erpnext/selling/doctype/quotation/quotation.js | 14 -------------- erpnext/selling/doctype/sales_order/sales_order.js | 14 -------------- erpnext/selling/sales_common.js | 1 + 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 dffd5d98c4f..73e51f2fcb4 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js @@ -667,20 +667,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 b7e685cd6fb..4bdd463f047 100644 --- a/erpnext/public/js/queries.js +++ b/erpnext/public/js/queries.js @@ -85,9 +85,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/selling/doctype/quotation/quotation.js b/erpnext/selling/doctype/quotation/quotation.js index d2f565ef70e..5d9966754bb 100644 --- a/erpnext/selling/doctype/quotation/quotation.js +++ b/erpnext/selling/doctype/quotation/quotation.js @@ -20,20 +20,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 - } - }; - }); }, refresh: function(frm) { diff --git a/erpnext/selling/doctype/sales_order/sales_order.js b/erpnext/selling/doctype/sales_order/sales_order.js index 7bdaab75a53..0d9a0e2e8b3 100644 --- a/erpnext/selling/doctype/sales_order/sales_order.js +++ b/erpnext/selling/doctype/sales_order/sales_order.js @@ -21,20 +21,6 @@ frappe.ui.form.on("Sales Order", { frm.set_indicator_formatter('item_code', function(doc) { 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 { diff --git a/erpnext/selling/sales_common.js b/erpnext/selling/sales_common.js index ad2f1e5f282..0293f37d0ad 100644 --- a/erpnext/selling/sales_common.js +++ b/erpnext/selling/sales_common.js @@ -40,6 +40,7 @@ erpnext.selling.SellingController = class SellingController extends erpnext.Tran 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);