Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][IMP] spreadsheet_dashboard_oca: Dashboard editability #31

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
_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 @@
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"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we export a record (compatible for import) an xml id is generated.
With the current algorithm, if we export a record, it will become not editable. Don't you think ?

Quite theoritical use case though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really, as the XML-ID entry __export__.<whatever> will be noupdate=1.

Copy link
Contributor

@legalsylvain legalsylvain May 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really, as the XML-ID entry __export__.<whatever> will be noupdate=1.

I just tested in a 16.0 CE database.

  • create a new product template, via UI
# select id, name, categ_id, type from product_template where id = 28;
 id |            name             | categ_id | type  
----+-----------------------------+----------+-------
 28 | {"en_US": "my new product"} |        1 | consu
  • export the product via UI, (checking compatible for import)
select id, module, name, model, res_id, noupdate from ir_model_data where res_id = 28 and model = 'product.template';
  id   |   module   |             name             |      model       | res_id | noupdate 
-------+------------+------------------------------+------------------+--------+----------
 15659 | __export__ | product_template_28_c3c1d954 | product.template |     28 | f

If I understand correctly, noupdate = False, so can_edit = False

did I missed something ? Sorry if my comment is not relevant.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ouch, I didn't expect that one... Anyway, fixed 😉

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"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only setting users??

Copy link
Member Author

@pedrobaeza pedrobaeza May 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't changed this. Only being consistent with the other buttons. But yes, it seems a bit restricted. What do you think, @etobella ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was done this way in order to set some groups, but we can create a new set if we think that it is the best option.

/>
<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>
Loading