diff options
| author | Christophe Simonis <chs@odoo.com> | 2017-08-31 12:55:41 +0200 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2017-08-31 12:55:41 +0200 |
| commit | 4879ce040797fd4a47b6b8326c3aacd365c8ab91 (patch) | |
| tree | 45479b47c5dcfba0d0ced4f05d770b0852f31263 /addons/barcodes | |
| parent | dae6178a0a5629ce678b20fcc9226caa44a5b0ce (diff) | |
| parent | fe77df3ba480d40b3d6b25736397bd52c684ce03 (diff) | |
[MERGE] forward port branch saas-17 up to fe77df3ba48
Diffstat (limited to 'addons/barcodes')
| -rw-r--r-- | addons/barcodes/static/src/js/barcode_events.js | 22 | ||||
| -rw-r--r-- | addons/barcodes/static/src/js/barcode_field.js | 24 | ||||
| -rw-r--r-- | addons/barcodes/static/src/js/barcode_form_view.js | 118 | ||||
| -rw-r--r-- | addons/barcodes/static/tests/barcode_tests.js | 406 | ||||
| -rw-r--r-- | addons/barcodes/views/barcodes_templates.xml | 6 |
5 files changed, 527 insertions, 49 deletions
diff --git a/addons/barcodes/static/src/js/barcode_events.js b/addons/barcodes/static/src/js/barcode_events.js index 04c03a41308..0f13c59fe66 100644 --- a/addons/barcodes/static/src/js/barcode_events.js +++ b/addons/barcodes/static/src/js/barcode_events.js @@ -77,13 +77,7 @@ var BarcodeEvents = core.Class.extend(mixins.PropertiesMixin, { 'bubbles': old_event.bubbles, 'cancelable': old_event.cancelable, }; - try { - new_event = new Event("keypress", params); - } catch(error) { - // For IE >= 9, use new CustomEvent(), instead of new Event() - new_event = new CustomEvent("keypress", params); - } - + new_event = $.Event('keypress', params); new_event.viewArg = old_event.viewArg; new_event.ctrl = old_event.ctrl; new_event.alt = old_event.alt; @@ -96,7 +90,7 @@ var BarcodeEvents = core.Class.extend(mixins.PropertiesMixin, { new_event.which = old_event.which; new_event.dispatched_by_barcode_reader = true; - old_event.target.dispatchEvent(new_event); + $(old_event.target).trigger(new_event); } } }, @@ -173,17 +167,17 @@ var BarcodeEvents = core.Class.extend(mixins.PropertiesMixin, { }, start: function(prevent_key_repeat){ - document.body.addEventListener('keypress', this.__handler, true); + $('body').bind("keypress", this.__handler); if (prevent_key_repeat === true) { - document.body.addEventListener('keydown', this.__keydown_handler, true); - document.body.addEventListener('keyup', this.__keyup_handler, true); + $('body').bind("keydown", this.__keydown_handler); + $('body').bind('keyup', this.__keyup_handler); } }, stop: function(){ - document.body.removeEventListener('keypress', this.__handler, true); - document.body.removeEventListener('keydown', this.__keydown_handler, true); - document.body.removeEventListener('keyup', this.__keyup_handler, true); + $('body').unbind("keypress", this.__handler); + $('body').unbind("keydown", this.__keydown_handler); + $('body').unbind('keyup', this.__keyup_handler); }, }); diff --git a/addons/barcodes/static/src/js/barcode_field.js b/addons/barcodes/static/src/js/barcode_field.js index aa31b4d8261..7b9b29aa4c8 100644 --- a/addons/barcodes/static/src/js/barcode_field.js +++ b/addons/barcodes/static/src/js/barcode_field.js @@ -8,12 +8,12 @@ var fieldRegistry = require('web.field_registry'); // Field in which the user can both type normally and scan barcodes var FieldFloatScannable = basicFields.FieldFloat.extend({ - events: { + events: _.extend({}, basicFields.FieldFloat.prototype.events, { // The barcode_events component intercepts keypresses and releases them when it // appears they are not part of a barcode. But since released keypresses don't // trigger native behaviour (like characters input), we must simulate it. 'keypress': '_onKeypress', - }, + }), //-------------------------------------------------------------------------- // Private @@ -40,9 +40,8 @@ var FieldFloatScannable = basicFields.FieldFloat.extend({ */ _onKeypress: function (e) { /* only simulate a keypress if it has been previously prevented */ - if (e.originalEvent.dispatched_by_barcode_reader !== true) { + if (e.dispatched_by_barcode_reader !== true) { e.preventDefault(); - this.$input.blur(); return; } var character = String.fromCharCode(e.which); @@ -52,23 +51,12 @@ var FieldFloatScannable = basicFields.FieldFloat.extend({ e.target.value = str_before_carret + character + str_after_carret; var new_carret_index = str_before_carret.length + character.length; e.target.setSelectionRange(new_carret_index, new_carret_index); - // Note: FieldChar (that FieldFloat extends) calls store_dom_value upon change - // event, which is triggered when the input loses focus and its internal dirty - // flag is set. But here, we directly modify the value property of the input, - // which doesn't set the dirty flag. So we could call store_dom_value upon blur. - // But we also want the DOM value to be stored when a barcode_event occurs and - // triggers an onchange. We could listen to barcode_event in order to call - // store_dom_value, but that would have to happen before the onchange is triggered. - // So the safest method is still to store the value each time it changes. - // This long explanation is here to avoid having to do the thinking all over agan - // in case this strategy doesn't work / breaks. - // TL;DR Safest way not to lose the value when a barcode scan triggers an onchange. - this._setValue(e.target.value); + // trigger an 'input' event to notify the widget that it's value changed + $(e.target).trigger('input'); }, }); // Field to use scan barcodes - var FormViewBarcodeHandler = AbstractField.extend({ /** * @override @@ -78,8 +66,6 @@ var FormViewBarcodeHandler = AbstractField.extend({ this.trigger_up('activeBarcode', { name: this.name, - fieldName: 'pack_operation_product_ids', - quantity: 'qty_done', commands: { barcode: '_barcodeAddX2MQuantity', } diff --git a/addons/barcodes/static/src/js/barcode_form_view.js b/addons/barcodes/static/src/js/barcode_form_view.js index 73df8a3c03f..da90b198352 100644 --- a/addons/barcodes/static/src/js/barcode_form_view.js +++ b/addons/barcodes/static/src/js/barcode_form_view.js @@ -26,19 +26,23 @@ FormController.include({ this.activeBarcode = { form_view: { commands: { - 'O-CMD.NEW': 'createRecord', - 'O-CMD.EDIT': 'toEditMode', - 'O-CMD.CANCEL': 'discardChange', - 'O-CMD.SAVE': function () { return this.saveRecord({reload: true}); }, - // 'O-CMD.PAGER-PREV': - // 'O-CMD.PAGER-NEXT': - } - } + 'O-CMD.EDIT': this._barcodeEdit.bind(this), + 'O-CMD.CANCEL': this._barcodeDiscard.bind(this), + 'O-CMD.SAVE': this._barcodeSave.bind(this), + 'O-CMD.PAGER-PREV': this._barcodePagerPrevious.bind(this), + 'O-CMD.PAGER-NEXT': this._barcodePagerNext.bind(this), + 'O-CMD.PAGER-FIRST': this._barcodePagerFirst.bind(this), + 'O-CMD.PAGER-LAST': this._barcodePagerLast.bind(this), + }, + }, }; this.barcodeMutex = new concurrency.Mutex(); this._barcodeStartListening(); }, + /** + * @override + */ destroy: function () { this._barcodeStopListening(); this._super(); @@ -71,6 +75,55 @@ FormController.include({ }, /** * @private + */ + _barcodeDiscard: function () { + return this.discardChanges(); + }, + /** + * @private + */ + _barcodeEdit: function () { + return this._setMode('edit'); + }, + /** + * @private + */ + _barcodePagerFirst: function () { + var self = this; + return this.mutex.exec(function () {}).then(function () { + self.pager.updateState({ + current_min: 1, + }, {notifyChange: true}); + }); + }, + /** + * @private + */ + _barcodePagerLast: function () { + var self = this; + return this.mutex.exec(function () {}).then(function () { + var state = self.model.get(self.handle, {raw: true}); + self.pager.updateState({ + current_min: state.count, + }, {notifyChange: true}); + }); + }, + /** + * @private + */ + _barcodePagerNext: function () { + return this.mutex.exec(function () {}).then(this.pager.next.bind(this.pager)); + }, + /** + * @private + */ + _barcodePagerPrevious: function () { + return this.mutex.exec(function () {}).then(this.pager.previous.bind(this.pager)); + }, + /** + * Returns true iff the given barcode matches the given record (candidate). + * + * @private * @param {Object} candidate: record in the x2m * @param {string} barcode sent by the scanner (string generate from keypress series) * @param {Object} activeBarcode: options sent by the field who use barcode features @@ -81,6 +134,12 @@ FormController.include({ }, /** * @private + */ + _barcodeSave: function () { + return this.saveRecord(); + }, + /** + * @private * @param {Object} candidate: record in the x2m * @param {Object} current record * @param {string} barcode sent by the scanner (string generate from keypress series) @@ -89,8 +148,14 @@ FormController.include({ */ _barcodeSelectedCandidate: function (candidate, record, barcode, activeBarcode) { var changes = {}; - changes[activeBarcode.quantity] = candidate.data[activeBarcode.quantity] + 1; - return this.model.notifyChanges(candidate.id, changes); + var candidateChanges = {}; + candidateChanges[activeBarcode.quantity] = candidate.data[activeBarcode.quantity] + 1; + changes[activeBarcode.fieldName] = { + operation: 'UPDATE', + id: candidate.id, + data: candidateChanges, + }; + return this.model.notifyChanges(this.handle, changes); }, /** * @private @@ -99,7 +164,6 @@ FormController.include({ core.bus.on('barcode_scanned', this, this._barcodeScanned); core.bus.on('keypress', this, this._quantityListener); }, - /** * @private */ @@ -128,7 +192,7 @@ FormController.include({ */ _getBarCodeRecord: function (record, barcode, activeBarcode) { var self = this; - if (!activeBarcode.fieldName) { + if (!activeBarcode.fieldName || !record.data[activeBarcode.fieldName]) { return; } return _.find(record.data[activeBarcode.fieldName].data, function (record) { @@ -167,6 +231,10 @@ FormController.include({ candidate: this.activeBarcode[name] && this.activeBarcode[name].handle === this.handle ? this.activeBarcode[name].candidate : null, }; + + // we want to disable autofocus when activating the barcode to avoid + // putting the scanned value in the focused field + this.disableAutofocus = true; }, /** * @private @@ -232,8 +300,13 @@ FormController.include({ if (prefixed && !hasCommand) { self.do_warn(_t('Error : Barcode command is undefined'), barcode); } - return $.when.apply($, defs).then(function () { - self.update({}, {reload: false}); + return self.alive($.when.apply($, defs)).then(function () { + if (!prefixed) { + // redraw the view if we scanned a real barcode (required if + // we manually apply the change in JS, e.g. incrementing the + // quantity) + self.update({}, {reload: false}); + } }); }); }, @@ -321,8 +394,6 @@ FormRenderer.include({ commands['O-BTN.' + node.attrs.barcode_trigger] = function () { if (!$button.hasClass('o_invisible_modifier')) { $button.click(); - } else { - this.do_warn(_t('Action currently unavailable')); } return $.when(); }; @@ -361,6 +432,21 @@ FormRenderer.include({ } return $button; }, + /** + * Add barcode event handler + * + * @override + * @private + * @param {Object} node + * @returns {jQueryElement} + */ + _renderTagButton: function (node) { + var $button = this._super.apply(this, arguments); + if (node.attrs.barcode_trigger) { + this._barcodeButtonHandler($button, node); + } + return $button; + } }); BarcodeEvents.ReservedBarcodePrefixes.push('O-BTN'); diff --git a/addons/barcodes/static/tests/barcode_tests.js b/addons/barcodes/static/tests/barcode_tests.js new file mode 100644 index 00000000000..7487972ea62 --- /dev/null +++ b/addons/barcodes/static/tests/barcode_tests.js @@ -0,0 +1,406 @@ +odoo.define('barcodes.tests', function (require) { +"use strict"; + +var barcodeEvents = require('barcodes.BarcodeEvents'); + +var AbstractField = require('web.AbstractField'); +var fieldRegistry = require('web.field_registry'); +var FormController = require('web.FormController'); +var FormView = require('web.FormView'); +var testUtils = require('web.test_utils'); + +var createView = testUtils.createView; +var triggerKeypressEvent = testUtils.triggerKeypressEvent; + +QUnit.module('Barcodes', { + beforeEach: function () { + this.data = { + order: { + fields: { + _barcode_scanned: {string: 'Barcode scanned', type: 'char'}, + line_ids: {string: 'Order lines', type: 'one2many', relation: 'order_line'}, + }, + records: [ + {id: 1, line_ids: [1, 2]}, + ], + }, + order_line: { + fields: { + product_id: {string: 'Product', type: 'many2one', relation: 'product'}, + product_barcode: {string: 'Product Barcode', type: 'char'}, + quantity: {string: 'Quantity', type: 'integer'}, + }, + records: [ + {id: 1, product_id: 1, quantity: 0, product_barcode: '1234567890'}, + {id: 2, product_id: 2, quantity: 0, product_barcode: '0987654321'}, + ], + }, + product: { + fields: { + name: {string : "Product name", type: "char"}, + int_field: {string : "Integer", type: "integer"}, + barcode: {string: "Barcode", type: "char"}, + }, + records: [ + {id: 1, name: "iPad Mini", barcode: '1234567890'}, + {id: 2, name: "Mouse, Optical", barcode: '0987654321'}, + ], + }, + }; + } +}); + +QUnit.test('Button with barcode_trigger', function (assert) { + assert.expect(2); + + var form = createView({ + View: FormView, + model: 'product', + data: this.data, + arch: '<form>' + + '<header>' + + '<button name="do_something" string="Validate" type="object" barcode_trigger="doit"/>' + + '<button name="do_something_else" string="Validate" type="object" invisible="1" barcode_trigger="dothat"/>' + + '</header>' + + '</form>', + res_id: 2, + intercepts: { + execute_action: function (event) { + assert.strictEqual(event.data.action_data.name, 'do_something', + "do_something method call verified"); + }, + warning: function () { + assert.step('warn'); + }, + }, + }); + + // O-BTN.doit + _.each(['O','-','B','T','N','.','d','o','i','t','Enter'], triggerKeypressEvent); + // O-BTN.dothat (should not call execute_action as the button isn't visible) + _.each(['O','-','B','T','N','.','d','o','t','h','a','t','Enter'], triggerKeypressEvent); + + assert.verifySteps([], "no warning should be displayed"); + + form.destroy(); +}); + +QUnit.test('edit, save and cancel buttons', function (assert) { + assert.expect(6); + + var form = createView({ + View: FormView, + model: 'product', + data: this.data, + arch: '<form><field name="display_name"/></form>', + mockRPC: function (route, args) { + if (args.method === 'write') { + assert.step('save'); + } + return this._super.apply(this, arguments); + }, + res_id: 1, + }); + + // O-CMD.EDIT + _.each(["O","-","C","M","D",".","E","D","I","T","Enter"], triggerKeypressEvent); + assert.strictEqual(form.$(".o_form_editable").length, 1, + "should have switched to 'edit' mode"); + // dummy change to check that it actually saves + form.$('.o_field_widget').val('test').trigger('input'); + // O-CMD.SAVE + _.each(["O","-","C","M","D",".","S","A","V","E","Enter"], triggerKeypressEvent); + assert.strictEqual(form.$(".o_form_readonly").length, 1, + "should have switched to 'readonly' mode"); + assert.verifySteps(['save'], 'should have saved'); + + // O-CMD.EDIT + _.each(["O","-","C","M","D",".","E","D","I","T","Enter"], triggerKeypressEvent); + // dummy change to check that it correctly discards + form.$('.o_field_widget').val('test').trigger('input'); + // O-CMD.CANCEL + _.each(["O","-","C","M","D",".","C","A","N","C","E","L","Enter"], triggerKeypressEvent); + assert.strictEqual(form.$(".o_form_readonly").length, 1, + "should have switched to 'readonly' mode"); + assert.verifySteps(['save'], 'should not have saved'); + + form.destroy(); +}); + +QUnit.test('pager buttons', function (assert) { + assert.expect(5); + + var form = createView({ + View: FormView, + model: 'product', + data: this.data, + arch: '<form><field name="display_name"/></form>', + res_id: 1, + viewOptions: { + ids: [1, 2], + index: 0, + }, + }); + + assert.strictEqual(form.$('.o_field_widget').text(), 'iPad Mini'); + // O-CMD.PAGER-NEXT + _.each(["O","-","C","M","D",".","P","A","G","E","R","-","N","E","X","T","Enter"], triggerKeypressEvent); + assert.strictEqual(form.$('.o_field_widget').text(), 'Mouse, Optical'); + // O-CMD.PAGER-PREV + _.each(["O","-","C","M","D",".","P","A","G","E","R","-","P","R","E","V","Enter"], triggerKeypressEvent); + assert.strictEqual(form.$('.o_field_widget').text(), 'iPad Mini'); + // O-CMD.PAGER-LAST + _.each(["O","-","C","M","D",".","P","A","G","E","R","-","L","A","S","T","Enter"], triggerKeypressEvent); + assert.strictEqual(form.$('.o_field_widget').text(), 'Mouse, Optical'); + // O-CMD.PAGER-FIRST + _.each(["O","-","C","M","D",".","P","A","G","E","R","-","F","I","R","S","T","Enter"], triggerKeypressEvent); + assert.strictEqual(form.$('.o_field_widget').text(), 'iPad Mini'); + + form.destroy(); +}); + +QUnit.test('do no update form twice after a command barcode scanned', function (assert) { + assert.expect(7); + + var delay = barcodeEvents.BarcodeEvents.max_time_between_keys_in_ms; + barcodeEvents.BarcodeEvents.max_time_between_keys_in_ms = 0; + var formUpdate = FormController.prototype.update; + FormController.prototype.update = function () { + assert.step('update'); + return formUpdate.apply(this, arguments); + }; + + var form = createView({ + View: FormView, + model: 'product', + data: this.data, + arch: '<form>' + + '<field name="display_name"/>' + + '<field name="int_field" widget="field_float_scannable"/>' + + '</form>', + mockRPC: function (route, args) { + if (args.method === 'read') { + assert.step('read'); + } + return this._super.apply(this, arguments); + }, + res_id: 1, + viewOptions: { + ids: [1, 2], + index: 0, + }, + }); + + assert.verifySteps(['read'], "update should not have been called yet"); + + // switch to next record + _.each(["O","-","C","M","D",".","P","A","G","E","R","-","N","E","X","T","Enter"], triggerKeypressEvent); + // a first update is done to reload the data (thus followed by a read), but + // update shouldn't be called afterwards + assert.verifySteps(['read', 'update', 'read']); + + _.each(['5','4','3','9','8','2','6','7','1','2','5','2','Enter'], triggerKeypressEvent); + // a real barcode has been scanned -> an update should be requested (with + // option reload='false', so it isn't followed by a read) + assert.verifySteps(['read', 'update', 'read', 'update']); + + form.destroy(); + barcodeEvents.BarcodeEvents.max_time_between_keys_in_ms = delay; + FormController.prototype.update = formUpdate; +}); + +QUnit.test('widget field_float_scannable', function (assert) { + var done = assert.async(); + assert.expect(11); + + var delay = barcodeEvents.BarcodeEvents.max_time_between_keys_in_ms; + barcodeEvents.BarcodeEvents.max_time_between_keys_in_ms = 0; + + this.data.product.records[0].int_field = 4; + this.data.product.onchanges = { + int_field: function () {}, + }; + + var form = createView({ + View: FormView, + model: 'product', + data: this.data, + arch: '<form>' + + '<field name="display_name"/>' + + '<field name="int_field" widget="field_float_scannable"/>' + + '</form>', + mockRPC: function (route, args) { + if (args.method === 'onchange') { + assert.step('onchange'); + assert.strictEqual(args.args[1].int_field, 426, + "should send correct value for int_field"); + } + return this._super.apply(this, arguments); + }, + fieldDebounce: 1000, + res_id: 1, + }); + + assert.strictEqual(form.$('.o_field_widget[name=int_field]').text(), '4', + "should display the correct value in readonly"); + + form.$buttons.find('.o_form_button_edit').click(); + + assert.strictEqual(form.$('.o_field_widget[name=int_field]').val(), '4', + "should display the correct value in edit"); + + // simulates keypress events in the input to replace 0.00 by 26 (should not trigger onchanges) + form.$('.o_field_widget[name=int_field]').focus(); + assert.strictEqual(form.$('.o_field_widget[name=int_field]').get(0), document.activeElement, + "int field should be focused"); + form.$('.o_field_widget[name=int_field]').trigger({type: 'keypress', which: 50, keyCode: 50}); // 2 + assert.strictEqual(form.$('.o_field_widget[name=int_field]').get(0), document.activeElement, + "int field should still be focused"); + form.$('.o_field_widget[name=int_field]').trigger({type: 'keypress', which: 54, keyCode: 54}); // 6 + assert.strictEqual(form.$('.o_field_widget[name=int_field]').get(0), document.activeElement, + "int field should still be focused"); + + setTimeout(function () { + assert.strictEqual(form.$('.o_field_widget[name=int_field]').val(), '426', + "should display the correct value in edit"); + assert.strictEqual(form.$('.o_field_widget[name=int_field]').get(0), document.activeElement, + "int field should still be focused"); + + assert.verifySteps([], 'should not have done any onchange RPC'); + + form.$('.o_field_widget[name=int_field]').trigger('change'); // should trigger the onchange + + assert.verifySteps(['onchange'], 'should have done the onchange RPC'); + + form.destroy(); + barcodeEvents.BarcodeEvents.max_time_between_keys_in_ms = delay; + done(); + }); +}); + +QUnit.test('widget barcode_handler', function (assert) { + assert.expect(4); + + var delay = barcodeEvents.BarcodeEvents.max_time_between_keys_in_ms; + barcodeEvents.BarcodeEvents.max_time_between_keys_in_ms = 0; + + this.data.product.fields.barcode_scanned = {string : "Scanned barcode", type: "char"}; + this.data.product.onchanges = { + barcode_scanned: function (obj) { + // simulate an onchange that increment the int_field value + // at each barcode scanned + obj.int_field = obj.int_field + 1; + }, + }; + + var form = createView({ + View: FormView, + model: 'product', + data: this.data, + arch: '<form>' + + '<field name="display_name"/>' + + '<field name="int_field"/>' + + '<field name="barcode_scanned" widget="barcode_handler" invisible="1"/>' + + '</form>', + mockRPC: function (route, args) { + if (args.method === 'onchange') { + assert.step('onchange'); + } + return this._super.apply(this, arguments); + }, + res_id: 1, + viewOptions: { + mode: 'edit', + }, + }); + + assert.strictEqual(form.$('.o_field_widget[name=int_field]').val(), '0', + "initial value should be correct"); + + _.each(['5','4','3','9','8','2','6','7','1','2','5','2','Enter'], triggerKeypressEvent); + assert.strictEqual(form.$('.o_field_widget[name=int_field]').val(), '1', + "value should have been incremented"); + + assert.verifySteps(['onchange'], "an onchange should have been done"); + + form.destroy(); + barcodeEvents.BarcodeEvents.max_time_between_keys_in_ms = delay; +}); + +QUnit.test('specification of widget barcode_handler', function (assert) { + assert.expect(5); + + var delay = barcodeEvents.BarcodeEvents.max_time_between_keys_in_ms; + barcodeEvents.BarcodeEvents.max_time_between_keys_in_ms = 0; + + // 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', + quantity: 'quantity', + commands: { + barcode: '_barcodeAddX2MQuantity', + } + }); + }, + }); + fieldRegistry.add('test_barcode_handler', TestBarcodeHandler); + + var form = 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) { + if (args.method === 'onchange') { + assert.notOK(true, "should not do any onchange RPC"); + } + if (args.method === 'write') { + assert.deepEqual(args.args[1].line_ids, [ + [1, 1, {quantity: 2}], [1, 2, {quantity: 1}], + ], "should have generated the correct commands"); + } + return this._super.apply(this, arguments); + }, + res_id: 1, + viewOptions: { + mode: 'edit', + }, + }); + + assert.strictEqual(form.$('.o_data_row').length, 2, + "one2many should contain 2 rows"); + + // scan twice product 1 + _.each(['1','2','3','4','5','6','7','8','9','0','Enter'], triggerKeypressEvent); + assert.strictEqual(form.$('.o_data_row:first .o_data_cell:nth(1)').text(), '1', + "quantity of line one should have been incremented"); + _.each(['1','2','3','4','5','6','7','8','9','0','Enter'], triggerKeypressEvent); + assert.strictEqual(form.$('.o_data_row:first .o_data_cell:nth(1)').text(), '2', + "quantity of line one should have been incremented"); + + // scan once product 2 + _.each(['0','9','8','7','6','5','4','3','2','1','Enter'], triggerKeypressEvent); + assert.strictEqual(form.$('.o_data_row:nth(1) .o_data_cell:nth(1)').text(), '1', + "quantity of line one should have been incremented"); + + form.$buttons.find('.o_form_button_save').click(); + + form.destroy(); + barcodeEvents.BarcodeEvents.max_time_between_keys_in_ms = delay; + delete fieldRegistry.map.test_barcode_handler; +}); +}); diff --git a/addons/barcodes/views/barcodes_templates.xml b/addons/barcodes/views/barcodes_templates.xml index 420a069a491..cb16a40c178 100644 --- a/addons/barcodes/views/barcodes_templates.xml +++ b/addons/barcodes/views/barcodes_templates.xml @@ -10,4 +10,10 @@ </xpath> </template> + <template id="qunit_suite" name="barcode_tests" inherit_id="web.qunit_suite"> + <xpath expr="//t[@t-set='head']" position="inside"> + <script type="text/javascript" src="/barcodes/static/tests/barcode_tests.js"/> + </xpath> + </template> + </odoo> |
