I am trying to create a custom function to scan a barcode and execute my custom function.
This what happening.
- Tap the icon
- open the scanner (in mobile app)
- scan the barcode - Vibrate the mobile after scan)
- Then it shows a toast/warning message on top right corner ' You are expected to scan one or more products.'
Expected out put was, scan the barcode and execute my custom function.
Here is my code.
odoo.define('basket_verification.add_basket',function (require){
'use strict';
var core = require('web.core');
var Widget = require('web.Widget');
var Dialog = require('web.Dialog');
var QWeb = core.qweb;
var LinesWidget = require('stock_barcode.LinesWidget');
const mobile = require('web_mobile.core');
LinesWidget.include({
events:_.extend({}, LinesWidget.prototype.events,{
'click .o_scan_basket': 'open_mobile_scanner_basket',
}),
init: function (parent, page, pageIndex, nbPages) {
this._super.apply(this, arguments);
console.log('parent.actionParams',parent.actionParams);
// this.basket_ids = parent.basket_ids;
this.action_params = parent.actionParams;
},
open_mobile_scanner_basket:function(){
console.log('am here');
var self = this;
openMobileScannerBasket(function (barcode) {
_onBasketBarcodeScanned(barcode);
});
},
_onBasketBarcodeScanned: function (barcode){
console.log('am here');
var self = this;
core.bus.off('barcode_scanned', this, this._onBarcodeScanned);
this._rpc({
model: 'stock.picking',
method: 'set_basket',
args: [this.action_params.id,this.action_params.id,barcode,]
}).then(function (res){
console.log('rec',res);
$('.basket_barcode_input').val('');
var message = res['result'];
if (res['status'] == true){
mobile.methods.showToast({'message':_t(message)});
// Dialog.alert(self, message);
}
else{
mobile.methods.showToast({'message':_t(message)});
// Dialog.alert(self, message);
}
});
},
openMobileScannerBasket(callback){
mobile.methods.scanBarcode().then(function (response){
mobile.methods.showToast({'response':_t(response)});
var barcode = response.data;
mobile.methods.showToast({'scanned barcode':_t(barcode)});
if (barcode){
callback(barcode);
mobile.methods.vibrate({'duration':100});
mobile.methods.showToast({'scanned barcode':_t(barcode)});
} else {
mobile.methods.showToast({'message':_t('Please, Scan again !!')});
}
});
},
});
Any solution pls?
I am using Odoo.sh.