[fix] values update in items in invoices
diff --git a/erpnext/public/build.json b/erpnext/public/build.json
index 9405719..393e90c 100644
--- a/erpnext/public/build.json
+++ b/erpnext/public/build.json
@@ -30,7 +30,6 @@
"public/js/payment/payment_details.html",
"public/js/templates/item_selector.html",
"public/js/utils/item_selector.js",
- "public/js/utils/serial_no_batch_selector.js",
"public/js/help_links.js",
"public/js/schools/student_button.html",
"public/js/schools/assessment_result_tool.html"
diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js
index 0977361..1801f5a 100644
--- a/erpnext/public/js/controllers/transaction.js
+++ b/erpnext/public/js/controllers/transaction.js
@@ -1,6 +1,8 @@
// 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();
@@ -265,13 +267,12 @@
item_code: function(doc, cdt, cdn, from_barcode) {
var me = this;
var item = frappe.get_doc(cdt, cdn);
- var update_stock = 0, show_batch_dialog = 1;
+ var update_stock = 0, show_batch_dialog = 0;
- if(['Sales Invoice', 'Purchase Invoice'].includes(me.frm.doc.doctype)) {
+ if(['Sales Invoice', 'Purchase Invoice'].includes(this.frm.doc.doctype)) {
update_stock = cint(me.frm.doc.update_stock);
show_batch_dialog = update_stock;
- } else {
- update_stock = 0;
+ } else if(this.frm.doc.doctype === 'Delivery Note') {
show_batch_dialog = 1;
}
@@ -320,7 +321,12 @@
me.frm.script_manager.trigger("price_list_rate", cdt, cdn);
me.toggle_conversion_factor(item);
if(show_batch_dialog) {
- let d = r.message;
+ var d = locals[cdt][cdn];
+ $.each(r.message, function(k, v) {
+ if(!d[k]) {
+ d[k] = v;
+ }
+ });
let serial_no_batch_selector = new erpnext.SerialNoBatchSelector({
frm: me.frm,
item: d,
diff --git a/erpnext/public/js/utils/serial_no_batch_selector.js b/erpnext/public/js/utils/serial_no_batch_selector.js
index c1ec6d4..2b90e3e 100644
--- a/erpnext/public/js/utils/serial_no_batch_selector.js
+++ b/erpnext/public/js/utils/serial_no_batch_selector.js
@@ -5,6 +5,10 @@
// frm, item, warehouse_details, has_batch, oldest
let d = this.item;
+ if(frappe.flags.autofill_item_code) {
+ return;
+ }
+
// Don't show dialog if batch no or serial no already set
if(d && d.has_batch_no && !d.batch_no) {
this.has_batch = 1;
@@ -110,29 +114,29 @@
set_items: function() {
var me = this;
- function get_row_fields(index) {
- index += me.item.idx - 1;
- console.log(index, me.frm.fields_dict.items.grid.grid_rows);
- return me.frm.fields_dict.items.grid
- .grid_rows[index].on_grid_fields_dict;
- }
-
if(this.has_batch) {
this.values.batches.map((batch, i) => {
let row = (i !== 0) ? this.frm.add_child("items") : this.item;
refresh_field("items");
- let fields = (i !== 0) ? get_row_fields(i) : null;
- this.map_row_values(fields, row, batch, 'batch_no',
+ if(i !== 0) {
+ // let index = i + me.item.idx - 1;
+ // let grid_row = me.frm.fields_dict.items.grid.grid_rows[index];
+ // grid_row.toggle_editable_row();
+ // grid_row.on_grid_fields_dict.item_code.set_value(this.item_code);
+ row.item_code = this.item_code;
+ }
+ this.map_row_values(row, batch, 'batch_no',
'selected_qty', this.values.warehouse);
});
} else {
- this.map_row_values(null, this.item, this.values, 'serial_no', 'qty');
+ this.map_row_values(this.item, this.values, 'serial_no', 'qty');
}
+ refresh_field("items");
},
- map_row_values: function(row_fields, row, values, number, qty_field, warehouse) {
+ map_row_values: function(row, values, number, qty_field, warehouse) {
row.qty = values[qty_field];
-
+ row[number] = values[number];
if(this.warehouse_details.type === 'Source Warehouse') {
row.s_warehouse = values.warehouse || warehouse;
} else if(this.warehouse_details.type === 'Target Warehouse') {
@@ -141,14 +145,6 @@
row.warehouse = values.warehouse || warehouse;
}
- row[number] = values[number];
- refresh_field("items");
-
- // Set item_code after setting batch
- // so that dialog does not fire for inserted rows
- if(row_fields) {
- row_fields.item_code.set_value(this.item_code);
- }
},
bind_qty: function() {
@@ -230,7 +226,6 @@
return {filters: {item: me.item_code }};
},
onchange: function(e) {
- console.log(this);
if(this.get_value().length === 0) {
this.grid_row.on_grid_fields_dict
.available_qty.set_value(0);
diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.js b/erpnext/stock/doctype/stock_entry/stock_entry.js
index 3cc7cd1..141faeb 100644
--- a/erpnext/stock/doctype/stock_entry/stock_entry.js
+++ b/erpnext/stock/doctype/stock_entry/stock_entry.js
@@ -1,6 +1,7 @@
// 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) {
@@ -176,7 +177,6 @@
d[k] = v;
});
erpnext.stock.select_batch_and_serial_no(frm, d);
- refresh_field("items");
}
}
});