Skip to content

Commit bc3b15c

Browse files
[IMP] spreadsheet_dashboard_oca: Add to dashboard feature from existing spreadsheet
1 parent 6aa56fd commit bc3b15c

File tree

8 files changed

+178
-26
lines changed

8 files changed

+178
-26
lines changed

spreadsheet_dashboard_oca/README.rst

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
.. image:: https://odoo-community.org/readme-banner-image
2-
:target: https://odoo-community.org/get-involved?utm_source=readme
3-
:alt: Odoo Community Association
4-
51
=========================
62
Spreadsheet Dashboard Oca
73
=========================
@@ -17,7 +13,7 @@ Spreadsheet Dashboard Oca
1713
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
1814
:target: https://odoo-community.org/page/development-status
1915
:alt: Beta
20-
.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png
16+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
2117
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
2218
:alt: License: AGPL-3
2319
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fspreadsheet-lightgray.png?logo=github
@@ -61,14 +57,14 @@ Authors
6157
Contributors
6258
------------
6359

64-
- Enric Tobella
65-
- `Tecnativa <https://www.tecnativa.com>`__:
60+
- Enric Tobella
61+
- `Tecnativa <https://www.tecnativa.com>`__:
6662

67-
- Carlos Roca
63+
- Carlos Roca
6864

69-
- `Open User Systems <https://www.openusersystems.com>`__:
65+
- `Open User Systems <https://www.openusersystems.com>`__:
7066

71-
- Chris Mann
67+
- Chris Mann
7268

7369
Maintainers
7470
-----------

spreadsheet_dashboard_oca/__manifest__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,20 @@
1414
"spreadsheet_oca",
1515
],
1616
"data": [
17+
"security/ir.model.access.csv",
1718
"wizards/spreadsheet_spreadsheet_import.xml",
19+
"wizards/spreadsheet_to_dashboard.xml",
1820
"views/spreadsheet_dashboard_group_views.xml",
1921
"views/spreadsheet_dashboard.xml",
2022
"data/spreadsheet_spreadsheet_import_mode.xml",
2123
],
24+
"assets": {
25+
"spreadsheet.o_spreadsheet": [
26+
(
27+
"after",
28+
"spreadsheet/static/src/o_spreadsheet/o_spreadsheet.js",
29+
"spreadsheet_dashboard_oca/static/src/bundle/*.js",
30+
),
31+
],
32+
},
2233
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
2+
access_spreadsheet_to_dashboard_wizard,spreadsheet.to.dashboard.wizard.access,model_spreadsheet_to_dashboard,base.group_user,1,1,1,0

spreadsheet_dashboard_oca/static/description/index.html

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<head>
44
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
55
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
6-
<title>README.rst</title>
6+
<title>Spreadsheet Dashboard Oca</title>
77
<style type="text/css">
88

99
/*
@@ -360,21 +360,16 @@
360360
</style>
361361
</head>
362362
<body>
363-
<div class="document">
363+
<div class="document" id="spreadsheet-dashboard-oca">
364+
<h1 class="title">Spreadsheet Dashboard Oca</h1>
364365

365-
366-
<a class="reference external image-reference" href="https://odoo-community.org/get-involved?utm_source=readme">
367-
<img alt="Odoo Community Association" src="https://odoo-community.org/readme-banner-image" />
368-
</a>
369-
<div class="section" id="spreadsheet-dashboard-oca">
370-
<h1>Spreadsheet Dashboard Oca</h1>
371366
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
372367
!! This file is generated by oca-gen-addon-readme !!
373368
!! changes will be overwritten. !!
374369
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
375370
!! source digest: sha256:3cc11a34f632c64341e2dee08d3fc582e30f6a13f049b460e154768d0368a7e6
376371
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
377-
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/license-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/spreadsheet/tree/18.0/spreadsheet_dashboard_oca"><img alt="OCA/spreadsheet" src="https://img.shields.io/badge/github-OCA%2Fspreadsheet-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/spreadsheet-18-0/spreadsheet-18-0-spreadsheet_dashboard_oca"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/spreadsheet&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
372+
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/spreadsheet/tree/18.0/spreadsheet_dashboard_oca"><img alt="OCA/spreadsheet" src="https://img.shields.io/badge/github-OCA%2Fspreadsheet-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/spreadsheet-18-0/spreadsheet-18-0-spreadsheet_dashboard_oca"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/spreadsheet&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
378373
<p>This module allows to edit spreadsheet dashboards using OCA Spreadsheet
379374
editor.</p>
380375
<p><strong>Table of contents</strong></p>
@@ -390,23 +385,23 @@ <h1>Spreadsheet Dashboard Oca</h1>
390385
</ul>
391386
</div>
392387
<div class="section" id="bug-tracker">
393-
<h2><a class="toc-backref" href="#toc-entry-1">Bug Tracker</a></h2>
388+
<h1><a class="toc-backref" href="#toc-entry-1">Bug Tracker</a></h1>
394389
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/spreadsheet/issues">GitHub Issues</a>.
395390
In case of trouble, please check there if your issue has already been reported.
396391
If you spotted it first, help us to smash it by providing a detailed and welcomed
397392
<a class="reference external" href="https://github.com/OCA/spreadsheet/issues/new?body=module:%20spreadsheet_dashboard_oca%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
398393
<p>Do not contact contributors directly about support or help with technical issues.</p>
399394
</div>
400395
<div class="section" id="credits">
401-
<h2><a class="toc-backref" href="#toc-entry-2">Credits</a></h2>
396+
<h1><a class="toc-backref" href="#toc-entry-2">Credits</a></h1>
402397
<div class="section" id="authors">
403-
<h3><a class="toc-backref" href="#toc-entry-3">Authors</a></h3>
398+
<h2><a class="toc-backref" href="#toc-entry-3">Authors</a></h2>
404399
<ul class="simple">
405400
<li>CreuBlanca</li>
406401
</ul>
407402
</div>
408403
<div class="section" id="contributors">
409-
<h3><a class="toc-backref" href="#toc-entry-4">Contributors</a></h3>
404+
<h2><a class="toc-backref" href="#toc-entry-4">Contributors</a></h2>
410405
<ul class="simple">
411406
<li>Enric Tobella</li>
412407
<li><a class="reference external" href="https://www.tecnativa.com">Tecnativa</a>:<ul>
@@ -420,7 +415,7 @@ <h3><a class="toc-backref" href="#toc-entry-4">Contributors</a></h3>
420415
</ul>
421416
</div>
422417
<div class="section" id="maintainers">
423-
<h3><a class="toc-backref" href="#toc-entry-5">Maintainers</a></h3>
418+
<h2><a class="toc-backref" href="#toc-entry-5">Maintainers</a></h2>
424419
<p>This module is maintained by the OCA.</p>
425420
<a class="reference external image-reference" href="https://odoo-community.org">
426421
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
@@ -433,6 +428,5 @@ <h3><a class="toc-backref" href="#toc-entry-5">Maintainers</a></h3>
433428
</div>
434429
</div>
435430
</div>
436-
</div>
437431
</body>
438432
</html>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import * as spreadsheet from "@odoo/o-spreadsheet";
2+
import {useState, useSubEnv} from "@odoo/owl";
3+
import {SpreadsheetRenderer} from "@spreadsheet_oca/spreadsheet/bundle/spreadsheet_renderer.esm";
4+
import {_t} from "@web/core/l10n/translation";
5+
import {patch} from "@web/core/utils/patch";
6+
const {topbarMenuRegistry} = spreadsheet.registries;
7+
import {user} from "@web/core/user";
8+
9+
topbarMenuRegistry.addChild("add_to_dashboard", ["file"], {
10+
name: _t("Add to dashboard"),
11+
sequence: 120,
12+
execute: (env) => env.addToDashboard(),
13+
isVisible: (env) => env.canAddToDashboard?.(),
14+
icon: "o-spreadsheet-Icon.INSERT_CHART",
15+
});
16+
17+
patch(SpreadsheetRenderer.prototype, {
18+
setup() {
19+
super.setup();
20+
this.state = useState({canAddToDashboard: false});
21+
this._checkDashboardPermission();
22+
useSubEnv({
23+
addToDashboard: this._addToDashboard.bind(this),
24+
canAddToDashboard: () => this.state.canAddToDashboard,
25+
});
26+
},
27+
async _checkDashboardPermission() {
28+
const result =
29+
(await user.hasGroup("base.group_system")) ||
30+
(await user.hasGroup("spreadsheet_dashboard.group_dashboard_manager"));
31+
this.state.canAddToDashboard = result;
32+
},
33+
async _addToDashboard() {
34+
const record = this.props.record;
35+
const resId = this.props.res_id;
36+
const name = record.name;
37+
this.onSpreadsheetSaved();
38+
this.env.services.action.doAction(
39+
{
40+
name: _t("Add to dashboard"),
41+
type: "ir.actions.act_window",
42+
view_mode: "form",
43+
views: [[false, "form"]],
44+
target: "new",
45+
res_model: "spreadsheet.to.dashboard",
46+
},
47+
{
48+
additionalContext: {
49+
default_spreadsheet_id: resId,
50+
default_name: name,
51+
},
52+
}
53+
);
54+
},
55+
});
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from . import spreadsheet_spreadsheet_import
1+
from . import spreadsheet_spreadsheet_import, spreadsheet_to_dashboard
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Copyright 2025 Open User Systems
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
import json
5+
6+
from odoo import api, fields, models
7+
8+
9+
class SpreadsheetToDashboard(models.TransientModel):
10+
_name = "spreadsheet.to.dashboard"
11+
_description = "Create dashboard from spreadsheet"
12+
13+
name = fields.Char(
14+
"Dashboard Name",
15+
required=True,
16+
compute="_compute_name",
17+
store=True,
18+
readonly=False,
19+
precompute=True,
20+
)
21+
spreadsheet_id = fields.Many2one(
22+
"spreadsheet.spreadsheet",
23+
readonly=True,
24+
required=True,
25+
)
26+
dashboard_group_id = fields.Many2one(
27+
"spreadsheet.dashboard.group", string="Dashboard Section", required=True
28+
)
29+
group_ids = fields.Many2many(
30+
"res.groups",
31+
default=lambda self: self._default_group_ids(),
32+
string="User Groups",
33+
)
34+
35+
def _default_group_ids(self):
36+
return self.env["spreadsheet.dashboard"].default_get(["group_ids"])["group_ids"]
37+
38+
@api.depends("spreadsheet_id.name")
39+
def _compute_name(self):
40+
for rec in self:
41+
rec.name = rec.spreadsheet_id.name
42+
43+
def create_dashboard(self):
44+
self.ensure_one()
45+
spreadsheet_data = self.spreadsheet_id.get_spreadsheet_data()
46+
spreadsheet_raw = spreadsheet_data["spreadsheet_raw"]
47+
dashboard = self.env["spreadsheet.dashboard"].create(
48+
{
49+
"name": self.name,
50+
"dashboard_group_id": self.dashboard_group_id.id,
51+
"group_ids": self.group_ids.ids,
52+
"spreadsheet_data": json.dumps(spreadsheet_raw),
53+
}
54+
)
55+
return {
56+
"type": "ir.actions.client",
57+
"tag": "action_spreadsheet_dashboard",
58+
"name": self.name,
59+
"params": {
60+
"dashboard_id": dashboard.id,
61+
},
62+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<odoo>
3+
<record id="spreadsheet_to_dashboard_view_form" model="ir.ui.view">
4+
<field name="name">spreadsheet.to.dashboard.view.form</field>
5+
<field name="model">spreadsheet.to.dashboard</field>
6+
<field name="arch" type="xml">
7+
<form>
8+
<group>
9+
<group>
10+
<field name="name" />
11+
<field
12+
name="dashboard_group_id"
13+
options="{'no_open': True, 'no_create_edit': True}"
14+
/>
15+
</group>
16+
<group>
17+
<field name="group_ids" widget="many2many_tags" />
18+
</group>
19+
</group>
20+
<footer>
21+
<button
22+
string="Create"
23+
name="create_dashboard"
24+
type="object"
25+
class="btn-primary"
26+
/>
27+
<button string="Cancel" class="btn-secondary" special="cancel" />
28+
</footer>
29+
</form>
30+
</field>
31+
</record>
32+
</odoo>

0 commit comments

Comments
 (0)