fix: Available qty not shown in item batch selector for batch

This commit is contained in:
deepeshgarg007 2019-06-10 17:33:36 +05:30
parent dde4f93137
commit 30f7e7be87

View File

@ -268,26 +268,27 @@ erpnext.SerialNoBatchSelector = Class.extend({
{fieldname: 'batches', fieldtype: 'Table', label: __('Batch Entries'), {fieldname: 'batches', fieldtype: 'Table', label: __('Batch Entries'),
fields: [ fields: [
{ {
fieldtype:'Link', 'fieldtype': 'Link',
fieldname:'batch_no', 'read_only': 0,
options: 'Batch', 'fieldname': 'batch_no',
label: __('Select Batch'), 'options': 'Batch',
in_list_view:1, 'label': __('Select Batch'),
get_query: function() { 'in_list_view': 1,
get_query: function () {
return { return {
filters: {item: me.item_code }, filters: { item: me.item_code },
query: 'erpnext.controllers.queries.get_batch_numbers' query: 'erpnext.controllers.queries.get_batch_numbers'
}; };
}, },
onchange: function(e) { change: function (e) {
let val = this.get_value(); let val = this.get_value();
if(val.length === 0) { if (val.length === 0) {
this.grid_row.on_grid_fields_dict this.grid_row.on_grid_fields_dict
.available_qty.set_value(0); .available_qty.set_value(0);
return; return;
} }
let selected_batches = this.grid.grid_rows.map((row) => { let selected_batches = this.grid.grid_rows.map((row) => {
if(row === this.grid_row) { if (row === this.grid_row) {
return ""; return "";
} }
@ -295,12 +296,12 @@ erpnext.SerialNoBatchSelector = Class.extend({
return row.on_grid_fields_dict.batch_no.get_value(); return row.on_grid_fields_dict.batch_no.get_value();
} }
}); });
if(selected_batches.includes(val)) { if (selected_batches.includes(val)) {
this.set_value(""); this.set_value("");
frappe.throw(__(`Batch ${val} already selected.`)); frappe.throw(__(`Batch ${val} already selected.`));
return; return;
} }
if(me.warehouse_details.name) { if (me.warehouse_details.name) {
frappe.call({ frappe.call({
method: 'erpnext.stock.doctype.batch.batch.get_batch_qty', method: 'erpnext.stock.doctype.batch.batch.get_batch_qty',
args: { args: {
@ -323,31 +324,32 @@ erpnext.SerialNoBatchSelector = Class.extend({
} }
}, },
{ {
fieldtype:'Float', 'fieldtype': 'Float',
read_only:1, 'read_only': 1,
fieldname:'available_qty', 'fieldname': 'available_qty',
label: __('Available'), 'label': __('Available'),
in_list_view:1, 'in_list_view': 1,
default: 0, 'default': 0,
onchange: function() { change: function () {
this.grid_row.on_grid_fields_dict.selected_qty.set_value('0'); this.grid_row.on_grid_fields_dict.selected_qty.set_value('0');
} }
}, },
{ {
fieldtype:'Float', 'fieldtype': 'Float',
fieldname:'selected_qty', 'read_only': 0,
label: __('Qty'), 'fieldname': 'selected_qty',
in_list_view:1, 'label': __('Qty'),
'in_list_view': 1,
'default': 0, 'default': 0,
onchange: function(e) { change: function (e) {
var batch_no = this.grid_row.on_grid_fields_dict.batch_no.get_value(); var batch_no = this.grid_row.on_grid_fields_dict.batch_no.get_value();
var available_qty = this.grid_row.on_grid_fields_dict.available_qty.get_value(); var available_qty = this.grid_row.on_grid_fields_dict.available_qty.get_value();
var selected_qty = this.grid_row.on_grid_fields_dict.selected_qty.get_value(); var selected_qty = this.grid_row.on_grid_fields_dict.selected_qty.get_value();
if(batch_no.length === 0 && parseInt(selected_qty)!==0) { if (batch_no.length === 0 && parseInt(selected_qty) !== 0) {
frappe.throw(__("Please select a batch")); frappe.throw(__("Please select a batch"));
} }
if(me.warehouse_details.type === 'Source Warehouse' && if (me.warehouse_details.type === 'Source Warehouse' &&
parseFloat(available_qty) < parseFloat(selected_qty)) { parseFloat(available_qty) < parseFloat(selected_qty)) {
this.set_value('0'); this.set_value('0');
@ -363,7 +365,7 @@ erpnext.SerialNoBatchSelector = Class.extend({
], ],
in_place_edit: true, in_place_edit: true,
data: this.data, data: this.data,
get_data: function() { get_data: function () {
return this.data; return this.data;
}, },
} }