From bc51651a0012644a1a9149fa6be1fb40c3a63686 Mon Sep 17 00:00:00 2001
From: "Hubert Van de Walle (huvw)" <huvw@odoo.com>
Date: Thu, 17 Aug 2023 16:58:10 +0000
Subject: [PATCH] [FIX] board: empty dashboard fails to render on mobile

Steps to reproduce
==================

- Go on a 14.0 runbot
- Open dashboard

```
TypeError: Cannot read properties of undefined (reading 'split')
    at Class.changeLayout
```

Cause of the issue
==================

`.oe_dashboard` isn't rendered on an empty dashboard

opw-3469183

closes odoo/odoo#132254

Signed-off-by: Romain Estievenart (res) <res@odoo.com>
---
 addons/board/static/src/js/board_view.js      |  3 ++
 .../board/static/tests/mobile/board_tests.js  | 31 +++++++++++++++++++
 2 files changed, 34 insertions(+)

diff --git a/addons/board/static/src/js/board_view.js b/addons/board/static/src/js/board_view.js
index 0aa5f3d63a80..daa84329ac55 100644
--- a/addons/board/static/src/js/board_view.js
+++ b/addons/board/static/src/js/board_view.js
@@ -174,6 +174,9 @@ var BoardRenderer = FormRenderer.extend({
      */
     changeLayout: function (layout) {
         var $dashboard = this.$('.oe_dashboard');
+        if (!$dashboard.length) {
+            return;
+        }
         var current_layout = $dashboard.attr('data-layout');
         if (current_layout !== layout) {
             var clayout = current_layout.split('-').length,
diff --git a/addons/board/static/tests/mobile/board_tests.js b/addons/board/static/tests/mobile/board_tests.js
index 9b32e2e9dcb0..964471037d54 100644
--- a/addons/board/static/tests/mobile/board_tests.js
+++ b/addons/board/static/tests/mobile/board_tests.js
@@ -113,4 +113,35 @@ odoo.define("board.dashboard_tests", function (require) {
 
         target.destroy();
     });
+
+    QUnit.test("empty board view", async function (assert) {
+        assert.expect(2);
+        const target = await createView({
+            View: BoardView,
+            debug: 1,
+            model: "board",
+            data: this.data,
+            arch: `<form string="My Dashboard">
+                <board style="2-1">
+                    <column/>
+                </board>
+            </form>`,
+            archs: {
+                "partner,4,list": '<tree string="Partner"><field name="foo"/></tree>',
+            },
+        });
+
+        assert.hasClass(
+            target.renderer.$el,
+            "o_dashboard",
+            "with a dashboard, the renderer should have the proper css class"
+        );
+        assert.containsOnce(
+            target,
+            ".o_dashboard .o_view_nocontent",
+            "should have a no content helper"
+        );
+
+        target.destroy();
+    });
 });
-- 
GitLab