From c196d740e5f193a88ad269ef2b18ead2f350eb49 Mon Sep 17 00:00:00 2001 From: Makarand Bauskar Date: Fri, 2 Jun 2017 17:28:40 +0530 Subject: [PATCH] [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 --- erpnext/public/js/controllers/transaction.js | 35 +++++++++++++++++++ erpnext/selling/sales_common.js | 28 --------------- .../purchase_receipt/purchase_receipt.js | 11 ------ 3 files changed, 35 insertions(+), 39 deletions(-) diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index 6206b286da..b508fcb692 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -98,6 +98,13 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ 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 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ 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 1fcf334717..6233f05d8b 100644 --- a/erpnext/selling/sales_common.js +++ b/erpnext/selling/sales_common.js @@ -73,34 +73,6 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({ 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 5c97e7cd63..b4cfcaab43 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('project').get_query = function(doc, } } -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;