fix: Increment batch qty if pre-existing batch is scanned
diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js
index f97d8cf..149582f 100644
--- a/erpnext/public/js/controllers/transaction.js
+++ b/erpnext/public/js/controllers/transaction.js
@@ -378,18 +378,14 @@
let batch_no_scan = Boolean(data.batch_no) && frappe.meta.has_field(cur_grid.doctype, "batch_no");
if (batch_no_scan) {
- let duplicate = this.check_duplicate_batch_scan(data.batch_no);
- if (duplicate) {
- scan_barcode_field.set_value('');
- return;
- }
+ row_to_modify = this.get_batch_row_to_modify(data.batch_no);
} else {
// serial or barcode scan
row_to_modify = this.get_row_to_modify_on_scan(row_to_modify, data);
}
- if (!row_to_modify || batch_no_scan) {
- // add new row if new item scanned or batch is scanned
+ if (!row_to_modify) {
+ // add new row if new item/batch is scanned
row_to_modify = frappe.model.add_child(this.frm.doc, cur_grid.doctype, 'items');
}
@@ -408,8 +404,8 @@
['serial_no', 'batch_no', 'barcode'].forEach(field => {
if (data[field] && frappe.meta.has_field(row_to_modify.doctype, field)) {
let is_serial_no = row_to_modify[field] && field === "serial_no";
-
let value = data[field];
+
if (is_serial_no) {
value = row_to_modify[field] + '\n' + data[field];
}
@@ -436,21 +432,14 @@
return row_to_modify;
}
- check_duplicate_batch_scan(batch_no) {
- // ignore scan if batch already exists in table
+ get_batch_row_to_modify(batch_no) {
+ // get row if batch already exists in table
const existing_batch_row = this.frm.doc.items.find(d => d.batch_no === batch_no);
-
- if (existing_batch_row) {
- frappe.show_alert({
- message: __('Batch {0} already added', [batch_no]),
- indicator: 'orange'
- });
- return true;
- }
- return false;
+ return existing_batch_row || null;
}
show_scan_message (idx, exist = null) {
+ // show new row or qty increase toast
if (exist) {
frappe.show_alert({
message: __('Row #{0}: Qty increased by 1', [idx]),
diff --git a/erpnext/www/shop-by-category/__init__.py b/erpnext/www/shop-by-category/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/erpnext/www/shop-by-category/__init__.py