fix: Usability fixes to Serial No and batch selector (#18070)

* fix: Usability fixes to Serial No and batch selector

* fix: Codacy

* Update sales_common.js
This commit is contained in:
Deepesh Garg
2019-06-28 14:09:23 +05:30
committed by Nabin Hait
parent c82253e479
commit fdd1422d31
2 changed files with 31 additions and 7 deletions

View File

@@ -45,6 +45,13 @@ erpnext.SerialNoBatchSelector = Class.extend({
label: __(me.warehouse_details.type), label: __(me.warehouse_details.type),
default: me.warehouse_details.name, default: me.warehouse_details.name,
onchange: function(e) { 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(); me.warehouse_details.name = this.get_value();
var batches = this.layout.fields_dict.batches; var batches = this.layout.fields_dict.batches;
if(batches) { if(batches) {
@@ -232,6 +239,15 @@ erpnext.SerialNoBatchSelector = Class.extend({
get_batch_fields: function() { get_batch_fields: function() {
var me = this; 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 [ return [
{ fieldtype: 'Section Break', label: __('Batches') }, { fieldtype: 'Section Break', label: __('Batches') },
{ {
@@ -246,8 +262,8 @@ erpnext.SerialNoBatchSelector = Class.extend({
'in_list_view': 1, 'in_list_view': 1,
get_query: function () { get_query: function () {
return { return {
filters: { item: me.item_code }, filters: filters,
query: 'erpnext.controllers.queries.get_batch_numbers' query: 'erpnext.controllers.queries.get_batch_no'
}; };
}, },
change: function () { change: function () {

View File

@@ -215,6 +215,9 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
}, },
callback:function(r){ callback:function(r){
if (in_list(['Delivery Note', 'Sales Invoice'], doc.doctype)) { 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.set_batch_number(cdt, cdn);
me.batch_no(doc, 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); this._super(doc, cdt, cdn, dont_fetch_price_list_rate);
if(frappe.meta.get_docfield(cdt, "stock_qty", cdn) && if(frappe.meta.get_docfield(cdt, "stock_qty", cdn) &&
in_list(['Delivery Note', 'Sales Invoice'], doc.doctype)) { in_list(['Delivery Note', 'Sales Invoice'], doc.doctype)) {
if (doc.doctype === 'Sales Invoice' && (!doc.update_stock)) return;
this.set_batch_number(cdt, cdn); this.set_batch_number(cdt, cdn);
} }
}, },
qty: function(doc, cdt, cdn) { qty: function(doc, cdt, cdn) {
this._super(doc, cdt, cdn); this._super(doc, 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); this.set_batch_number(cdt, cdn);
}
}, },
/* Determine appropriate batch number and set it in the form. /* Determine appropriate batch number and set it in the form.