From e5b19e3f700daf374c90dbcacef3740a74c42f82 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Wed, 2 Nov 2022 20:38:07 +0530 Subject: [PATCH] fix: auto increment qty if item table has no items --- erpnext/public/js/controllers/transaction.js | 7 +++++++ erpnext/public/js/utils/barcode_scanner.js | 9 +++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index 7fecb18fad..96daeef9db 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -341,6 +341,7 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe this.set_dynamic_labels(); this.setup_sms(); this.setup_quality_inspection(); + this.validate_has_items(); } scan_barcode() { @@ -348,6 +349,12 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe barcode_scanner.process_scan(); } + validate_has_items () { + let table = this.frm.doc.items; + this.frm.has_items = (table && table.length + && table[0].qty && table[0].item_code); + } + apply_default_taxes() { var me = this; var taxes_and_charges_field = frappe.meta.get_docfield(me.frm.doc.doctype, "taxes_and_charges", diff --git a/erpnext/public/js/utils/barcode_scanner.js b/erpnext/public/js/utils/barcode_scanner.js index 5d3a16114a..a4f74bdaee 100644 --- a/erpnext/public/js/utils/barcode_scanner.js +++ b/erpnext/public/js/utils/barcode_scanner.js @@ -103,6 +103,7 @@ erpnext.utils.BarcodeScanner = class BarcodeScanner { row = frappe.model.add_child(this.frm.doc, cur_grid.doctype, this.items_table_name); // trigger any row add triggers defined on child table. this.frm.script_manager.trigger(`${this.items_table_name}_add`, row.doctype, row.name); + this.frm.has_items = false; } if (this.is_duplicate_serial_no(row, serial_no)) { @@ -157,8 +158,10 @@ erpnext.utils.BarcodeScanner = class BarcodeScanner { frappe.prompt(__("Please enter quantity for item {0}", [item_code]), ({value}) => { increment(value).then((value) => resolve(value)); }); - } else { + } else if (this.frm.has_items) { this.prepare_item_for_scan(row, item_code, barcode, batch_no, serial_no); + } else { + increment().then((value) => resolve(value)); } }); } @@ -207,7 +210,6 @@ erpnext.utils.BarcodeScanner = class BarcodeScanner { return; } - debugger if (e.target.value) { this.scan_api_call(e.target.value, (r) => { if (r.message) { @@ -280,7 +282,7 @@ erpnext.utils.BarcodeScanner = class BarcodeScanner { } update_dialog_values(scanned_item, r) { - const {item_code, barcode, batch_no, serial_no, uom} = r.message; + const {item_code, barcode, batch_no, serial_no} = r.message; this.dialog.set_value("barcode_scanner", ""); if (item_code === scanned_item && @@ -357,7 +359,6 @@ erpnext.utils.BarcodeScanner = class BarcodeScanner { } async set_batch_no(row, batch_no) { - debugger if (batch_no && frappe.meta.has_field(row.doctype, this.batch_no_field)) { await frappe.model.set_value(row.doctype, row.name, this.batch_no_field, batch_no); }