async call to require, more validation
This commit is contained in:
parent
5f389c999a
commit
ae450fc23b
@ -1,8 +1,6 @@
|
||||
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
||||
// License: GNU General Public License v3. See license.txt
|
||||
|
||||
frappe.require("assets/erpnext/js/utils/serial_no_batch_selector.js");
|
||||
|
||||
erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
||||
setup: function() {
|
||||
this._super();
|
||||
@ -272,8 +270,10 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
||||
if(['Sales Invoice', 'Purchase Invoice'].includes(this.frm.doc.doctype)) {
|
||||
update_stock = cint(me.frm.doc.update_stock);
|
||||
show_batch_dialog = update_stock;
|
||||
} else if(this.frm.doc.doctype === 'Delivery Note') {
|
||||
show_batch_dialog = 1;
|
||||
|
||||
} else if((this.frm.doc.doctype === 'Purchase Receipt' && me.frm.doc.is_return) ||
|
||||
this.frm.doc.doctype === 'Delivery Note') {
|
||||
show_batch_dialog = 1;
|
||||
}
|
||||
|
||||
// clear barcode if setting item (else barcode will take priority)
|
||||
@ -323,19 +323,9 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
||||
if(show_batch_dialog) {
|
||||
var d = locals[cdt][cdn];
|
||||
$.each(r.message, function(k, v) {
|
||||
if(!d[k]) {
|
||||
d[k] = v;
|
||||
}
|
||||
if(!d[k]) d[k] = v;
|
||||
});
|
||||
let serial_no_batch_selector = new erpnext.SerialNoBatchSelector({
|
||||
frm: me.frm,
|
||||
item: d,
|
||||
warehouse_details: {
|
||||
type: "Warehouse",
|
||||
name: d.warehouse
|
||||
},
|
||||
});
|
||||
refresh_field("items");
|
||||
erpnext.show_serial_batch_selector(me.frm, d);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1193,3 +1183,16 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
erpnext.show_serial_batch_selector = function(frm, d) {
|
||||
frappe.require("assets/erpnext/js/utils/serial_no_batch_selector.js", function() {
|
||||
let serial_no_batch_selector = new erpnext.SerialNoBatchSelector({
|
||||
frm: frm,
|
||||
item: d,
|
||||
warehouse_details: {
|
||||
type: "Warehouse",
|
||||
name: d.warehouse
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -31,8 +31,14 @@ erpnext.SerialNoBatchSelector = Class.extend({
|
||||
this.data = this.oldest ? this.oldest : [];
|
||||
let title = "";
|
||||
let fields = [
|
||||
{fieldname: 'item_code', read_only: 1, fieldtype:'Link', options: 'Item',
|
||||
label: __('Item Code'), 'default': me.item_code},
|
||||
{
|
||||
fieldname: 'item_code',
|
||||
read_only: 1,
|
||||
fieldtype:'Link',
|
||||
options: 'Item',
|
||||
label: __('Item Code'),
|
||||
default: me.item_code
|
||||
},
|
||||
{fieldtype:'Column Break'},
|
||||
{
|
||||
fieldname: 'warehouse',
|
||||
@ -51,7 +57,13 @@ erpnext.SerialNoBatchSelector = Class.extend({
|
||||
}
|
||||
},
|
||||
{fieldtype:'Column Break'},
|
||||
{fieldname: 'qty', fieldtype:'Float', label: __(me.has_batch ? 'Total Qty' : 'Qty'), 'default': me.qty},
|
||||
{
|
||||
fieldname: 'qty',
|
||||
fieldtype:'Float',
|
||||
read_only: 1,
|
||||
label: __(me.has_batch ? 'Total Qty' : 'Qty'),
|
||||
default: me.qty
|
||||
},
|
||||
];
|
||||
|
||||
if(this.has_batch) {
|
||||
@ -226,11 +238,23 @@ erpnext.SerialNoBatchSelector = Class.extend({
|
||||
return {filters: {item: me.item_code }};
|
||||
},
|
||||
onchange: function(e) {
|
||||
if(this.get_value().length === 0) {
|
||||
let val = this.get_value();
|
||||
if(val.length === 0) {
|
||||
this.grid_row.on_grid_fields_dict
|
||||
.available_qty.set_value(0);
|
||||
return;
|
||||
}
|
||||
let selected_batches = this.grid.grid_rows.map((row) => {
|
||||
if(row === this.grid_row) {
|
||||
return "";
|
||||
}
|
||||
return row.on_grid_fields_dict.batch_no.get_value();
|
||||
});
|
||||
if(selected_batches.includes(val)) {
|
||||
this.set_value("");
|
||||
frappe.throw(__(`Batch ${val} already selected.`));
|
||||
return;
|
||||
}
|
||||
if(me.warehouse_details.name) {
|
||||
frappe.call({
|
||||
method: 'erpnext.stock.doctype.batch.batch.get_batch_qty',
|
||||
@ -246,6 +270,7 @@ erpnext.SerialNoBatchSelector = Class.extend({
|
||||
});
|
||||
|
||||
} else {
|
||||
this.set_value("");
|
||||
frappe.throw(__(`Please select a warehouse to get available
|
||||
quantities`));
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt
|
||||
|
||||
frappe.provide("erpnext.stock");
|
||||
frappe.require("assets/erpnext/js/utils/serial_no_batch_selector.js");
|
||||
|
||||
frappe.ui.form.on('Stock Entry', {
|
||||
setup: function(frm) {
|
||||
@ -569,9 +568,12 @@ erpnext.stock.select_batch_and_serial_no = (frm, item) => {
|
||||
return;
|
||||
}
|
||||
|
||||
let serial_no_batch_selector = new erpnext.SerialNoBatchSelector({
|
||||
frm: frm,
|
||||
item: item,
|
||||
warehouse_details: get_warehouse_type_and_name(item),
|
||||
frappe.require("assets/erpnext/js/utils/serial_no_batch_selector.js", function() {
|
||||
let serial_no_batch_selector = new erpnext.SerialNoBatchSelector({
|
||||
frm: frm,
|
||||
item: item,
|
||||
warehouse_details: get_warehouse_type_and_name(item),
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user