From 605a66d554cc7b01cdaf148e5bf30421c8bdd6a1 Mon Sep 17 00:00:00 2001 From: "Touati Djamel (otd)" Date: Mon, 18 Jul 2022 14:11:01 +0000 Subject: [PATCH] [FIX] barcode: allow multiple buttons with the same string and action MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Steps to reproduce the bug: - Enable work order option in manufacturing settings - Create a manufacturing order and use the product Table - Open the tablet view - with the JS instruction, try to simulate the scan of the command `CONTINUE CONSUMPTION` with this value: `O-BTN.continue` Problem: The action continue is not executed because when the tablet view is loaded, the function _barcodeButtonHandler is triggered in which we try to call the `activeBarcode` function for all the buttons: https://github.com/odoo/odoo/blob/c6716847aa5d694650bfe046657f052a03f9ca39/addons/barcodes/static/src/js/barcode_form_view.js#L437-L445 To add each button in a dictionary, we use as key the name + the string of the button, but as multiple buttons can have the same name and the same action, only the last button is saved: https://github.com/odoo/enterprise/blob/2c9d2c5738d378f6f5cdc2ceec00b89cb5fa9536/mrp_workorder/views/mrp_workorder_views.xml#L137-L150 https://github.com/odoo/odoo/blob/c6716847aa5d694650bfe046657f052a03f9ca39/addons/barcodes/static/src/js/barcode_form_view.js#L252-L255 Solution: To allow having multiple buttons with a similar name and action, we must add in the key the attrs hash of the button opw-2899297 closes odoo/odoo#96778 X-original-commit: 6ff5e0a7c499f95017c09fafd9605bd51be9bfd0 Signed-off-by: Géry Debongnie Signed-off-by: Djamel Touati (otd) --- addons/barcodes/static/tests/barcode_tests.js | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/addons/barcodes/static/tests/barcode_tests.js b/addons/barcodes/static/tests/barcode_tests.js index 6397a278628..3c1d5e42562 100644 --- a/addons/barcodes/static/tests/barcode_tests.js +++ b/addons/barcodes/static/tests/barcode_tests.js @@ -124,6 +124,44 @@ QUnit.test('Button with barcode_trigger', async function (assert) { form.destroy(); }); +QUnit.test('Two buttons with same barcode_trigger and the same string and action', async function (assert) { + assert.expect(2); + + var form = await createView({ + View: FormView, + model: 'product', + data: this.data, + arch: '
' + + '
' + + '
' + + '
', + res_id: 2, + + services: { + notification: { + notify: function (params) { + assert.step(params.type); + } + }, + }, + intercepts: { + execute_action: function (event) { + assert.strictEqual(event.data.action_data.name, 'do_something', + "do_something method call verified"); + }, + }, + }); + + // O-BTN.doit should call execute_action as the first button is visible + simulateBarCode(['O','-','B','T','N','.','d','o','i','t','Enter']); + await testUtils.nextTick(); + assert.verifySteps([], "no warning should be displayed"); + + form.destroy(); +}); + QUnit.test('edit, save and cancel buttons', async function (assert) { assert.expect(6);