From d3ad21cdfc2a3c8c17282dcc023f2c3153bb3d6c Mon Sep 17 00:00:00 2001 From: Romeo Fragomeli Date: Mon, 21 Nov 2022 11:50:03 +0000 Subject: [PATCH] [FIX] web: Many2One field don't show all records in small screen MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since the conversion in OWL of the `many2one_barcode` widget, on Mobile when we open the search more a filter value is added automatically in the filter and so when we want to change the value we need an additional step to remove the filter to see all records. This commit, use a 'custom event' to open the barcode search and restore the normal behaviour on the `click` event. Steps to reproduce: * Go to Timesheet * Add a new line * Select a project * Try to change the project => BUG show only the selected project closes odoo/odoo#106267 X-original-commit: 6d7f5a0abd79f6185831a2b9617b031d13da89be Signed-off-by: Adrien Dieudonné (adr) Signed-off-by: Romeo Fragomeli (rfr) Co-authored-by: Romain Estievenart --- .../views/fields/many2one/many2one_field.js | 2 +- .../src/views/fields/relational_utils.js | 11 ++++-- .../src/views/fields/relational_utils.xml | 3 +- .../fields/many2one_barcode_field_tests.js | 36 +++++++++++++++++++ 4 files changed, 48 insertions(+), 4 deletions(-) diff --git a/addons/web/static/src/views/fields/many2one/many2one_field.js b/addons/web/static/src/views/fields/many2one/many2one_field.js index 5350ca0d07e..7141a89807b 100644 --- a/addons/web/static/src/views/fields/many2one/many2one_field.js +++ b/addons/web/static/src/views/fields/many2one/many2one_field.js @@ -232,7 +232,7 @@ export class Many2OneField extends Component { searchInput.value = barcode; searchInput.dispatchEvent(new Event("input")); if (this.env.isSmall) { - searchInput.click(); + searchInput.dispatchEvent(new Event("barcode-search")); } } } diff --git a/addons/web/static/src/views/fields/relational_utils.js b/addons/web/static/src/views/fields/relational_utils.js index fc89730b97e..49fcf2569a6 100644 --- a/addons/web/static/src/views/fields/relational_utils.js +++ b/addons/web/static/src/views/fields/relational_utils.js @@ -33,7 +33,14 @@ import { SelectCreateDialog } from "@web/views/view_dialogs/select_create_dialog * @property {Function | null} onDelete */ -import { Component, useComponent, useEffect, useEnv, useSubEnv, onWillUpdateProps } from "@odoo/owl"; +import { + Component, + useComponent, + useEffect, + useEnv, + useSubEnv, + onWillUpdateProps, +} from "@odoo/owl"; // // Commons @@ -285,7 +292,7 @@ export class Many2XAutocomplete extends Component { return options; } - async onSearchMoreSmall() { + async onBarcodeSearch() { const autoCompleteInput = this.autoCompleteContainer.el.querySelector("input"); return this.onSearchMore(autoCompleteInput.value); } diff --git a/addons/web/static/src/views/fields/relational_utils.xml b/addons/web/static/src/views/fields/relational_utils.xml index 5c8a7b3ec7f..a4e1b130691 100644 --- a/addons/web/static/src/views/fields/relational_utils.xml +++ b/addons/web/static/src/views/fields/relational_utils.xml @@ -43,7 +43,8 @@ readonly="" t-att-placeholder="props.placeholder" t-att-value="props.value" - t-on-click="onSearchMoreSmall" + t-on-click="onSearchMore" + t-on-barcode-search="onBarcodeSearch" /> { await click(modal, ".o_kanban_record:nth-child(1)"); await clickSave(target); }); + + QUnit.test("many2one with barcode show all records", async function (assert) { + // The product selected (mock) for the barcode scanner + const selectedRecordTest = serverData.models[PRODUCT_PRODUCT].records[0]; + + patchWithCleanup(BarcodeScanner, { + scanBarcode: async () => selectedRecordTest.barcode, + }); + + await makeView({ + type: "form", + resModel: SALE_ORDER_LINE, + serverData, + arch: ` +
+ + `, + mockRPC: barcodeMockRPC, + }); + + // Select one product + await click(target, ".o_barcode"); + + // Click on the input to show all records + await click(target, ".o_input_dropdown > input"); + + const modal = target.querySelector(".modal-dialog.modal-lg"); + assert.containsOnce(target, modal, "there should be one modal opened in full screen"); + + assert.containsN( + modal, + ".o_kanban_record .oe_kanban_global_click", + 3, + "there should be 3 records displayed" + ); + }); });