commit
af7ffca6f0
|
@ -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
|
||||||
|
<https://github.com/OCA/reporting-engine/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.
|
|
@ -0,0 +1,3 @@
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
|
|
||||||
|
from . import models
|
|
@ -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,
|
||||||
|
}
|
Binary file not shown.
After Width: | Height: | Size: 11 KiB |
|
@ -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
|
|
@ -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]
|
|
@ -0,0 +1,19 @@
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
|
|
||||||
|
from odoo import fields, models
|
||||||
|
|
||||||
|
|
||||||
|
class BiSQLViewField(models.Model):
|
||||||
|
_inherit = 'bi.sql.view.field'
|
||||||
|
|
||||||
|
_GROUP_OPERATOR_SELECTION = [
|
||||||
|
('sum', 'Sum'),
|
||||||
|
('avg', 'Average'),
|
||||||
|
('min', 'Minimum'),
|
||||||
|
('max', 'Maximum'),
|
||||||
|
]
|
||||||
|
|
||||||
|
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")
|
|
@ -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)
|
|
@ -0,0 +1,19 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
|
-->
|
||||||
|
|
||||||
|
<odoo>
|
||||||
|
|
||||||
|
<record id="view_bi_sql_view_form" model="ir.ui.view">
|
||||||
|
<field name="model">bi.sql.view</field>
|
||||||
|
<field name='inherit_id' ref='bi_sql_editor.view_bi_sql_view_form'/>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<field name="ttype" position='before'>
|
||||||
|
<field name='group_operator' attrs="{
|
||||||
|
'invisible': ['!', ('ttype', 'in', ('float', 'integer'))]}"/>
|
||||||
|
</field>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
</odoo>
|
Loading…
Reference in New Issue