Skip to Content
Menu
This question has been flagged
1 Reply
3432 Views

I am trying to create a custom function to scan a barcode and execute my custom function.

This what happening.

  1. Tap the icon
  2. open the scanner (in mobile app)
  3. scan the barcode - Vibrate the mobile after scan)
  4.  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.

Avatar
Discard
Best Answer

Where are you encountering an error? What have you done so far? I have implemented a similar solution using a React Native app and WebView. If you provide more information, I may be able to help you.

Avatar
Discard
Related Posts Replies Views Activity
1
Dec 23
2443
2
Aug 23
2220
1
Dec 23
3864
1
Jul 23
2794
0
May 23
2616