Skip to content

Commit

Permalink
feat: barcode scanner promise to return scanned row. (frappe#31018)
Browse files Browse the repository at this point in the history
* feat: barcode scanner promise to return scanned row.

* fix: missing reject at alternate code path
  • Loading branch information
dj12djdjs authored and hrwX committed May 20, 2022
1 parent 8182c01 commit 0c44087
Showing 1 changed file with 32 additions and 22 deletions.
54 changes: 32 additions & 22 deletions erpnext/public/js/utils/barcode_scanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,39 @@ erpnext.utils.BarcodeScanner = class BarcodeScanner {
}

process_scan() {
let me = this;
return new Promise((resolve, reject) => {
let me = this;

const input = this.scan_barcode_field.value;
if (!input) {
return;
}
const input = this.scan_barcode_field.value;
if (!input) {
return;
}

frappe
.call({
method: this.scan_api,
args: {
search_value: input,
},
})
.then((r) => {
const data = r && r.message;
if (!data || Object.keys(data).length === 0) {
this.show_alert(__("Cannot find Item with this Barcode"), "red");
this.clean_up();
return;
}

me.update_table(data);
});
frappe
.call({
method: this.scan_api,
args: {
search_value: input,
},
})
.then((r) => {
const data = r && r.message;
if (!data || Object.keys(data).length === 0) {
this.show_alert(__("Cannot find Item with this Barcode"), "red");
this.clean_up();
reject();
return;
}

const row = me.update_table(data);
if (row) {
resolve(row);
}
else {
reject();
}
});
});
}

update_table(data) {
Expand Down Expand Up @@ -90,6 +99,7 @@ erpnext.utils.BarcodeScanner = class BarcodeScanner {
this.set_batch_no(row, batch_no);
this.set_barcode(row, barcode);
this.clean_up();
return row;
}

// batch and serial selector is reduandant when all info can be added by scan
Expand Down

0 comments on commit 0c44087

Please sign in to comment.