fix: Blanket Order in SO/PO child tables (#21442)
diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.js b/erpnext/buying/doctype/purchase_order/purchase_order.js
index ed054ae..4a8146a 100644
--- a/erpnext/buying/doctype/purchase_order/purchase_order.js
+++ b/erpnext/buying/doctype/purchase_order/purchase_order.js
@@ -27,15 +27,6 @@
frm.set_indicator_formatter('item_code',
function(doc) { return (doc.qty<=doc.received_qty) ? "green" : "orange" })
- frm.set_query("blanket_order", "items", function() {
- return {
- filters: {
- "company": frm.doc.company,
- "docstatus": 1
- }
- }
- });
-
frm.set_query("expense_account", "items", function() {
return {
query: "erpnext.controllers.queries.get_expense_account",
diff --git a/erpnext/controllers/queries.py b/erpnext/controllers/queries.py
index c14bb66..5febfd6 100644
--- a/erpnext/controllers/queries.py
+++ b/erpnext/controllers/queries.py
@@ -371,6 +371,19 @@
fields = ["name", "parent_account"],
limit_start=start, limit_page_length=page_len, as_list=True)
+def get_blanket_orders(doctype, txt, searchfield, start, page_len, filters):
+ return frappe.db.sql("""select distinct bo.name, bo.blanket_order_type, bo.to_date
+ from `tabBlanket Order` bo, `tabBlanket Order Item` boi
+ where
+ boi.parent = bo.name
+ and boi.item_code = {item_code}
+ and bo.blanket_order_type = '{blanket_order_type}'
+ and bo.company = {company}
+ and bo.docstatus = 1"""
+ .format(item_code = frappe.db.escape(filters.get("item")),
+ blanket_order_type = filters.get("blanket_order_type"),
+ company = frappe.db.escape(filters.get("company"))
+ ))
@frappe.whitelist()
def get_income_account(doctype, txt, searchfield, start, page_len, filters):
diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js
index 5843034..c9d7728 100644
--- a/erpnext/public/js/controllers/transaction.js
+++ b/erpnext/public/js/controllers/transaction.js
@@ -175,6 +175,20 @@
};
}
+ if (this.frm.fields_dict["items"].grid.get_field('blanket_order')) {
+ this.frm.set_query("blanket_order", "items", function(doc, cdt, cdn) {
+ var item = locals[cdt][cdn];
+ return {
+ query: "erpnext.controllers.queries.get_blanket_orders",
+ filters: {
+ "company": doc.company,
+ "blanket_order_type": doc.doctype === "Sales Order" ? "Selling" : "Purchasing",
+ "item": item.item_code
+ }
+ }
+ });
+ }
+
},
onload: function() {
var me = this;
diff --git a/erpnext/selling/doctype/sales_order/sales_order.js b/erpnext/selling/doctype/sales_order/sales_order.js
index 3c1ffe9..45a43c5 100644
--- a/erpnext/selling/doctype/sales_order/sales_order.js
+++ b/erpnext/selling/doctype/sales_order/sales_order.js
@@ -65,15 +65,6 @@
}
});
- frm.set_query("blanket_order", "items", function() {
- return {
- filters: {
- "company": frm.doc.company,
- "docstatus": 1
- }
- }
- });
-
erpnext.queries.setup_warehouse_query(frm);
},
@@ -148,7 +139,7 @@
}
this.frm.add_custom_button(__('Pick List'), () => this.create_pick_list(), __('Create'));
-
+
const order_is_a_sale = ["Sales", "Shopping Cart"].indexOf(doc.order_type) !== -1;
const order_is_maintenance = ["Maintenance"].indexOf(doc.order_type) !== -1;
// order type has been customised then show all the action buttons