From 2ddc7348f2c3660b1659614e7e620a3a4cdb4d43 Mon Sep 17 00:00:00 2001 From: Bruno Boi Date: Tue, 9 May 2023 13:23:28 +0000 Subject: [PATCH] [FIX] web: optional viewMode in x2m field Before this commit, when having a x2many field invisible in a view, and displaying it anyway in studio, there was a crash because some variable was undefined. This originated from commit f22961a, which did not account for the fact that viewMode is an optional props. After this commit, the util function used by the x2m field and where the crash occur has been refactored. Moreover, the x2m field template has also been slightly refactored. closes odoo/odoo#120918 Taskid: 3305808 Related: odoo/enterprise#40852 Signed-off-by: Lucas Perais (lpe) --- .../src/views/fields/x2many/x2many_field.js | 5 ++- .../src/views/fields/x2many/x2many_field.xml | 4 +-- addons/web/static/src/views/utils.js | 34 ++++++++++++++----- 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/addons/web/static/src/views/fields/x2many/x2many_field.js b/addons/web/static/src/views/fields/x2many/x2many_field.js index 74025398626..6d34eed63ee 100644 --- a/addons/web/static/src/views/fields/x2many/x2many_field.js +++ b/addons/web/static/src/views/fields/x2many/x2many_field.js @@ -44,7 +44,10 @@ export class X2ManyField extends Component { ); this.archInfo = this.props.views?.[this.props.viewMode] || {}; - this.className = computeViewClassName(this.props.viewMode, this.archInfo.xmlDoc); + const classes = this.props.viewMode + ? ["o_field_x2many", `o_field_x2many_${this.props.viewMode}`] + : ["o_field_x2many"]; + this.className = computeViewClassName(this.props.viewMode, this.archInfo.xmlDoc, classes); const { activeActions, creates } = this.archInfo; if (this.props.viewMode === "kanban") { diff --git a/addons/web/static/src/views/fields/x2many/x2many_field.xml b/addons/web/static/src/views/fields/x2many/x2many_field.xml index 2702bd856ee..2d0f243ce40 100644 --- a/addons/web/static/src/views/fields/x2many/x2many_field.xml +++ b/addons/web/static/src/views/fields/x2many/x2many_field.xml @@ -2,7 +2,7 @@ -
+