Skip to content

Commit

Permalink
[IMP] bi_view_editor: pre-commit auto fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
cormaza committed Jan 6, 2025
1 parent a23dc90 commit 4c00443
Show file tree
Hide file tree
Showing 22 changed files with 266 additions and 270 deletions.
150 changes: 77 additions & 73 deletions bi_view_editor/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ BI View Editor
: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/16.0/bi_view_editor
:target: https://github.com/OCA/reporting-engine/tree/18.0/bi_view_editor
: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-16-0/reporting-engine-16-0-bi_view_editor
:target: https://translation.odoo-community.org/projects/reporting-engine-18-0/reporting-engine-18-0-bi_view_editor
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/reporting-engine&target_branch=16.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/reporting-engine&target_branch=18.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand All @@ -33,14 +33,12 @@ execute their own reports without the need to code.

Purpose:

* The BI View Editor is used to create reports not already contained in the
standard Odoo, combining data from existing sources.

* It has been designed to be used by users with little or no knowledge of
the technical architecture of Odoo. Users visually link business objects
and select the fields to visualize.

* The BI View Editor offers users different types of representations,
- The BI View Editor is used to create reports not already contained in
the standard Odoo, combining data from existing sources.
- It has been designed to be used by users with little or no knowledge
of the technical architecture of Odoo. Users visually link business
objects and select the fields to visualize.
- The BI View Editor offers users different types of representations,
including tree, graph, pivot views.

**Table of contents**
Expand All @@ -54,19 +52,21 @@ Installation
In the Odoo configuration file add ``bi_view_editor`` in the list
``server_wide_modules``:

.. code-block:: ini
.. code:: ini
[options]
(...)
server_wide_modules = web,bi_view_editor
(...)
[options]
(...)
server_wide_modules = web,bi_view_editor
(...)
Alternatively specify ``--load=bi_view_editor`` when starting Odoo by command line.
Alternatively specify ``--load=bi_view_editor`` when starting Odoo by
command line.

Optionally it is possible to enable the view of the ER Diagram. For this you
need to install `Graphviz`, an open source graph visualization software:
Optionally it is possible to enable the view of the ER Diagram. For this
you need to install Graphviz, an open source graph visualization
software:

.. code-block:: bash
.. code:: bash
``sudo apt-get install graphviz``
Expand All @@ -76,97 +76,101 @@ Usage
To graphically design your analysis data-set:

- From the Dashboards menu, select "Custom BI Views"
- BI Views creation is restricted to members of "BI View Editor Manager" group.
You can add this group to a user in User form, Access Rights, Technical section.
- BI Views creation is restricted to members of "BI View Editor Manager"
group. You can add this group to a user in User form, Access Rights,
Technical section.
- Browse trough the business objects in the "Query Builder" tab
- Pick the interesting fields (Drag & Drop)
- For each selected field, right-click on the Options column and select whether
it's a row, column or measure; if you want to remove the field from the list
view, unflag the checkbox ´List´ in the Options column
- For each selected field, right-click on the Options column and select
whether it's a row, column or measure; if you want to remove the field
from the list view, unflag the checkbox ´List´ in the Options column
- Save and click "Generate BI View"
- Click "Open BI View" to view the result

To access the created BI View with a dedicated menu:

- If module Dashboard (board) is installed, the standard "Add to My Dashboard"
functionality would be available
- "Create a menu" is restricted to members of "BI View Editor Manager" group.
- Click "Create a menu" to create a new menu item directly linked to your new
BI view (this feature is available in developer mode); when the BI view is
reset back to draft this menu will be removed, and you will need to re-create
the menu entry.

A more advanced UI is also available under the "Details" tab. It provides extra
possibilities for more advanced users, like to use LEFT JOIN instead of the
default INNER JOIN.

It also possible to improve the IDs generation for new views by adding an
`Over Condition` in the "SQL" tab, see https://www.postgresql.org/docs/current/sql-expressions.html#SYNTAX-WINDOW-FUNCTIONS
for further details.
For instance, an ORDER BY clause helps preventing unreliable behavior when
filtering the generated views.
- If module Dashboard (board) is installed, the standard "Add to My
Dashboard" functionality would be available
- "Create a menu" is restricted to members of "BI View Editor Manager"
group.
- Click "Create a menu" to create a new menu item directly linked to
your new BI view (this feature is available in developer mode); when
the BI view is reset back to draft this menu will be removed, and you
will need to re-create the menu entry.

A more advanced UI is also available under the "Details" tab. It
provides extra possibilities for more advanced users, like to use LEFT
JOIN instead of the default INNER JOIN.

It also possible to improve the IDs generation for new views by adding
an Over Condition in the "SQL" tab, see
https://www.postgresql.org/docs/current/sql-expressions.html#SYNTAX-WINDOW-FUNCTIONS
for further details. For instance, an ORDER BY clause helps preventing
unreliable behavior when filtering the generated views.

Known issues / Roadmap
======================

* Non-stored fields and many2many fields are not supported.
* Provide a tutorial (eg. a working example of usage).
* Find better ways to extend the *_auto_init()* without override.
* Possibly avoid the monkey patches.
* Data the user has no access to (e.g. in a multi company situation) can be
viewed by making a view. Would be nice if models available to select when
creating a view are limited to the ones that have intersecting groups.
* As of Odoo 16, translations of the name of a BI View and of the field
descriptions do not work as expected: the translated strings are selected
(by the user's language) when the view is generated (and stored as their
``en_US`` value) instead of when it is displayed.
- Non-stored fields and many2many fields are not supported.
- Provide a tutorial (eg. a working example of usage).
- Find better ways to extend the *\_auto_init()* without override.
- Possibly avoid the monkey patches.
- Data the user has no access to (e.g. in a multi company situation) can
be viewed by making a view. Would be nice if models available to
select when creating a view are limited to the ones that have
intersecting groups.
- As of Odoo 16, translations of the name of a BI View and of the field
descriptions do not work as expected: the translated strings are
selected (by the user's language) when the view is generated (and
stored as their ``en_US`` value) instead of when it is displayed.

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 to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/reporting-engine/issues/new?body=module:%20bi_view_editor%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/reporting-engine/issues/new?body=module:%20bi_view_editor%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Credits
=======

Authors
~~~~~~~
-------

* Onestein

Contributors
~~~~~~~~~~~~
------------

* Simon Janssens <s.janssens@onestein.nl>
* Diego Luis Neto <diegoluis.neto@gmail.com>
* Dennis Sluijk <d.sluijk@onestein.nl>
* Kevin Graveman <k.graveman@onestein.nl>
* Richard Dijkstra <r.dijkstra@onestein.nl>
* Andrea Stirpe <a.stirpe@onestein.nl>
* Antonio Esposito <a.esposito@onestein.nl>
* Jordi Ballester Alomar <jordi.ballester@eficent.com>
* Italo LOPES <italo.lopes@camptocamp.com>
* `Coop IT Easy SC <https://coopiteasy.be>`_:
- Simon Janssens <s.janssens@onestein.nl>
- Diego Luis Neto <diegoluis.neto@gmail.com>
- Dennis Sluijk <d.sluijk@onestein.nl>
- Kevin Graveman <k.graveman@onestein.nl>
- Richard Dijkstra <r.dijkstra@onestein.nl>
- Andrea Stirpe <a.stirpe@onestein.nl>
- Antonio Esposito <a.esposito@onestein.nl>
- Jordi Ballester Alomar <jordi.ballester@eficent.com>
- Italo LOPES <italo.lopes@camptocamp.com>
- `Coop IT Easy SC <https://coopiteasy.be>`__:

* hugues de keyzer
- hugues de keyzer

Other credits
~~~~~~~~~~~~~
-------------

Funders
-------
~~~~~~~

The development of this module for Odoo 11.0 has been financially supported by:
The development of this module for Odoo 11.0 has been financially
supported by:

* IDEAL Connaissances SAS https://www.idealconnaissances.com
- IDEAL Connaissances SAS https://www.idealconnaissances.com

Maintainers
~~~~~~~~~~~
-----------

This module is maintained by the OCA.

Expand All @@ -178,6 +182,6 @@ 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 <https://github.com/OCA/reporting-engine/tree/16.0/bi_view_editor>`_ project on GitHub.
This module is part of the `OCA/reporting-engine <https://github.com/OCA/reporting-engine/tree/18.0/bi_view_editor>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
45 changes: 13 additions & 32 deletions bi_view_editor/models/bve_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def _create_view_arch(self):

def _get_field_def(line):
field_type = line.view_field_type
return '<field name="{}" type="{}" />'.format(line.name, field_type)
return f'<field name="{line.name}" type="{field_type}" />'

bve_field_lines = self.field_ids.filtered("view_field_type")
return list(map(_get_field_def, bve_field_lines))
Expand All @@ -187,8 +187,8 @@ def _create_tree_view_arch(self):

def _get_field_attrs(line):
attr = line.list_attr
res = attr and '{}="{}"'.format(attr, line.description) or ""
return '<field name="{}" {} />'.format(line.name, res)
res = attr and f'{attr}="{line.description}"' or ""
return f'<field name="{line.name}" {res} />'

bve_field_lines = self.field_ids.filtered(lambda l: l.in_list)
return list(map(_get_field_attrs, bve_field_lines.sorted("sequence")))
Expand All @@ -212,9 +212,7 @@ def _create_bve_view(self):
<pivot string="Pivot Analysis">
{}
</pivot>
""".format(
"".join(self._create_view_arch())
),
""".format("".join(self._create_view_arch())),
},
{
"name": "Graph Analysis",
Expand All @@ -226,9 +224,7 @@ def _create_bve_view(self):
type="bar" stacked="True">
{}
</graph>
""".format(
"".join(self._create_view_arch())
),
""".format("".join(self._create_view_arch())),
},
{
"name": "Search BI View",
Expand All @@ -239,9 +235,7 @@ def _create_bve_view(self):
<search>
{}
</search>
""".format(
"".join(self._create_view_arch())
),
""".format("".join(self._create_view_arch())),
},
]
)
Expand All @@ -257,9 +251,7 @@ def _create_bve_view(self):
<tree create="false">
{}
</tree>
""".format(
"".join(self._create_tree_view_arch())
),
""".format("".join(self._create_tree_view_arch())),
}
)

Expand Down Expand Up @@ -344,7 +336,7 @@ def _compute_sql_query(self):
table = line.table_alias
select = line.field_id.name
as_name = line.name
select_str += ",\n {}.{} AS {}".format(table, select, as_name)
select_str += f",\n {table}.{select} AS {as_name}"

if line.table_alias not in tables_map:
table = self.env[line.field_id.model_id.model]._table
Expand All @@ -354,34 +346,23 @@ def _compute_sql_query(self):
if not bve_view.relation_ids and bve_view.field_ids:
first_line = bve_view.field_ids[0]
table = tables_map[first_line.table_alias]
from_str = "{} AS {}".format(table, first_line.table_alias)
from_str = f"{table} AS {first_line.table_alias}"
for line in bve_view.relation_ids:
table = tables_map[line.table_alias]
table_format = "{} AS {}".format(table, line.table_alias)
table_format = f"{table} AS {line.table_alias}"
if not from_str:
from_str += table_format
seen.add(line.table_alias)
if line.table_alias not in seen:
seen.add(line.table_alias)
from_str += "\n"
from_str += " LEFT" if line.left_join else ""
from_str += " JOIN {} ON {}.id = {}.{}".format(
table_format,
line.join_node,
line.table_alias,
line.field_id.name,
)
from_str += f" JOIN {table_format} ON {line.join_node}.id = {line.table_alias}.{line.field_id.name}"
if line.join_node not in seen:
from_str += "\n"
seen.add(line.join_node)
from_str += " LEFT" if line.left_join else ""
from_str += " JOIN {} AS {} ON {}.{} = {}.id".format(
tables_map[line.join_node],
line.join_node,
line.table_alias,
line.field_id.name,
line.join_node,
)
from_str += f" JOIN {tables_map[line.join_node]} AS {line.join_node} ON {line.table_alias}.{line.field_id.name} = {line.join_node}.id"
bve_view.query = """SELECT %s\n\nFROM %s
""" % (
AsIs(select_str),
Expand Down Expand Up @@ -457,7 +438,7 @@ def _check_groups_consistency(self):
)
group_list = ""
for group in access_records.mapped("group_id"):
group_list += " * {}\n".format(group.full_name)
group_list += f" * {group.full_name}\n"
msg_title = _(
'The model "%s" cannot be accessed by users with the selected groups only.'
) % (line_model.name,)
Expand Down
4 changes: 2 additions & 2 deletions bi_view_editor/models/bve_view_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ def _compute_name(self):
for line in self:
line.name = False
if line.field_id:
line.name = "x_bve_{}_{}".format(line.table_alias, line.field_id.name)
line.name = f"x_bve_{line.table_alias}_{line.field_id.name}"

@api.depends("field_id")
def _compute_model_field_name(self):
for line in self:
line.field_name = False
if line.field_id:
line.field_name = "{} ({})".format(line.description, line.model_name)
line.field_name = f"{line.description} ({line.model_name})"

def _prepare_field_vals(self):
vals_list = []
Expand Down
1 change: 0 additions & 1 deletion bi_view_editor/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def _bi_view(_name):


def _auto_init(self):

# This monkey patch is meant to fix an error (probably
# introduced by https://github.com/odoo/odoo/pull/15412), while
# running an update all. The _auto_init() method invoked during
Expand Down
3 changes: 3 additions & 0 deletions bi_view_editor/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
11 changes: 11 additions & 0 deletions bi_view_editor/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
- Simon Janssens \<<s.janssens@onestein.nl>\>
- Diego Luis Neto \<<diegoluis.neto@gmail.com>\>
- Dennis Sluijk \<<d.sluijk@onestein.nl>\>
- Kevin Graveman \<<k.graveman@onestein.nl>\>
- Richard Dijkstra \<<r.dijkstra@onestein.nl>\>
- Andrea Stirpe \<<a.stirpe@onestein.nl>\>
- Antonio Esposito \<<a.esposito@onestein.nl>\>
- Jordi Ballester Alomar \<<jordi.ballester@eficent.com>\>
- Italo LOPES \<<italo.lopes@camptocamp.com>\>
- [Coop IT Easy SC](https://coopiteasy.be):
- hugues de keyzer
Loading

0 comments on commit 4c00443

Please sign in to comment.