feat (UX): Refactored batch selector

This commit is contained in:
scmmishra 2019-04-16 12:47:39 +05:30
parent 8ec54c2214
commit 41cf945247

View File

@ -68,10 +68,38 @@ erpnext.SerialNoBatchSelector = Class.extend({
{ {
fieldname: 'qty', fieldname: 'qty',
fieldtype:'Float', fieldtype:'Float',
read_only: 1, read_only: me.has_batch ? 1 : 0,
label: __(me.has_batch ? 'Total Qty' : 'Qty'), label: __(me.has_batch ? 'Total Qty' : 'Qty'),
default: 0 default: 0
}, },
{
fieldname: 'auto_fetch_button',
fieldtype:'Button',
hidden: me.has_batch ? 1 : 0,
label: __(me.has_batch ? 'Fetch Batch Numbers' : 'Fetch Serial Numbers'),
click: (e) => {
// window.abc = this.dialog
// console.log(this.dialog.fields_dict.qty.get_value())
// let auto_fetch_qty_field = this.dialog.fields_dict.qty;
// let fetch_qty = auto_fetch_qty_field.get_value();
let numbers = frappe.call({
method: "erpnext.stock.doctype.serial_no.serial_no.auto_fetch_serial_number",
args: {
qty: this.dialog.fields_dict.qty.get_value(),
item_code: me.item_code,
warehouse: me.warehouse_details.name
}
});
numbers.then((data) => {
let auto_fetched_serial_numbers = data.message;
let serial_no_list_field = this.dialog.fields_dict.serial_no;
numbers = auto_fetched_serial_numbers.join('\n');
serial_no_list_field.set_value(numbers);
// auto_fetch_qty_field.set_value("");
})
}
}
]; ];
if(this.has_batch) { if(this.has_batch) {
@ -234,7 +262,7 @@ erpnext.SerialNoBatchSelector = Class.extend({
var me = this; var me = this;
return [ return [
{fieldtype:'Section Break', label: __('Batches')}, {fieldtype:'Section Break', label: __('Batches')},
{fieldname: 'batches', fieldtype: 'Table', {fieldname: 'batches', fieldtype: 'Table', label: __('Batch Entries'),
fields: [ fields: [
{ {
fieldtype:'Link', fieldtype:'Link',
@ -344,24 +372,6 @@ erpnext.SerialNoBatchSelector = Class.extend({
this.serial_list = []; this.serial_list = [];
return [ return [
{fieldtype: 'Section Break', label: __('Serial No')}, {fieldtype: 'Section Break', label: __('Serial No')},
{
fieldname: 'auto_fetch_toggle',
fieldtype:'Check',
label: __('Fetch based on FIFO'),
default: 0,
onchange: function(e) {
const show_auto_fetch = this.get_value();
if (show_auto_fetch) {
this.layout.set_df_property('auto_qty', 'hidden', 0);
this.layout.set_df_property('auto_fetch_button', 'hidden', 0);
this.layout.set_df_property('serial_no_select', 'hidden', 1);
} else {
this.layout.set_df_property('serial_no_select', 'hidden', 0);
this.layout.set_df_property('auto_qty', 'hidden', 1);
this.layout.set_df_property('auto_fetch_button', 'hidden', 1);
}
}
},
{ {
fieldtype: 'Link', fieldname: 'serial_no_select', options: 'Serial No', fieldtype: 'Link', fieldname: 'serial_no_select', options: 'Serial No',
label: __('Select to add serial no.'), label: __('Select to add serial no.'),
@ -397,47 +407,40 @@ erpnext.SerialNoBatchSelector = Class.extend({
this.in_local_change = 0; this.in_local_change = 0;
} }
}, },
{ // {
fieldname: 'auto_qty', // fieldname: 'auto_fetch_button',
fieldtype:'Float', // fieldtype:'Button',
read_only: 0, // label: __('Fetch Serial Numbers'),
hidden: 1, // read_only: 0,
label: __('Auto Fetch Quantity'), // hidden: 1,
default: 0, // click: (e) => {
}, // // window.abc = this.dialog
{ // console.log(this.dialog.fields_dict.auto_qty.get_value())
fieldname: 'auto_fetch_button', // let auto_fetch_qty_field = this.dialog.fields_dict.auto_qty;
fieldtype:'Button', // let fetch_qty = auto_fetch_qty_field.get_value();
label: __('Fetch Serial Numbers'), // let numbers = frappe.call({
read_only: 0, // method: "erpnext.stock.doctype.serial_no.serial_no.auto_fetch_serial_number",
hidden: 1, // args: {
click: (e) => { // qty: fetch_qty,
// window.abc = this.dialog // item_code: me.item_code,
console.log(this.dialog.fields_dict.auto_qty.get_value()) // warehouse: me.warehouse_details.name
let auto_fetch_qty_field = this.dialog.fields_dict.auto_qty; // }
let fetch_qty = auto_fetch_qty_field.get_value(); // });
let numbers = frappe.call({
method: "erpnext.stock.doctype.serial_no.serial_no.auto_fetch_serial_number",
args: {
qty: fetch_qty,
item_code: me.item_code,
warehouse: me.warehouse_details.name
}
});
numbers.then((data) => { // numbers.then((data) => {
let auto_fetched_serial_numbers = data.message; // let auto_fetched_serial_numbers = data.message;
let serial_no_list_field = this.layout.fields_dict.serial_no; // let serial_no_list_field = this.layout.fields_dict.serial_no;
numbers = auto_fetched_serial_numbers.join('\n'); // numbers = auto_fetched_serial_numbers.join('\n');
serial_no_list_field.set_value(numbers); // serial_no_list_field.set_value(numbers);
auto_fetch_qty_field.set_value(""); // auto_fetch_qty_field.set_value("");
}) // })
} // }
}, // },
{fieldtype: 'Column Break'}, {fieldtype: 'Column Break'},
{ {
fieldname: 'serial_no', fieldname: 'serial_no',
fieldtype: 'Small Text', fieldtype: 'Small Text',
label: __(me.has_batch ? 'Selected Batch Numbers' : 'Selected Serial Numbers'),
onchange: function() { onchange: function() {
me.serial_list = this.get_value() me.serial_list = this.get_value()
.replace(/\n/g, ' ').match(/\S+/g) || []; .replace(/\n/g, ' ').match(/\S+/g) || [];