Skip to content

Commit

Permalink
[IMP] spreadsheet_dashboard_oca: Dashboard editability
Browse files Browse the repository at this point in the history
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
  • Loading branch information
pedrobaeza committed May 29, 2024
1 parent 292967c commit 5b9316b
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 1 deletion.
1 change: 1 addition & 0 deletions spreadsheet_dashboard_oca/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
Expand Down
12 changes: 12 additions & 0 deletions spreadsheet_dashboard_oca/models/spreadsheet_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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

Check warning on line 38 in spreadsheet_dashboard_oca/models/spreadsheet_dashboard.py

View check run for this annotation

Codecov / codecov/patch

spreadsheet_dashboard_oca/models/spreadsheet_dashboard.py#L38

Added line #L38 was not covered by tests
for record in self.filtered("id"):
imd = self.env["ir.model.data"].search(

Check warning on line 40 in spreadsheet_dashboard_oca/models/spreadsheet_dashboard.py

View check run for this annotation

Codecov / codecov/patch

spreadsheet_dashboard_oca/models/spreadsheet_dashboard.py#L40

Added line #L40 was not covered by tests
[("model", "=", record._name), ("res_id", "=", record.id)]
)
if imd and imd.module != "__export__":
record.can_edit = imd.noupdate

Check warning on line 44 in spreadsheet_dashboard_oca/models/spreadsheet_dashboard.py

View check run for this annotation

Codecov / codecov/patch

spreadsheet_dashboard_oca/models/spreadsheet_dashboard.py#L44

Added line #L44 was not covered by tests
1 change: 0 additions & 1 deletion spreadsheet_dashboard_oca/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
Expand Down
21 changes: 21 additions & 0 deletions spreadsheet_dashboard_oca/views/spreadsheet_dashboard.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,42 @@
<field name="arch" type="xml">
<tree position="attributes">
<attribute name="create">1</attribute>
<attribute name="decoration-muted">not active</attribute>
</tree>
<tree position="inside">
<field name="can_edit" invisible="1" />
<field
name="data"
groups="base.group_no_one"
widget="binary"
filename="name"
/>
<!-- Put the button 2 times for having the edit button explicitly disabled for discoverability -->
<button
name="open_spreadsheet"
type="object"
string="Edit"
icon="fa-pencil"
disabled="1"
groups="base.group_system"
attrs="{'invisible': [('can_edit', '=', True)]}"
/>
<button
name="open_spreadsheet"
type="object"
string="Edit"
icon="fa-pencil"
groups="base.group_system"
attrs="{'invisible': [('can_edit', '=', False)]}"
/>
<button
name="copy"
type="object"
string="Copy"
icon="fa-copy"
groups="base.group_system"
/>
<field name="active" widget="boolean_toggle" />
</tree>
</field>
</record>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2024 Tecnativa - Pedro M. Baeza
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo>
<record
model="ir.actions.act_window"
id="spreadsheet_dashboard.spreadsheet_dashboard_action_configuration_dashboards"
>
<field name="context">{'active_test': False}</field>
</record>
</odoo>

0 comments on commit 5b9316b

Please sign in to comment.