[minor] added filter for batch no field in purchase transaction (#9038)
* [minor] added filter for batch no field in purchase transaction
* [minor] filter the batch based on item_code instead of get_batch_no method
* [minor] filter based on item_code for Purchase Invoice with update stock
diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js
index 6206b28..b508fcb 100644
--- a/erpnext/public/js/controllers/transaction.js
+++ b/erpnext/public/js/controllers/transaction.js
@@ -98,6 +98,13 @@
frm.cscript.calculate_taxes_and_totals();
});
+
+ var me = this;
+ if(this.frm.fields_dict["items"].grid.get_field('batch_no')) {
+ this.frm.set_query("batch_no", "items", function(doc, cdt, cdn) {
+ return me.set_query_for_batch(doc, cdt, cdn)
+ });
+ }
},
onload: function() {
var me = this;
@@ -1129,4 +1136,32 @@
return method
},
+
+ set_query_for_batch: function(doc, cdt, cdn) {
+ // Show item's batches in the dropdown of batch no
+
+ var me = this;
+ var item = frappe.get_doc(cdt, cdn);
+
+ if(!item.item_code) {
+ frappe.throw(__("Please enter Item Code to get batch no"));
+ } else if (doc.doctype == "Purchase Receipt" ||
+ (doc.doctype == "Purchase Invoice" && doc.update_stock)) {
+
+ return {
+ filters: {'item': item.item_code}
+ }
+ } else {
+ filters = {
+ 'item_code': item.item_code,
+ 'posting_date': me.frm.doc.posting_date || frappe.datetime.nowdate(),
+ }
+ if(item.warehouse) filters["warehouse"] = item.warehouse
+
+ return {
+ query : "erpnext.controllers.queries.get_batch_no",
+ filters: filters
+ }
+ }
+ },
});
diff --git a/erpnext/selling/sales_common.js b/erpnext/selling/sales_common.js
index 1fcf334..6233f05 100644
--- a/erpnext/selling/sales_common.js
+++ b/erpnext/selling/sales_common.js
@@ -73,34 +73,6 @@
return me.set_query_for_batch(doc, cdt, cdn)
});
}
-
- if(this.frm.fields_dict["items"].grid.get_field('batch_no')) {
- this.frm.set_query("batch_no", "items", function(doc, cdt, cdn) {
- return me.set_query_for_batch(doc, cdt, cdn)
- });
- }
- },
-
- set_query_for_batch: function(doc, cdt, cdn) {
- // Show item's batches in the dropdown of batch no
-
- var me = this;
- var item = frappe.get_doc(cdt, cdn);
-
- if(!item.item_code) {
- frappe.throw(__("Please enter Item Code to get batch no"));
- } else {
- filters = {
- 'item_code': item.item_code,
- 'posting_date': me.frm.doc.posting_date || frappe.datetime.nowdate(),
- }
- if(item.warehouse) filters["warehouse"] = item.warehouse
-
- return {
- query : "erpnext.controllers.queries.get_batch_no",
- filters: filters
- }
- }
},
refresh: function() {
diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.js b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.js
index 5c97e7c..b4cfcaa 100644
--- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.js
+++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.js
@@ -145,17 +145,6 @@
}
}
-cur_frm.fields_dict['items'].grid.get_field('batch_no').get_query= function(doc, cdt, cdn) {
- var d = locals[cdt][cdn];
- if(d.item_code) {
- return {
- filters: {'item': d.item_code}
- }
- }
- else
- msgprint(__("Please enter Item Code."));
-}
-
cur_frm.cscript.select_print_heading = function(doc, cdt, cdn) {
if(doc.select_print_heading)
cur_frm.pformat.print_heading = doc.select_print_heading;