[REF] barcodes: remove dead code

Part-of: odoo/odoo#93387
This commit is contained in:
Géry Debongnie
2022-07-04 14:07:26 +02:00
committed by Adrien Dieudonné
parent 2dd2f97de3
commit 5f15909c8a
2 changed files with 0 additions and 147 deletions
@@ -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 = $('<div>').append($('<input>', {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();
},
});
@@ -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: '<form>' +
'<field name="_barcode_scanned" widget="test_barcode_handler"/>' +
'<field name="line_ids">' +
'<tree>' +
'<field name="product_id"/>' +
'<field name="product_barcode" invisible="1"/>' +
'<field name="quantity"/>' +
'</tree>' +
'</field>' +
'</form>',
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);