diff --git a/erpnext/public/js/utils/serial_no_batch_selector.js b/erpnext/public/js/utils/serial_no_batch_selector.js index 0202bbb872a..576ae0fbde1 100644 --- a/erpnext/public/js/utils/serial_no_batch_selector.js +++ b/erpnext/public/js/utils/serial_no_batch_selector.js @@ -45,6 +45,13 @@ erpnext.SerialNoBatchSelector = Class.extend({ label: __(me.warehouse_details.type), default: me.warehouse_details.name, onchange: function(e) { + + if(me.has_batch) { + fields = fields.concat(me.get_batch_fields()); + } else { + fields = fields.concat(me.get_serial_no_fields()); + } + me.warehouse_details.name = this.get_value(); var batches = this.layout.fields_dict.batches; if(batches) { @@ -232,6 +239,15 @@ erpnext.SerialNoBatchSelector = Class.extend({ get_batch_fields: function() { var me = this; + + let filters = { + item_code: me.item_code + } + + if (me.warehouse || me.warehouse_details.name) { + filters['warehouse'] = me.warehouse || me.warehouse_details.name; + } + return [ { fieldtype: 'Section Break', label: __('Batches') }, { @@ -246,8 +262,8 @@ erpnext.SerialNoBatchSelector = Class.extend({ 'in_list_view': 1, get_query: function () { return { - filters: { item: me.item_code }, - query: 'erpnext.controllers.queries.get_batch_numbers' + filters: filters, + query: 'erpnext.controllers.queries.get_batch_no' }; }, change: function () { diff --git a/erpnext/selling/sales_common.js b/erpnext/selling/sales_common.js index c431df403aa..b1b64a3e4ec 100644 --- a/erpnext/selling/sales_common.js +++ b/erpnext/selling/sales_common.js @@ -184,7 +184,7 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({ this.calculate_incentive(sales_person); refresh_field(["allocated_percentage", "allocated_amount", "commission_rate","incentives"], sales_person.name, sales_person.parentfield); - } + } }, sales_person: function(doc, cdt, cdn) { @@ -215,6 +215,9 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({ }, callback:function(r){ if (in_list(['Delivery Note', 'Sales Invoice'], doc.doctype)) { + + if (doc.doctype === 'Sales Invoice' && (!doc.update_stock)) return; + me.set_batch_number(cdt, cdn); me.batch_no(doc, cdt, cdn); } @@ -358,13 +361,18 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({ this._super(doc, cdt, cdn, dont_fetch_price_list_rate); if(frappe.meta.get_docfield(cdt, "stock_qty", cdn) && in_list(['Delivery Note', 'Sales Invoice'], doc.doctype)) { - this.set_batch_number(cdt, cdn); - } + if (doc.doctype === 'Sales Invoice' && (!doc.update_stock)) return; + this.set_batch_number(cdt, cdn); + } }, qty: function(doc, cdt, cdn) { this._super(doc, cdt, cdn); - this.set_batch_number(cdt, cdn); + + if(in_list(['Delivery Note', 'Sales Invoice'], doc.doctype)) { + if (doc.doctype === 'Sales Invoice' && (!doc.update_stock)) return; + this.set_batch_number(cdt, cdn); + } }, /* Determine appropriate batch number and set it in the form. @@ -396,7 +404,7 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({ if (doc.auto_repeat) { frappe.call({ method:"frappe.desk.doctype.auto_repeat.auto_repeat.update_reference", - args:{ + args:{ docname: doc.auto_repeat, reference:doc.name },