From c414ea4a875ef7c428389943758bcfd1d62c0908 Mon Sep 17 00:00:00 2001 From: Richard deMeester Date: Thu, 28 Nov 2019 12:11:36 +1100 Subject: [PATCH 1/4] [12.0][ENH] sql view - allow group operator Replaces #345 Adds the possibility, for float and integer columns, to apply a group operator (average, min, max). --- bi_sql_editor_aggregate/__init__.py | 3 ++ bi_sql_editor_aggregate/__manifest__.py | 20 +++++++++ bi_sql_editor_aggregate/description/icon.png | Bin 0 -> 11127 bytes bi_sql_editor_aggregate/models/__init__.py | 5 +++ bi_sql_editor_aggregate/models/bi_sql_view.py | 38 ++++++++++++++++++ .../models/bi_sql_view_field.py | 25 ++++++++++++ bi_sql_editor_aggregate/models/ir_model.py | 14 +++++++ .../views/view_bi_sql_view.xml | 19 +++++++++ 8 files changed, 124 insertions(+) create mode 100644 bi_sql_editor_aggregate/__init__.py create mode 100644 bi_sql_editor_aggregate/__manifest__.py create mode 100644 bi_sql_editor_aggregate/description/icon.png create mode 100644 bi_sql_editor_aggregate/models/__init__.py create mode 100644 bi_sql_editor_aggregate/models/bi_sql_view.py create mode 100644 bi_sql_editor_aggregate/models/bi_sql_view_field.py create mode 100644 bi_sql_editor_aggregate/models/ir_model.py create mode 100644 bi_sql_editor_aggregate/views/view_bi_sql_view.xml diff --git a/bi_sql_editor_aggregate/__init__.py b/bi_sql_editor_aggregate/__init__.py new file mode 100644 index 00000000..83e553ac --- /dev/null +++ b/bi_sql_editor_aggregate/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import models diff --git a/bi_sql_editor_aggregate/__manifest__.py b/bi_sql_editor_aggregate/__manifest__.py new file mode 100644 index 00000000..ac3766f0 --- /dev/null +++ b/bi_sql_editor_aggregate/__manifest__.py @@ -0,0 +1,20 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +{ + 'name': 'BI SQL Editor Aggregate', + 'summary': 'BI SQL Editor Aggregation', + 'version': '12.0.1.0.0', + 'license': 'AGPL-3', + 'category': 'Reporting', + 'author': 'Richard deMeester,Odoo Community Association (OCA)', + 'website': 'https://github.com/OCA/reporting-engine', + 'depends': [ + 'bi_sql_editor', + ], + 'data': [ + 'views/view_bi_sql_view.xml', + ], + 'demo': [ + ], + 'installable': True, +} diff --git a/bi_sql_editor_aggregate/description/icon.png b/bi_sql_editor_aggregate/description/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..c72ba5caa1302634ebeeb1689bb6df735f8bb5c8 GIT binary patch literal 11127 zcmcI~c|6qH|Nr|vV<=;3D*M_*i?xg`S>_gMNGkghvW!sSN+g;0 zCoQQg2|#C}8HAmRhzU9t6=D$iYiRC_r7{F*LKNFyT;p#| z_n+-MxtzE>x4diDp7oS<6esNq>(=i*uVG@P{IRs`F5~8&<6)QG*QjgTUjCJ`Zm)Eh z(;Er7y@BppcS^tY>~p!W&D-h5mQ4@;39iexS!!}#+BK@aRQ3MH{h`$-73X(Z?OOI8 zyf!lbfwj0Y{q$H^*jmb}JfQ)Tf?2`tzR!K4&XwluMQx}fCKv6q-d&THhss#QKpMv@ z?V0e0i=eNQE{oj?`&UctUk!$@C2S#9U@eu+Re6JWzZn)i4r&V?=}CRPrOZkXI+9`A z+JuJEeLND!JK>CWHeRQxqG%5oaJFsjSG*|nGwB~5r0)wJVVWHEKay;ktxoP9CJrZ| zIi-et_!K_Tim2}Q#Y)Sh6{8vJYs-fVwSV+0*Y#JRFA34E*yT*u%^L82HF<)w*Z}r~ zPSlD-=twC3v&Rt}kg?CM)rqb_vS{&t=7qw{`ueU_ZGChfbR=$7VZ6$@i<}o88}_n>bIf~qK*Tp1FOy!J4nukpl4jv zSmv3!vmtNFM!GIz))8_M zXvQX~U!t#m>`VO8KF#Vh0U(*;WH>mT`V9$M@!IQTEQeaqO7iv(}qM zHbSv$(fik|4idxNAw(BfjUy}G*BlZQK5%IG~DN^-*X)@-$}DDep0utF?)@p zTkJ*J(GR!O@0&Keu2t611Y2s8SpLgb!-WP2!+hg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__init__.py b/bi_sql_editor_aggregate/models/__init__.py new file mode 100644 index 00000000..ef99aabc --- /dev/null +++ b/bi_sql_editor_aggregate/models/__init__.py @@ -0,0 +1,5 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import bi_sql_view +from . import bi_sql_view_field +from . import ir_model diff --git a/bi_sql_editor_aggregate/models/bi_sql_view.py b/bi_sql_editor_aggregate/models/bi_sql_view.py new file mode 100644 index 00000000..ceab2a34 --- /dev/null +++ b/bi_sql_editor_aggregate/models/bi_sql_view.py @@ -0,0 +1,38 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import models, tools + + +class BiSQLView(models.Model): + _inherit = 'bi.sql.view' + + def check_manual_fields(self, model): + # check the fields we need are defined on self, to stop it going + # early on install / startup - particularly problematic during upgrade + if 'group_operator' in tools.table_columns( + self.env.cr, 'bi_sql_view_field') and\ + model._name.startswith(self._model_prefix): + # Use SQL instead of ORM, as ORM might not be fully initialised - + # we have no control over the order that fields are defined! + # We are not concerned about user security rules. + self.env.cr.execute( + """ +SELECT + f.name, + f.ttype, + f.group_operator +FROM + bi_sql_view v + LEFT JOIN bi_sql_view_field f ON f.bi_sql_view_id = v.id +WHERE + v.model_name = %s +; + """, (model._name,) + ) + sql_fields = self.env.cr.fetchall() + + for sql_field in sql_fields: + if sql_field[0] in model._fields and\ + sql_field[1] in ('integer', 'float') and\ + sql_field[2]: + model._fields[sql_field[0]].group_operator = sql_field[2] diff --git a/bi_sql_editor_aggregate/models/bi_sql_view_field.py b/bi_sql_editor_aggregate/models/bi_sql_view_field.py new file mode 100644 index 00000000..00efc454 --- /dev/null +++ b/bi_sql_editor_aggregate/models/bi_sql_view_field.py @@ -0,0 +1,25 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import _, api, fields, models + + +class BiSQLViewField(models.Model): + _inherit = 'bi.sql.view.field' + + _GROUP_OPERATOR_SELECTION = [ + ('sum', 'Sum'), + ('avg', 'Average'), + ('min', 'Minimum'), + ('max', 'Maximum'), + ] + + _GRAPH_TYPE_SELECTION = [ + ('col', 'Column'), + ('row', 'Row'), + ('measure', 'Measure'), + ] + + group_operator = fields.Selection( + string='Group Operator', selection=_GROUP_OPERATOR_SELECTION, + help="By default, Odoo will sum the values when grouping. If you wish" + " to alter the behaviour, choose an alternate Group Operator") diff --git a/bi_sql_editor_aggregate/models/ir_model.py b/bi_sql_editor_aggregate/models/ir_model.py new file mode 100644 index 00000000..6ec21d50 --- /dev/null +++ b/bi_sql_editor_aggregate/models/ir_model.py @@ -0,0 +1,14 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import models + + +class IrModelFields(models.Model): + _inherit = 'ir.model.fields' + + def _add_manual_fields(self, model): + super()._add_manual_fields(model) + if 'bi.sql.view' in self.env: + Sql = self.env['bi.sql.view'] + if hasattr(Sql, 'check_manual_fields'): + Sql.check_manual_fields(model) diff --git a/bi_sql_editor_aggregate/views/view_bi_sql_view.xml b/bi_sql_editor_aggregate/views/view_bi_sql_view.xml new file mode 100644 index 00000000..f81f62dc --- /dev/null +++ b/bi_sql_editor_aggregate/views/view_bi_sql_view.xml @@ -0,0 +1,19 @@ + + + + + + + bi.sql.view + + + + + + + + + From 46279078c4dbb0b94a9d47f2c8386a0655dbe706 Mon Sep 17 00:00:00 2001 From: Richard deMeester Date: Thu, 28 Nov 2019 12:59:27 +1100 Subject: [PATCH 2/4] Added README --- bi_sql_editor_aggregate/README.rst | 63 ++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 bi_sql_editor_aggregate/README.rst diff --git a/bi_sql_editor_aggregate/README.rst b/bi_sql_editor_aggregate/README.rst new file mode 100644 index 00000000..4ebfc898 --- /dev/null +++ b/bi_sql_editor_aggregate/README.rst @@ -0,0 +1,63 @@ +.. 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 + +================== +BI Views aggregate +================== + +This module extends the functionality of bi_sql_editor, to support creation +custom aggregation for float and integer values. + +After the model is generated, before creating the UI, the option is given +to define aggregation - either Sum (Default), Average, Minimum, or Maximum. + +Configuration +============= + +No configuration is required after installation. + +Usage +===== + +To use this module, you need to adjust the aggregation on the custom fields +tab of the sql_view between validating the SQL + +#. Go to 'Reporting' / 'Custom Reports' + +Known issues / Roadmap +====================== + +* Can be integrated with bi_sql_editor, but breaks for existing sites. +* Would be good to integrate and remove need for additional install. + +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 smash it by providing detailed and welcomed feedback. + +Credits +======= + +Contributors +------------ + +* Richard deMeester, Willdoo IT (http://www.willdooit.com/) + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +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. + +To contribute to this module, please visit https://odoo-community.org. From 00d43abb9b8a95075f30fa1c07848daaa7523800 Mon Sep 17 00:00:00 2001 From: Richard deMeester Date: Thu, 28 Nov 2019 17:09:40 +1100 Subject: [PATCH 3/4] flake8 lint --- bi_sql_editor_aggregate/models/bi_sql_view.py | 2 +- bi_sql_editor_aggregate/models/bi_sql_view_field.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bi_sql_editor_aggregate/models/bi_sql_view.py b/bi_sql_editor_aggregate/models/bi_sql_view.py index ceab2a34..29d9aeec 100644 --- a/bi_sql_editor_aggregate/models/bi_sql_view.py +++ b/bi_sql_editor_aggregate/models/bi_sql_view.py @@ -10,7 +10,7 @@ class BiSQLView(models.Model): # check the fields we need are defined on self, to stop it going # early on install / startup - particularly problematic during upgrade if 'group_operator' in tools.table_columns( - self.env.cr, 'bi_sql_view_field') and\ + self.env.cr, 'bi_sql_view_field') and\ model._name.startswith(self._model_prefix): # Use SQL instead of ORM, as ORM might not be fully initialised - # we have no control over the order that fields are defined! diff --git a/bi_sql_editor_aggregate/models/bi_sql_view_field.py b/bi_sql_editor_aggregate/models/bi_sql_view_field.py index 00efc454..60bdfcff 100644 --- a/bi_sql_editor_aggregate/models/bi_sql_view_field.py +++ b/bi_sql_editor_aggregate/models/bi_sql_view_field.py @@ -1,6 +1,6 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from odoo import _, api, fields, models +from odoo import fields, models class BiSQLViewField(models.Model): From c06c3914bf3fbd6d20656756a5bf66f5bf3a9629 Mon Sep 17 00:00:00 2001 From: Richard deMeester Date: Fri, 29 Nov 2019 09:14:56 +1100 Subject: [PATCH 4/4] Remove unused constant --- bi_sql_editor_aggregate/models/bi_sql_view_field.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/bi_sql_editor_aggregate/models/bi_sql_view_field.py b/bi_sql_editor_aggregate/models/bi_sql_view_field.py index 60bdfcff..db79ab21 100644 --- a/bi_sql_editor_aggregate/models/bi_sql_view_field.py +++ b/bi_sql_editor_aggregate/models/bi_sql_view_field.py @@ -13,12 +13,6 @@ class BiSQLViewField(models.Model): ('max', 'Maximum'), ] - _GRAPH_TYPE_SELECTION = [ - ('col', 'Column'), - ('row', 'Row'), - ('measure', 'Measure'), - ] - group_operator = fields.Selection( string='Group Operator', selection=_GROUP_OPERATOR_SELECTION, help="By default, Odoo will sum the values when grouping. If you wish"