From 8beca68948410e8d71bc905848dbea08b3d0bd76 Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Mon, 16 Sep 2019 15:20:10 +0530 Subject: [PATCH] feat: Scan Barcode using Camera in mobile (#19033) * feat: Scan Barcode using Camera in mobile * fix: Use input-group for scan button * fix: Muted camera button --- erpnext/public/js/controllers/transaction.js | 26 ++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index 844db996a2..a9b19eddd7 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -277,8 +277,30 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ this.set_dynamic_labels(); this.setup_sms(); this.setup_quality_inspection(); - this.frm.fields_dict["scan_barcode"] && this.frm.fields_dict["scan_barcode"].set_value(""); - this.frm.fields_dict["scan_barcode"] && this.frm.fields_dict["scan_barcode"].set_new_description(""); + let scan_barcode_field = this.frm.get_field('scan_barcode'); + if (scan_barcode_field) { + scan_barcode_field.set_value(""); + scan_barcode_field.set_new_description(""); + + if (frappe.is_mobile()) { + if (scan_barcode_field.$input_wrapper.find('.input-group').length) return; + + let $input_group = $('
'); + scan_barcode_field.$input_wrapper.find('.control-input').append($input_group); + $input_group.append(scan_barcode_field.$input); + $(` + + `) + .on('click', '.btn', () => { + frappe.barcode.scan_barcode().then(barcode => { + scan_barcode_field.set_value(barcode); + }); + }) + .appendTo($input_group); + } + } }, scan_barcode: function() {