diff --git a/spreadsheet_dashboard_oca/README.rst b/spreadsheet_dashboard_oca/README.rst index 5b74e62..6800da8 100644 --- a/spreadsheet_dashboard_oca/README.rst +++ b/spreadsheet_dashboard_oca/README.rst @@ -1,7 +1,3 @@ -.. image:: https://odoo-community.org/readme-banner-image - :target: https://odoo-community.org/get-involved?utm_source=readme - :alt: Odoo Community Association - ========================= Spreadsheet Dashboard Oca ========================= @@ -17,7 +13,7 @@ Spreadsheet Dashboard Oca .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png :target: https://odoo-community.org/page/development-status :alt: Beta -.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fspreadsheet-lightgray.png?logo=github @@ -61,14 +57,14 @@ Authors Contributors ------------ -- Enric Tobella -- `Tecnativa `__: +- Enric Tobella +- `Tecnativa `__: - - Carlos Roca + - Carlos Roca -- `Open User Systems `__: +- `Open User Systems `__: - - Chris Mann + - Chris Mann Maintainers ----------- diff --git a/spreadsheet_dashboard_oca/__manifest__.py b/spreadsheet_dashboard_oca/__manifest__.py index 8d08ea2..7fc19c2 100644 --- a/spreadsheet_dashboard_oca/__manifest__.py +++ b/spreadsheet_dashboard_oca/__manifest__.py @@ -14,9 +14,20 @@ "spreadsheet_oca", ], "data": [ + "security/ir.model.access.csv", "wizards/spreadsheet_spreadsheet_import.xml", + "wizards/spreadsheet_to_dashboard.xml", "views/spreadsheet_dashboard_group_views.xml", "views/spreadsheet_dashboard.xml", "data/spreadsheet_spreadsheet_import_mode.xml", ], + "assets": { + "spreadsheet.o_spreadsheet": [ + ( + "after", + "spreadsheet/static/src/o_spreadsheet/o_spreadsheet.js", + "spreadsheet_dashboard_oca/static/src/bundle/*.js", + ), + ], + }, } diff --git a/spreadsheet_dashboard_oca/security/ir.model.access.csv b/spreadsheet_dashboard_oca/security/ir.model.access.csv new file mode 100644 index 0000000..28c5d5f --- /dev/null +++ b/spreadsheet_dashboard_oca/security/ir.model.access.csv @@ -0,0 +1,2 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_spreadsheet_to_dashboard_wizard,spreadsheet.to.dashboard.wizard.access,model_spreadsheet_to_dashboard,base.group_user,1,1,1,0 diff --git a/spreadsheet_dashboard_oca/static/description/index.html b/spreadsheet_dashboard_oca/static/description/index.html index 8d8fbe9..fce2b5f 100644 --- a/spreadsheet_dashboard_oca/static/description/index.html +++ b/spreadsheet_dashboard_oca/static/description/index.html @@ -3,7 +3,7 @@ -README.rst +Spreadsheet Dashboard Oca -
+
+

Spreadsheet Dashboard Oca

- - -Odoo Community Association - -
-

Spreadsheet Dashboard Oca

-

Beta License: AGPL-3 OCA/spreadsheet Translate me on Weblate Try me on Runboat

+

Beta License: AGPL-3 OCA/spreadsheet Translate me on Weblate Try me on Runboat

This module allows to edit spreadsheet dashboards using OCA Spreadsheet editor.

Table of contents

@@ -390,7 +385,7 @@

Spreadsheet Dashboard Oca

-

Bug Tracker

+

Bug Tracker

Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us to smash it by providing a detailed and welcomed @@ -398,15 +393,15 @@

Bug Tracker

Do not contact contributors directly about support or help with technical issues.

-

Credits

+

Credits

-

Authors

+

Authors

  • CreuBlanca
-

Contributors

+

Contributors

-

Maintainers

+

Maintainers

This module is maintained by the OCA.

Odoo Community Association @@ -433,6 +428,5 @@

Maintainers

-
diff --git a/spreadsheet_dashboard_oca/static/src/bundle/spreadsheet_to_dashboard.esm.js b/spreadsheet_dashboard_oca/static/src/bundle/spreadsheet_to_dashboard.esm.js new file mode 100644 index 0000000..f98c64d --- /dev/null +++ b/spreadsheet_dashboard_oca/static/src/bundle/spreadsheet_to_dashboard.esm.js @@ -0,0 +1,55 @@ +import * as spreadsheet from "@odoo/o-spreadsheet"; +import {useState, useSubEnv} from "@odoo/owl"; +import {SpreadsheetRenderer} from "@spreadsheet_oca/spreadsheet/bundle/spreadsheet_renderer.esm"; +import {_t} from "@web/core/l10n/translation"; +import {patch} from "@web/core/utils/patch"; +const {topbarMenuRegistry} = spreadsheet.registries; +import {user} from "@web/core/user"; + +topbarMenuRegistry.addChild("add_to_dashboard", ["file"], { + name: _t("Add to dashboard"), + sequence: 120, + execute: (env) => env.addToDashboard(), + isVisible: (env) => env.canAddToDashboard?.(), + icon: "o-spreadsheet-Icon.INSERT_CHART", +}); + +patch(SpreadsheetRenderer.prototype, { + setup() { + super.setup(); + this.state = useState({canAddToDashboard: false}); + this._checkDashboardPermission(); + useSubEnv({ + addToDashboard: this._addToDashboard.bind(this), + canAddToDashboard: () => this.state.canAddToDashboard, + }); + }, + async _checkDashboardPermission() { + const result = + (await user.hasGroup("base.group_system")) || + (await user.hasGroup("spreadsheet_dashboard.group_dashboard_manager")); + this.state.canAddToDashboard = result; + }, + async _addToDashboard() { + const record = this.props.record; + const resId = this.props.res_id; + const name = record.name; + this.onSpreadsheetSaved(); + this.env.services.action.doAction( + { + name: _t("Add to dashboard"), + type: "ir.actions.act_window", + view_mode: "form", + views: [[false, "form"]], + target: "new", + res_model: "spreadsheet.to.dashboard", + }, + { + additionalContext: { + default_spreadsheet_id: resId, + default_name: name, + }, + } + ); + }, +}); diff --git a/spreadsheet_dashboard_oca/wizards/__init__.py b/spreadsheet_dashboard_oca/wizards/__init__.py index 758b199..d77deca 100644 --- a/spreadsheet_dashboard_oca/wizards/__init__.py +++ b/spreadsheet_dashboard_oca/wizards/__init__.py @@ -1 +1 @@ -from . import spreadsheet_spreadsheet_import +from . import spreadsheet_spreadsheet_import, spreadsheet_to_dashboard diff --git a/spreadsheet_dashboard_oca/wizards/spreadsheet_to_dashboard.py b/spreadsheet_dashboard_oca/wizards/spreadsheet_to_dashboard.py new file mode 100644 index 0000000..4a0bcba --- /dev/null +++ b/spreadsheet_dashboard_oca/wizards/spreadsheet_to_dashboard.py @@ -0,0 +1,62 @@ +# Copyright 2025 Open User Systems +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +import json + +from odoo import api, fields, models + + +class SpreadsheetToDashboard(models.TransientModel): + _name = "spreadsheet.to.dashboard" + _description = "Create dashboard from spreadsheet" + + name = fields.Char( + "Dashboard Name", + required=True, + compute="_compute_name", + store=True, + readonly=False, + precompute=True, + ) + spreadsheet_id = fields.Many2one( + "spreadsheet.spreadsheet", + readonly=True, + required=True, + ) + dashboard_group_id = fields.Many2one( + "spreadsheet.dashboard.group", string="Dashboard Section", required=True + ) + group_ids = fields.Many2many( + "res.groups", + default=lambda self: self._default_group_ids(), + string="User Groups", + ) + + def _default_group_ids(self): + return self.env["spreadsheet.dashboard"].default_get(["group_ids"])["group_ids"] + + @api.depends("spreadsheet_id.name") + def _compute_name(self): + for rec in self: + rec.name = rec.spreadsheet_id.name + + def create_dashboard(self): + self.ensure_one() + spreadsheet_data = self.spreadsheet_id.get_spreadsheet_data() + spreadsheet_raw = spreadsheet_data["spreadsheet_raw"] + dashboard = self.env["spreadsheet.dashboard"].create( + { + "name": self.name, + "dashboard_group_id": self.dashboard_group_id.id, + "group_ids": self.group_ids.ids, + "spreadsheet_data": json.dumps(spreadsheet_raw), + } + ) + return { + "type": "ir.actions.client", + "tag": "action_spreadsheet_dashboard", + "name": self.name, + "params": { + "dashboard_id": dashboard.id, + }, + } diff --git a/spreadsheet_dashboard_oca/wizards/spreadsheet_to_dashboard.xml b/spreadsheet_dashboard_oca/wizards/spreadsheet_to_dashboard.xml new file mode 100644 index 0000000..a734389 --- /dev/null +++ b/spreadsheet_dashboard_oca/wizards/spreadsheet_to_dashboard.xml @@ -0,0 +1,32 @@ + + + + spreadsheet.to.dashboard.view.form + spreadsheet.to.dashboard + +
+ + + + + + + + + + +
+
+
+