From 5b9316be7db8f36770d2f8a732c39d61305ce162 Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Wed, 29 May 2024 16:34:07 +0200 Subject: [PATCH] [IMP] spreadsheet_dashboard_oca: Dashboard editability All the spreadsheet dashboards coming from Odoo in the modules spreadsheet_dashboard* are noupdate="0", which means that if you modify anything via this module, and then you update the module, all the changes will be lost. To avoid frustrations and to allow seamless updates, the following mechanisms have been put in place: - Spreadsheet dashboards now have an active field. - Only the manually created dashboards or those coming from data with noupdate="1" will be editable. - There's a mechanism for copying existing dashboards. So, for modifying one of the standard dashboards, the steps will be: - Duplicate it through the "Copy" button. - Disable the standard one. - Edit the copy. TT49379 --- spreadsheet_dashboard_oca/__manifest__.py | 1 + .../models/spreadsheet_dashboard.py | 12 +++++++++++ .../static/description/index.html | 1 - .../views/spreadsheet_dashboard.xml | 21 +++++++++++++++++++ .../spreadsheet_dashboard_group_views.xml | 11 ++++++++++ 5 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 spreadsheet_dashboard_oca/views/spreadsheet_dashboard_group_views.xml diff --git a/spreadsheet_dashboard_oca/__manifest__.py b/spreadsheet_dashboard_oca/__manifest__.py index 18f3e49e..3440425f 100644 --- a/spreadsheet_dashboard_oca/__manifest__.py +++ b/spreadsheet_dashboard_oca/__manifest__.py @@ -15,6 +15,7 @@ ], "data": [ "wizards/spreadsheet_spreadsheet_import.xml", + "views/spreadsheet_dashboard_group_views.xml", "views/spreadsheet_dashboard.xml", "data/spreadsheet_spreadsheet_import_mode.xml", ], diff --git a/spreadsheet_dashboard_oca/models/spreadsheet_dashboard.py b/spreadsheet_dashboard_oca/models/spreadsheet_dashboard.py index dc0c66ff..8752405a 100644 --- a/spreadsheet_dashboard_oca/models/spreadsheet_dashboard.py +++ b/spreadsheet_dashboard_oca/models/spreadsheet_dashboard.py @@ -11,9 +11,11 @@ class SpreadsheetDashboard(models.Model): _name = "spreadsheet.dashboard" _inherit = ["spreadsheet.dashboard", "spreadsheet.abstract"] + active = fields.Boolean(default=True) spreadsheet_raw = fields.Serialized( inverse="_inverse_spreadsheet_raw", compute="_compute_spreadsheet_raw" ) + can_edit = fields.Boolean(compute="_compute_can_edit") @api.depends("data") def _compute_spreadsheet_raw(self): @@ -30,3 +32,13 @@ def _inverse_spreadsheet_raw(self): record.data = base64.encodebytes( json.dumps(record.spreadsheet_raw).encode("UTF-8") ) + + def _compute_can_edit(self): + """We can edit if the record doesn't have XML-ID, or the XML-ID is noupdate=1""" + self.can_edit = True + for record in self.filtered("id"): + imd = self.env["ir.model.data"].search( + [("model", "=", record._name), ("res_id", "=", record.id)] + ) + if imd and imd.module != "__export__": + record.can_edit = imd.noupdate diff --git a/spreadsheet_dashboard_oca/static/description/index.html b/spreadsheet_dashboard_oca/static/description/index.html index 6c134723..9da7bca4 100644 --- a/spreadsheet_dashboard_oca/static/description/index.html +++ b/spreadsheet_dashboard_oca/static/description/index.html @@ -1,4 +1,3 @@ - diff --git a/spreadsheet_dashboard_oca/views/spreadsheet_dashboard.xml b/spreadsheet_dashboard_oca/views/spreadsheet_dashboard.xml index 683c931c..d952792c 100644 --- a/spreadsheet_dashboard_oca/views/spreadsheet_dashboard.xml +++ b/spreadsheet_dashboard_oca/views/spreadsheet_dashboard.xml @@ -15,21 +15,42 @@ 1 + not active + +