[FIX] web, sale_management: translation button of text field disappears

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) <boi@odoo.com>
Co-authored-by: niyasraphy <niyasraphyk@gmail.com>
This commit is contained in:
Jinjiu Liu
2023-02-03 07:07:11 +01:00
co-authored by niyasraphy
parent b94335f92f
commit 4ccb1d134e
3 changed files with 62 additions and 8 deletions
@@ -91,7 +91,7 @@
<field name="company_id" invisible="1"/>
<field name="sequence" widget="handle"/>
<field name="product_id"/>
<field name="name" widget="section_and_note_text"/>
<field name="name"/>
<field name="product_uom_qty"/>
<field name="product_uom_category_id" invisible="1"/>
<field
@@ -16,14 +16,14 @@
t-on-input="onInput"
t-ref="textarea"
/>
<t t-if="props.isTranslatable">
<TranslationButton
fieldName="props.name"
record="props.record"
updateField="props.update"
/>
</t>
</div>
<t t-if="props.isTranslatable">
<TranslationButton
fieldName="props.name"
record="props.record"
updateField="props.update"
/>
</t>
</t>
</t>
@@ -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: `
<form>
<sheet>
<notebook>
<page string="First Page">
<field name="txt"/>
</page>
</notebook>
</sheet>
</form>`,
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) {