From 4ccb1d134e950f5f06abf116a79648936792e832 Mon Sep 17 00:00:00 2001 From: Jinjiu Liu Date: Tue, 31 Jan 2023 10:30:04 +0000 Subject: [PATCH] [FIX] web, sale_management: translation button of text field disappears MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reproduction: 1. On Odoo 16, install Sales 2. Go to Sales -> Configuration -> Quotation template 3. Click the example “4 person desk” 4. In the “Lines” and “Optional Products” tabs, the translation button is not show in the Description field 5. In Odoo 15, it shows the translation button Reason: 1. In text_field.xml, the translationButton is not in the same div element. This causes the translation button is hidden when in the tree view. This is the case of the Optional Products tab 2. For the case of Lines, another reason causing this issue is the use of widget “section_and_note_text” Fix: move the translation button to the same div element with the textarea in text_field.xml; remove the widget “section_and_note_text” from the Lines tab. Also added a test for the text field translation button The adding of div: https://github.com/odoo-dev/odoo/commit/98e94d45fd6176d7afdcf682c10ce8894f86915a Rewrite of Text Field js: https://github.com/odoo-dev/odoo/commit/32bc28aa665c479e31a40afffca2f03f6f2cc805 Rewrite of section_and_note: https://github.com/odoo-dev/odoo/commit/5a21823f4364d6db407d48178435de041b157b44 An community PR for the translationButton by niyasraphy (same change): https://github.com/odoo/odoo/pull/111291 opw-3078122 closes odoo/odoo#111763 X-original-commit: 99a23902bd2002099322b5c36fac94c8bd500951 Signed-off-by: Bruno Boi (boi) Co-authored-by: niyasraphy --- .../views/sale_order_template_views.xml | 2 +- .../src/views/fields/text/text_field.xml | 14 ++--- .../tests/views/fields/text_field_tests.js | 54 +++++++++++++++++++ 3 files changed, 62 insertions(+), 8 deletions(-) diff --git a/addons/sale_management/views/sale_order_template_views.xml b/addons/sale_management/views/sale_order_template_views.xml index 2c8fdb65966..30bed879670 100644 --- a/addons/sale_management/views/sale_order_template_views.xml +++ b/addons/sale_management/views/sale_order_template_views.xml @@ -91,7 +91,7 @@ - + + + + - - - diff --git a/addons/web/static/tests/views/fields/text_field_tests.js b/addons/web/static/tests/views/fields/text_field_tests.js index 76459e2772e..f261bdf1c0e 100644 --- a/addons/web/static/tests/views/fields/text_field_tests.js +++ b/addons/web/static/tests/views/fields/text_field_tests.js @@ -436,6 +436,60 @@ QUnit.module("Fields", (hooks) => { ); }); + QUnit.test("text field translatable on notebook page", async function (assert) { + serverData.models.partner.fields.txt.translate = true; + serviceRegistry.add("localization", makeFakeLocalizationService({ multiLang: true }), { + force: true, + }); + + await makeView({ + type: "form", + resModel: "partner", + serverData, + arch: ` +
+ + + + + + + +
`, + resId: 1, + mockRPC(route, { args, method }) { + if (route === "/web/dataset/call_kw/res.lang/get_installed") { + return Promise.resolve([ + ["en_US", "English"], + ["fr_BE", "French (Belgium)"], + ]); + } + if (route === "/web/dataset/call_kw/partner/get_field_translations") { + return Promise.resolve([ + [ + { lang: "en_US", source: "yop", value: "yop" }, + { lang: "fr_BE", source: "yop", value: "valeur français" }, + ], + { translation_type: "text", translation_show_source: false }, + ]); + } + }, + }); + + assert.hasClass(target.querySelectorAll(".o_notebook .nav .nav-link")[0], "active"); + + assert.hasClass(target.querySelector("[name=txt] textarea"), "o_field_translate"); + + assert.strictEqual( + target.querySelector("[name=txt] textarea").nextElementSibling.textContent, + "EN", + "The input should be preceded by a translate button" + ); + await click(target, ".o_field_text .btn.o_field_translate"); + + assert.containsOnce(target, ".modal", "there should be a translation modal"); + }); + QUnit.test( "go to next line (and not the next row) when pressing enter", async function (assert) {