diff --git a/addons/barcodes/static/src/js/barcode_form_view.js b/addons/barcodes/static/src/js/barcode_form_view.js
index f050ec15cfe..9fa45c55d33 100644
--- a/addons/barcodes/static/src/js/barcode_form_view.js
+++ b/addons/barcodes/static/src/js/barcode_form_view.js
@@ -3,7 +3,6 @@ odoo.define('barcodes.FormView', function (require) {
var concurrency = require('web.concurrency');
var core = require('web.core');
-var Dialog = require('web.Dialog');
var FormController = require('web.FormController');
var FormRenderer = require('web.FormRenderer');
@@ -193,14 +192,12 @@ FormController.include({
*/
_barcodeStartListening: function () {
core.bus.on('barcode_scanned', this, this._barcodeScanned);
- core.bus.on('keypress', this, this._quantityListener);
},
/**
* @private
*/
_barcodeStopListening: function () {
core.bus.off('barcode_scanned', this, this._barcodeScanned);
- core.bus.off('keypress', this, this._quantityListener);
},
/**
* @private
@@ -345,72 +342,6 @@ FormController.include({
});
});
},
- /**
- * @private
- * @param {KeyEvent} event
- */
- _quantityListener: function (event) {
- var character = String.fromCharCode(event.which);
-
- if (! $.contains(event.target, this.el)) {
- return;
- }
- // only catch the event if we're not focused in
- // another field and it's a number
- if (!$(event.target).is('body, .modal') || !/[0-9]/.test(character)) {
- return;
- }
-
- var barcodeInfos = _.filter(this.activeBarcode, 'setQuantityWithKeypress');
- if (!barcodeInfos.length) {
- return;
- }
-
- if (!_.compact(_.pluck(barcodeInfos, 'candidate')).length) {
- return this.displayNotification({ message: _t('Scan a barcode to set the quantity'), type: 'danger' });
- }
-
- for (var k in this.activeBarcode) {
- if (this.activeBarcode[k].candidate) {
- this._quantityOpenDialog(character, this.activeBarcode[k]);
- }
- }
- },
- /**
- * @private
- * @param {string} character
- * @param {Object} activeBarcode: options sent by the field who use barcode features
- */
- _quantityOpenDialog: function (character, activeBarcode) {
- var self = this;
- var $content = $('
').append($('', {type: 'text', class: 'o_set_qty_input'}));
- this.dialog = new Dialog(this, {
- title: _t('Set quantity'),
- buttons: [{text: _t('Select'), classes: 'btn-primary', close: true, click: function () {
- var new_qty = this.$content.find('.o_set_qty_input').val();
- var record = self.model.get(self.handle);
- return self._barcodeSelectedCandidate(activeBarcode.candidate, record,
- self.current_barcode, activeBarcode, parseFloat(new_qty))
- .then(function () {
- self.update({}, {reload: false});
- });
- }}, {text: _t('Discard'), close: true}],
- $content: $content,
- });
- this.dialog.opened().then(function () {
- // This line set the value of the key which triggered the _set_quantity in the input
- var $input = self.dialog.$('.o_set_qty_input').focus().val(character);
- var $selectBtn = self.dialog.$footer.find('.btn-primary');
- $input.on('keypress', function (event){
- if (event.which === 13) {
- event.preventDefault();
- $input.off();
- $selectBtn.click();
- }
- });
- });
- this.dialog.open();
- },
});
diff --git a/addons/barcodes/static/tests/barcode_tests.js b/addons/barcodes/static/tests/barcode_tests.js
index 19b7f3a9402..2609cdeb2dd 100644
--- a/addons/barcodes/static/tests/barcode_tests.js
+++ b/addons/barcodes/static/tests/barcode_tests.js
@@ -13,7 +13,6 @@ var FormView = require('web.FormView');
var testUtils = require('web.test_utils');
var createView = testUtils.createView;
-var triggerKeypressEvent = testUtils.dom.triggerKeypressEvent;
var triggerEvent = testUtils.dom.triggerEvent;
var core = require('web.core');
@@ -438,83 +437,6 @@ QUnit.test('specification of widget barcode_handler', async function (assert) {
delete fieldRegistry.map.test_barcode_handler;
});
-QUnit.test('specification of widget barcode_handler with keypress and notifyChange', async function (assert) {
- assert.expect(6);
- var done = assert.async();
-
- this.data.order.onchanges = {
- _barcode_scanned: function () {},
- };
-
- // Define a specific barcode_handler widget for this test case
- var TestBarcodeHandler = AbstractField.extend({
- init: function () {
- this._super.apply(this, arguments);
-
- this.trigger_up('activeBarcode', {
- name: 'test',
- fieldName: 'line_ids',
- notifyChange: false,
- setQuantityWithKeypress: true,
- quantity: 'quantity',
- commands: {
- barcode: '_barcodeAddX2MQuantity',
- }
- });
- },
- });
- fieldRegistry.add('test_barcode_handler', TestBarcodeHandler);
-
- var form = await createView({
- View: FormView,
- model: 'order',
- data: this.data,
- arch: '',
- mockRPC: function (route, args) {
- assert.step(args.method);
- return this._super.apply(this, arguments);
- },
- res_id: 1,
- viewOptions: {
- mode: 'edit',
- },
- });
- simulateBarCode(['1','2','3','4','5','6','7','8','9','0','Enter']);
- await testUtils.nextTick();
- // Quantity listener should open a dialog.
- triggerKeypressEvent('5');
- await testUtils.nextTick();
-
- setTimeout(async function () {
- var keycode = $.ui.keyCode.ENTER;
-
- assert.strictEqual($('.modal .modal-body').length, 1, 'should open a modal with a quantity as input');
- assert.strictEqual($('.modal .modal-body .o_set_qty_input').val(), '5', 'the quantity by default in the modal shoud be 5');
-
- $('.modal .modal-body .o_set_qty_input').val('7');
- await testUtils.nextTick();
-
- $('.modal .modal-body .o_set_qty_input').trigger($.Event('keypress', {which: keycode, keyCode: keycode}));
- await testUtils.nextTick();
- assert.strictEqual(form.$('.o_data_row .o_data_cell:nth(1)').text(), '7',
- "quantity checked should be 7");
-
- assert.verifySteps(['read', 'read']);
-
- form.destroy();
- delete fieldRegistry.map.test_barcode_handler;
- done();
- });
-});
QUnit.test('barcode_scanned only trigger error for active view', async function (assert) {
assert.expect(2);