diff --git a/kpi_dashboard_test/README.rst b/kpi_dashboard_test/README.rst new file mode 100644 index 00000000..591aee8c --- /dev/null +++ b/kpi_dashboard_test/README.rst @@ -0,0 +1,73 @@ +=================== +Kpi Dashboard: Test +=================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/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%2Freporting--engine-lightgray.png?logo=github + :target: https://github.com/OCA/reporting-engine/tree/12.0/kpi_dashboard_test + :alt: OCA/reporting-engine +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/reporting-engine-12-0/reporting-engine-12-0-kpi_dashboard_test + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/143/12.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module is used in order to test KPI Dashboard + +**Table of contents** + +.. contents:: + :local: + +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 smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Creu Blanca + +Contributors +~~~~~~~~~~~~ + +* Enric Tobella + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/reporting-engine `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/kpi_dashboard_test/__init__.py b/kpi_dashboard_test/__init__.py new file mode 100644 index 00000000..0650744f --- /dev/null +++ b/kpi_dashboard_test/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/kpi_dashboard_test/__manifest__.py b/kpi_dashboard_test/__manifest__.py new file mode 100644 index 00000000..6d684389 --- /dev/null +++ b/kpi_dashboard_test/__manifest__.py @@ -0,0 +1,14 @@ +# Copyright 2020 Creu Blanca +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Kpi Dashboard: Test", + "summary": """ + Testing KPI dashboard""", + "version": "12.0.1.0.0", + "license": "AGPL-3", + "author": "Creu Blanca,Odoo Community Association (OCA)", + "website": "https://github.com/reporting-engine", + "depends": ["kpi_dashboard"], + "demo": ["demo/demo_dashboard.xml"], +} diff --git a/kpi_dashboard_test/demo/demo_dashboard.xml b/kpi_dashboard_test/demo/demo_dashboard.xml new file mode 100644 index 00000000..30fc5e86 --- /dev/null +++ b/kpi_dashboard_test/demo/demo_dashboard.xml @@ -0,0 +1,126 @@ + + + + Dashboard + 4 + 50 + 250 + #020202 + + + + Number 01 + $ + function + number + test_demo_number + + + + Number 02 + + function + number + test_demo_number + + + + + + Meter 01 + + function + meter + test_demo_meter + + + + Meter 02 + $ + function + meter + test_demo_meter + + + + + + Graph + function + graph + test_demo_graph + + + + + + + Dashboard title + + 1 + 1 + 4 + #707070 + #000000 + + + + Number 01 + + + 1 + 2 + 4 + #47bbb3 + #ffffff + + + + Number 02 + + + 1 + 6 + 4 + #ec663c + #ffffff + + + + Meter 01 + + + 2 + 2 + 4 + #9c4274 + #ffffff + + + + Meter 02 + + + 2 + 6 + 4 + #12b0c5 + #ffffff + + + + Graph + + + 3 + 2 + 2 + 8 + #ff9618 + #ffffff + + + diff --git a/kpi_dashboard_test/models/__init__.py b/kpi_dashboard_test/models/__init__.py new file mode 100644 index 00000000..5bb66de7 --- /dev/null +++ b/kpi_dashboard_test/models/__init__.py @@ -0,0 +1 @@ +from . import kpi_kpi diff --git a/kpi_dashboard_test/models/kpi_kpi.py b/kpi_dashboard_test/models/kpi_kpi.py new file mode 100644 index 00000000..f74b04a7 --- /dev/null +++ b/kpi_dashboard_test/models/kpi_kpi.py @@ -0,0 +1,48 @@ +# Copyright 2020 Creu Blanca +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models +import random + + +class KpiKpi(models.Model): + _inherit = "kpi.kpi" + + def test_demo_number(self): + return { + "value": random.random() * 10000, + "previous": random.random() * 10000, + } + + def test_demo_meter(self): + return { + "min": 0, + "max": 100, + "value": random.random() * 100, + } + + def test_demo_graph(self): + return { + "graphs": [ + { + "values": [ + {"x": i, "y": random.random() * 1000} + for i in range(1, 12) + ], + "title": "Current Year", + "key": "current", + "area": True, + "color": "ffffff", + }, + { + "values": [ + {"x": i, "y": random.random() * 1000} + for i in range(1, 12) + ], + "title": "Previous Year", + "key": "previous", + "area": True, + "color": "000000", + }, + ] + } diff --git a/kpi_dashboard_test/readme/CONTRIBUTORS.rst b/kpi_dashboard_test/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..93ec993e --- /dev/null +++ b/kpi_dashboard_test/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Enric Tobella diff --git a/kpi_dashboard_test/readme/DESCRIPTION.rst b/kpi_dashboard_test/readme/DESCRIPTION.rst new file mode 100644 index 00000000..e9bc1e9d --- /dev/null +++ b/kpi_dashboard_test/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module is used in order to test KPI Dashboard diff --git a/kpi_dashboard_test/static/description/icon.png b/kpi_dashboard_test/static/description/icon.png new file mode 100644 index 00000000..3a0328b5 Binary files /dev/null and b/kpi_dashboard_test/static/description/icon.png differ diff --git a/kpi_dashboard_test/static/description/index.html b/kpi_dashboard_test/static/description/index.html new file mode 100644 index 00000000..e5c65ae9 --- /dev/null +++ b/kpi_dashboard_test/static/description/index.html @@ -0,0 +1,419 @@ + + + + + + +Kpi Dashboard: Test + + + +
+

Kpi Dashboard: Test

+ + +

Beta License: AGPL-3 OCA/reporting-engine Translate me on Weblate Try me on Runbot

+

This module is used in order to test KPI Dashboard

+

Table of contents

+ +
+

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 smashing it by providing a detailed and welcomed +feedback.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Creu Blanca
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/reporting-engine project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/kpi_dashboard_test/tests/__init__.py b/kpi_dashboard_test/tests/__init__.py new file mode 100644 index 00000000..7c3e55f2 --- /dev/null +++ b/kpi_dashboard_test/tests/__init__.py @@ -0,0 +1 @@ +from . import test_kpi_dashboard diff --git a/kpi_dashboard_test/tests/test_kpi_dashboard.py b/kpi_dashboard_test/tests/test_kpi_dashboard.py new file mode 100644 index 00000000..571bf859 --- /dev/null +++ b/kpi_dashboard_test/tests/test_kpi_dashboard.py @@ -0,0 +1,123 @@ +# Copyright 2020 Creu Blanca +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.tests.common import TransactionCase +from odoo.exceptions import ValidationError +from odoo.tests.common import Form + + +class TestKpiDashboard(TransactionCase): + + def setUp(self): + super(TestKpiDashboard, self).setUp() + self.kpi_01 = self.env['kpi.kpi'].create({ + 'name': 'KPI 01', + 'computation_method': 'function', + 'widget': 'number', + 'function': 'test_demo_number' + }) + self.kpi_02 = self.env['kpi.kpi'].create({ + 'name': 'KPI 02', + 'computation_method': 'function', + 'widget': 'number', + 'function': 'test_demo_number' + }) + self.dashboard = self.env['kpi.dashboard'].create({ + 'name': 'Dashboard', + 'number_of_columns': 4, + 'widget_dimension_x': 250, + 'widget_dimension_y': 250, + }) + self.env['kpi.dashboard.item'].create({ + 'dashboard_id': self.dashboard.id, + 'kpi_id': self.kpi_01.id, + 'name': self.kpi_01.name, + 'row': 1, + 'column': 1, + }) + self.env['kpi.dashboard.item'].create({ + 'dashboard_id': self.dashboard.id, + 'name': self.kpi_02.name, + 'kpi_id': self.kpi_02.id, + 'row': 1, + 'column': 2, + }) + self.env['kpi.dashboard.item'].create({ + 'dashboard_id': self.dashboard.id, + 'name': 'TITLE', + 'row': 2, + 'column': 1, + }) + + def test_constrains_01(self): + with self.assertRaises(ValidationError): + self.kpi_01.dashboard_item_ids.write({'size_x': 2}) + + def test_constrains_02(self): + with self.assertRaises(ValidationError): + self.kpi_02.dashboard_item_ids.write({'size_x': 4}) + + def test_constrains_03(self): + with self.assertRaises(ValidationError): + self.kpi_01.dashboard_item_ids.write({'size_y': 11}) + + def test_menu(self): + self.assertFalse(self.dashboard.menu_id) + wzd = self.env['kpi.dashboard.menu'].create({ + 'dashboard_id': self.dashboard.id, + 'menu_id': self.env['ir.ui.menu'].search([], limit=1).id, + }) + wzd.generate_menu() + self.assertTrue(self.dashboard.menu_id) + self.assertFalse(self.dashboard.menu_id.groups_id) + self.dashboard.write({ + 'group_ids': [ + (6, 0, self.env['res.groups'].search([], limit=1).ids)] + }) + self.assertTrue(self.dashboard.menu_id.groups_id) + + def test_onchange(self): + with Form(self.env['kpi.dashboard']) as dashboard: + dashboard.name = 'New Dashboard' + with dashboard.item_ids.new() as item: + item.kpi_id = self.kpi_01 + self.assertTrue(item.name) + + def test_read_dashboard(self): + data = self.dashboard.read_dashboard() + title_found = False + actions = 0 + for item in data['item_ids']: + if not item.get('kpi_id'): + title_found = True + if item.get('actions', False): + actions += len(item['actions']) + self.assertTrue(title_found) + self.assertEqual(0, actions) + act01 = self.env['ir.actions.act_window'].search( + [], limit=1) + self.env['kpi.kpi.action'].create({ + 'kpi_id': self.kpi_01.id, + 'action': '%s,%s' % (act01._name, act01.id) + }) + act02 = self.env['ir.actions.act_url'].search( + [], limit=1) + self.env['kpi.kpi.action'].create({ + 'kpi_id': self.kpi_01.id, + 'action': '%s,%s' % (act02._name, act02.id) + }) + data = self.dashboard.read_dashboard() + title_found = False + actions = 0 + for item in data['item_ids']: + if not item.get('kpi_id'): + title_found = True + if item.get('actions', False): + actions += len(item['actions']) + self.assertTrue(title_found) + self.assertEqual(2, actions) + + def test_compute(self): + self.assertFalse(self.kpi_01.value_last_update) + self.kpi_01.compute() + self.assertTrue(self.kpi_01.value_last_update)