From 7c3a3c6b70568e51fe9f0499dccda1b36bd714fe Mon Sep 17 00:00:00 2001 From: FrancoisGe Date: Fri, 26 May 2023 11:46:57 +0000 Subject: [PATCH] [FIX] web: multi sources definitions in kanban MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this commit, in a kanban view with a properties field, if the records have multiple sources for their properties then the view crashes. Why? The kanban record tries to make properties accessible from record in the kanban card. This is not useful, we don't want to be able to do "record.properties.hd32ndls". Solution: Properties must not be accessible from records in the kanban card. How do we reproduce? - Go to a kanban view with a properties field - Have a record with property A of type integer and another record which has no property Before the commit: The view crashes because we're trying to format the value of the second record for property A, which it doesn't know. After the commit: The view is displayed correctly. closes odoo/odoo#122833 X-original-commit: 735f34f29150ab1782f68d77c993dbe3227f998b Signed-off-by: Aaron Bohy (aab) Signed-off-by: Georis François (fge) --- .../static/src/views/kanban/kanban_record.js | 2 +- .../views/fields/properties_field_tests.js | 63 ++++++++++++++++++- 2 files changed, 63 insertions(+), 2 deletions(-) diff --git a/addons/web/static/src/views/kanban/kanban_record.js b/addons/web/static/src/views/kanban/kanban_record.js index 533f26175f2..dc87c9e1643 100644 --- a/addons/web/static/src/views/kanban/kanban_record.js +++ b/addons/web/static/src/views/kanban/kanban_record.js @@ -105,7 +105,7 @@ function getValue(record, fieldName) { export function getFormattedRecord(record) { const formattedRecord = {}; - for (const fieldName in record.activeFields) { + for (const fieldName of record.fieldNames) { formattedRecord[fieldName] = { value: getValue(record, fieldName), raw_value: getRawValue(record, fieldName), diff --git a/addons/web/static/tests/views/fields/properties_field_tests.js b/addons/web/static/tests/views/fields/properties_field_tests.js index c303d23c28c..3fe0dcffd9a 100644 --- a/addons/web/static/tests/views/fields/properties_field_tests.js +++ b/addons/web/static/tests/views/fields/properties_field_tests.js @@ -1357,6 +1357,66 @@ QUnit.module("Fields", (hooks) => { assert.equal(items.length, 2); }); + QUnit.test( + "properties: kanban view with multiple sources of properties definitions", + async function (assert) { + const definition = { + name: "property_integer", + string: "My Integer", + type: "integer", + view_in_kanban: true, + }; + serverData.models.company.records.push({ + id: 38, + display_name: "Company 2", + definitions: [definition], + }); + serverData.models.partner.records.push({ + id: 10, + display_name: "other partner", + properties: [ + { + ...definition, + value: 1, + }, + ], + company_id: 38, + }); + + await makeView({ + type: "kanban", + resModel: "partner", + serverData, + arch: ` + + + +
+
+
+ +
+
+
+
`, + }); + + assert.containsN(target, ".o_kanban_record:not(.o_kanban_ghost)", 5); + assert.deepEqual( + [...target.querySelectorAll(".o_kanban_record:not(.o_kanban_ghost)")].map( + (el) => el.textContent + ), + [ + "Company 1 first partner char valueB", + "Company 1 second partner char valueCchar value 4", + "Company 1 third partner ", + "Company 1 fourth partner ", + "Company 2 other partner 1", + ] + ); + } + ); + /** * Check that the properties are shown when switching view. */ @@ -1390,7 +1450,8 @@ QUnit.module("Fields", (hooks) => { }); await click(target, ".o_switch_view.o_list"); - assert.ok(target.querySelector(".o_optional_columns_dropdown"), + assert.ok( + target.querySelector(".o_optional_columns_dropdown"), "Properties should be added as optional columns." ); });