增加平板扫码功能

This commit is contained in:
mgw
2023-04-24 16:00:08 +08:00
parent 9300073be4
commit 21f7f55ae8
83 changed files with 309 additions and 272 deletions

View File

@@ -0,0 +1,51 @@
odoo.define('my_module.barcode_handler', function (require) {
"use strict";
var core = require('web.core');
var registry = require('web.field_registry');
var session = require('web.session');
var FieldChar = require('web.basic_fields').FieldChar;
var _t = core._t;
var BarcodeHandlerField = FieldChar.extend({
init: function () {
this._super.apply(this, arguments);
this.scanInProgress = false;
},
willStart: function () {
return this._super.apply(this, arguments).then(() => {
var barcode = this.call('barcode', 'get_barcode');
if (barcode) {
this._onBarcodeScanned(barcode);
}
this.call('barcode', 'start_listening');
});
},
destroy: function () {
this.call('barcode', 'stop_listening');
this._super.apply(this, arguments);
},
_onBarcodeScanned: function (barcode) {
if (this.scanInProgress) {
return;
}
this.scanInProgress = true;
var self = this;
session.rpc('/mrp_barcode/scan_to_open_report_from_form', { barcode: barcode }).then(function (result) {
self.scanInProgress = false;
self.$el.val(result);
self.trigger_up('field_changed', {
dataPointID: self.dataPointID,
changes: { value: result },
});
});
},
});
registry.add('barcode_handlerr', BarcodeHandlerField);
return {
BarcodeHandlerField: BarcodeHandlerField,
};
});