From 7b368df0fe1d038737ff02ef7879bcd12e906d8c Mon Sep 17 00:00:00 2001 From: "Hubert Van de Walle (huvw)" Date: Tue, 21 Mar 2023 15:29:30 +0000 Subject: [PATCH] [FIX] web: binary field filename in form view not updated with pager Steps to reproduce ================== - Go to a form view with a binary field, or add one with studio - Upload a file a.txt to a record - Upload a file b.txt to another record - Switch between both records with the pager - The filename is not updated opw-3208810 closes odoo/odoo#116323 X-original-commit: 90515916e8adb3edb560d73ec8889ad52319cc1d Signed-off-by: Luca Vitali Signed-off-by: Hubert Van De Walle --- .../src/views/fields/binary/binary_field.js | 4 +- .../tests/views/fields/binary_field_tests.js | 42 +++++++++++++++++++ 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/addons/web/static/src/views/fields/binary/binary_field.js b/addons/web/static/src/views/fields/binary/binary_field.js index 35a5b5f9334..51c61425367 100644 --- a/addons/web/static/src/views/fields/binary/binary_field.js +++ b/addons/web/static/src/views/fields/binary/binary_field.js @@ -29,9 +29,7 @@ export class BinaryField extends Component { fileName: this.props.record.data[this.props.fileNameField] || "", }); onWillUpdateProps((nextProps) => { - if (nextProps.readonly) { - this.state.fileName = nextProps.record.data[nextProps.fileNameField] || ""; - } + this.state.fileName = nextProps.record.data[nextProps.fileNameField] || ""; }); } diff --git a/addons/web/static/tests/views/fields/binary_field_tests.js b/addons/web/static/tests/views/fields/binary_field_tests.js index 1646f41f9ff..526ebea3307 100644 --- a/addons/web/static/tests/views/fields/binary_field_tests.js +++ b/addons/web/static/tests/views/fields/binary_field_tests.js @@ -430,4 +430,46 @@ QUnit.module("Fields", (hooks) => { }); assert.containsNone(target, "button.fa-download"); }); + + QUnit.test("BinaryField filename is updated when using the pager", async function (assert) { + serverData.models.partner.records.push( + { + id: 1, + document: "abc", + foo: "abc.txt", + }, + { + id: 2, + document: "def", + foo: "def.txt", + } + ); + await makeView({ + serverData, + type: "form", + resModel: "partner", + arch: ` +
+ + + + `, + resIds: [1, 2], + resId: 1, + }); + + assert.strictEqual( + target.querySelector(".o_field_binary input[type=text]").value, + "abc.txt", + 'displayed value should be "abc.txt"' + ); + + await click(target.querySelector(".o_pager_next")); + + assert.strictEqual( + target.querySelector(".o_field_binary input[type=text]").value, + "def.txt", + 'displayed value should be changed to "def.txt"' + ); + }); });