From 41df5fffb939f08afc538b4eee565f8b6203f48a Mon Sep 17 00:00:00 2001 From: chien Date: Tue, 19 Dec 2023 10:58:13 +0700 Subject: [PATCH] [IMP] bi_sql_editor: pre-commit auto fixes --- bi_sql_editor/README.rst | 156 ++++++++++++---------- bi_sql_editor/models/bi_sql_view.py | 23 +--- bi_sql_editor/models/bi_sql_view_field.py | 5 +- bi_sql_editor/pyproject.toml | 3 + bi_sql_editor/readme/CONFIGURE.md | 38 ++++++ bi_sql_editor/readme/CONFIGURE.rst | 42 ------ bi_sql_editor/readme/CONTRIBUTORS.md | 17 +++ bi_sql_editor/readme/CONTRIBUTORS.rst | 14 -- bi_sql_editor/readme/DESCRIPTION.md | 42 ++++++ bi_sql_editor/readme/DESCRIPTION.rst | 41 ------ bi_sql_editor/readme/USAGE.md | 8 ++ bi_sql_editor/readme/USAGE.rst | 10 -- 12 files changed, 197 insertions(+), 202 deletions(-) create mode 100644 bi_sql_editor/pyproject.toml create mode 100644 bi_sql_editor/readme/CONFIGURE.md delete mode 100644 bi_sql_editor/readme/CONFIGURE.rst create mode 100644 bi_sql_editor/readme/CONTRIBUTORS.md delete mode 100644 bi_sql_editor/readme/CONTRIBUTORS.rst create mode 100644 bi_sql_editor/readme/DESCRIPTION.md delete mode 100644 bi_sql_editor/readme/DESCRIPTION.rst create mode 100644 bi_sql_editor/readme/USAGE.md delete mode 100644 bi_sql_editor/readme/USAGE.rst diff --git a/bi_sql_editor/README.rst b/bi_sql_editor/README.rst index 5f4b5b13b..866ba4c29 100644 --- a/bi_sql_editor/README.rst +++ b/bi_sql_editor/README.rst @@ -17,58 +17,61 @@ BI SQL 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_sql_editor + :target: https://github.com/OCA/reporting-engine/tree/17.0/bi_sql_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_sql_editor + :target: https://translation.odoo-community.org/projects/reporting-engine-17-0/reporting-engine-17-0-bi_sql_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=17.0 :alt: Try me on Runboat |badge1| |badge2| |badge3| |badge4| |badge5| This module extends the functionality of reporting, to support creation -of extra custom reports. -It allows user to write a custom SQL request. (Generally, admin users) +of extra custom reports. It allows user to write a custom SQL request. +(Generally, admin users) -Once written, a new model is generated, and user can map the selected field -with odoo fields. -Then user ends the process, creating new menu, action and graph view. +Once written, a new model is generated, and user can map the selected +field with odoo fields. Then user ends the process, creating new menu, +action and graph view. -Technically, the module create SQL View (or materialized view, if option is -checked). Materialized view duplicates datas, but request are fastest. If -materialized view is enabled, this module will create a cron task to refresh -the data). +Technically, the module create SQL View (or materialized view, if option +is checked). Materialized view duplicates datas, but request are +fastest. If materialized view is enabled, this module will create a cron +task to refresh the data). By default, users member of 'SQL Request / User' can see all the views. -You can specify extra groups that have the right to access to a specific view. +You can specify extra groups that have the right to access to a specific +view. Warning ------- -This module is intended for technician people in a company and for Odoo integrators. +This module is intended for technician people in a company and for Odoo +integrators. It requires the user to know SQL syntax and Odoo models. -If you don't have such skills, do not try to use this module specially on a production -environment. +If you don't have such skills, do not try to use this module specially +on a production environment. Use Cases --------- this module is interesting for the following use cases -* You want to realize technical SQL requests, that Odoo framework doesn't allow - (For exemple, UNION with many SELECT) A typical use case is if you want to have - Sale Orders and PoS Orders datas in a same table - -* You want to customize an Odoo report, removing some useless fields and adding - some custom ones. In that case, you can simply select the fields of the original - report (sale.report model for exemple), and add your custom fields - -* You have a lot of data, and classical SQL Views have very bad performance. - In that case, MATERIALIZED VIEW will be a good solution to reduce display duration +- You want to realize technical SQL requests, that Odoo framework + doesn't allow (For exemple, UNION with many SELECT) A typical use + case is if you want to have Sale Orders and PoS Orders datas in a + same table +- You want to customize an Odoo report, removing some useless fields + and adding some custom ones. In that case, you can simply select the + fields of the original report (sale.report model for exemple), and + add your custom fields +- You have a lot of data, and classical SQL Views have very bad + performance. In that case, MATERIALIZED VIEW will be a good solution + to reduce display duration **Table of contents** @@ -78,17 +81,15 @@ this module is interesting for the following use cases Configuration ============= -* Go to Dashboard / Configuration / SQL Views +- Go to Dashboard / Configuration / SQL Views -* tip your SQL request +- tip your SQL request - .. figure:: https://raw.githubusercontent.com/OCA/reporting-engine/16.0/bi_sql_editor/static/description/01_sql_request.png - :width: 800 px + |image1| -* Select the group(s) that could have access to the view +- Select the group(s) that could have access to the view - .. figure:: https://raw.githubusercontent.com/OCA/reporting-engine/16.0/bi_sql_editor/static/description/02_security_access.png - :width: 800 px + |image2| Optionnaly, you can add a domain. @@ -96,44 +97,49 @@ A tipical domain in a multi company context is to write ``['|', ('company_id', '=', False), ('company_id', 'in', company_ids)]`` to make reporting depending on the current companies of the user. -* Click on the button 'Validate SQL Expression' +- Click on the button 'Validate SQL Expression' -* Once the sql request checked, the module analyses the column of the view, - and propose field mapping. For each field, you can decide to create an index - and set if it will be displayed on the pivot graph as a column, a row or a - measure. +- Once the sql request checked, the module analyses the column of the + view, and propose field mapping. For each field, you can decide to + create an index and set if it will be displayed on the pivot graph as + a column, a row or a measure. - .. figure:: https://raw.githubusercontent.com/OCA/reporting-engine/16.0/bi_sql_editor/static/description/03_field_mapping.png - :width: 800 px + |image3| -* Click on the button 'Create SQL elements'. (this step could - take a while, if view is materialized) +- Click on the button 'Create SQL elements'. (this step could take a + while, if view is materialized) -* If it's a MATERIALIZED view: +- If it's a MATERIALIZED view: - * a cron task is created to refresh - the view. You can so define the frequency of the refresh. - * the size of view (and the indexes is displayed) + - a cron task is created to refresh the view. You can so define + the frequency of the refresh. + - the size of view (and the indexes is displayed) - .. figure:: https://raw.githubusercontent.com/OCA/reporting-engine/16.0/bi_sql_editor/static/description/04_materialized_view_setting.png - :width: 800 px + |image4| -* Finally, click on 'Create UI', to create new menu, action, graph view and - search view. +- Finally, click on 'Create UI', to create new menu, action, graph view + and search view. + +.. |image1| image:: https://raw.githubusercontent.com/OCA/reporting-engine/17.0/bi_sql_editor/static/description/01_sql_request.png +.. |image2| image:: https://raw.githubusercontent.com/OCA/reporting-engine/17.0/bi_sql_editor/static/description/02_security_access.png +.. |image3| image:: https://raw.githubusercontent.com/OCA/reporting-engine/17.0/bi_sql_editor/static/description/03_field_mapping.png +.. |image4| image:: https://raw.githubusercontent.com/OCA/reporting-engine/17.0/bi_sql_editor/static/description/04_materialized_view_setting.png Usage ===== To use this module, you need to: -#. Go to 'Dashboards > SQL Reports' +1. Go to 'Dashboards > SQL Reports' +2. Select the desired report -#. Select the desired report +.. - .. figure:: https://raw.githubusercontent.com/OCA/reporting-engine/16.0/bi_sql_editor/static/description/05_reporting_pivot.png - :width: 800 px + |image1| -* You can switch to 'Graph' or 'tree' views as any report. +- You can switch to 'Graph' or 'tree' views as any report. + +.. |image1| image:: https://raw.githubusercontent.com/OCA/reporting-engine/17.0/bi_sql_editor/static/description/05_reporting_pivot.png Bug Tracker =========== @@ -141,7 +147,7 @@ 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 to smash it by providing a detailed and welcomed -`feedback `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -149,30 +155,34 @@ Credits ======= Authors -~~~~~~~ +------- * GRAP Contributors -~~~~~~~~~~~~ +------------ -* Sylvain LE GAL (https://twitter.com/legalsylvain) -* Richard deMeester, WilldooIT (http://www.willdooit.com/) -* David James, WilldooIT (http://www.willdooit.com/) +- Sylvain LE GAL (https://twitter.com/legalsylvain) -* This module is highly inspired by the work of - * Onestein: (http://www.onestein.nl/) - Module: OCA/server-tools/bi_view_editor. - Link: https://github.com/OCA/reporting-engine/tree/9.0/bi_view_editor - * Anybox: (https://anybox.fr/) - Module : OCA/server-tools/materialized_sql_view - link: https://github.com/OCA/server-tools/pull/110 - * GRAP, Groupement Régional Alimentaire de Proximité: (http://www.grap.coop/) - Module: grap/odoo-addons-misc/pos_sale_reporting - link: https://github.com/grap/odoo-addons-misc/tree/7.0/pos_sale_reporting +- Richard deMeester, WilldooIT (http://www.willdooit.com/) + +- David James, WilldooIT (http://www.willdooit.com/) + +- This module is highly inspired by the work of + + - Onestein: (http://www.onestein.nl/) Module: + OCA/server-tools/bi_view_editor. Link: + https://github.com/OCA/reporting-engine/tree/9.0/bi_view_editor + - Anybox: (https://anybox.fr/) Module : + OCA/server-tools/materialized_sql_view link: + https://github.com/OCA/server-tools/pull/110 + - GRAP, Groupement Régional Alimentaire de Proximité: + (http://www.grap.coop/) Module: + grap/odoo-addons-misc/pos_sale_reporting link: + https://github.com/grap/odoo-addons-misc/tree/7.0/pos_sale_reporting Maintainers -~~~~~~~~~~~ +----------- This module is maintained by the OCA. @@ -192,6 +202,6 @@ Current `maintainer `__: |maintainer-legalsylvain| -This module is part of the `OCA/reporting-engine `_ project on GitHub. +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/bi_sql_editor/models/bi_sql_view.py b/bi_sql_editor/models/bi_sql_view.py index 53026da22..d13eaf659 100644 --- a/bi_sql_editor/models/bi_sql_view.py +++ b/bi_sql_editor/models/bi_sql_view.py @@ -235,18 +235,12 @@ class BiSQLView(models.Model): @api.depends("technical_name") def _compute_view_name(self): for sql_view in self: - sql_view.view_name = "{}{}".format( - sql_view._sql_prefix, - sql_view.technical_name, - ) + sql_view.view_name = f"{sql_view._sql_prefix}{sql_view.technical_name}" @api.depends("technical_name") def _compute_model_name(self): for sql_view in self: - sql_view.model_name = "{}{}".format( - sql_view._model_prefix, - sql_view.technical_name, - ) + sql_view.model_name = f"{sql_view._model_prefix}{sql_view.technical_name}" # Overload Section def write(self, vals): @@ -607,7 +601,7 @@ class BiSQLView(models.Model): def _prepare_request_check_execution(self): self.ensure_one() - return "CREATE VIEW {} AS ({});".format(self.view_name, self.query) + return f"CREATE VIEW {self.view_name} AS ({self.query});" def _prepare_request_for_execution(self): self.ensure_one() @@ -625,11 +619,7 @@ class BiSQLView(models.Model): """ % self.query ) - return "CREATE {} VIEW {} AS ({});".format( - self.materialized_text, - self.view_name, - query, - ) + return f"CREATE {self.materialized_text} VIEW {self.view_name} AS ({query});" def _check_execution(self): """Ensure that the query is valid, trying to execute it. @@ -686,10 +676,7 @@ class BiSQLView(models.Model): def _refresh_materialized_view(self): for sql_view in self.filtered(lambda x: x.is_materialized): - req = "REFRESH {} VIEW {}".format( - sql_view.materialized_text, - sql_view.view_name, - ) + req = f"REFRESH {sql_view.materialized_text} VIEW {sql_view.view_name}" self._log_execute(req) sql_view._refresh_size() if sql_view.action_id: diff --git a/bi_sql_editor/models/bi_sql_view_field.py b/bi_sql_editor/models/bi_sql_view_field.py index 2a89e291f..676f17fd1 100644 --- a/bi_sql_editor/models/bi_sql_view_field.py +++ b/bi_sql_editor/models/bi_sql_view_field.py @@ -261,10 +261,7 @@ class BiSQLViewField(models.Model): def _prepare_search_field(self): self.ensure_one() - return """\n""".format( - self.name, - self.field_context, - ) + return f"""\n""" def _prepare_search_filter_field(self): self.ensure_one() diff --git a/bi_sql_editor/pyproject.toml b/bi_sql_editor/pyproject.toml new file mode 100644 index 000000000..4231d0ccc --- /dev/null +++ b/bi_sql_editor/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/bi_sql_editor/readme/CONFIGURE.md b/bi_sql_editor/readme/CONFIGURE.md new file mode 100644 index 000000000..5b392945a --- /dev/null +++ b/bi_sql_editor/readme/CONFIGURE.md @@ -0,0 +1,38 @@ +- Go to Dashboard / Configuration / SQL Views + +- tip your SQL request + + ![](../static/description/01_sql_request.png) + +- Select the group(s) that could have access to the view + + ![](../static/description/02_security_access.png) + +Optionnaly, you can add a domain. + +A tipical domain in a multi company context is to write +`['|', ('company_id', '=', False), ('company_id', 'in', company_ids)]` +to make reporting depending on the current companies of the user. + +- Click on the button 'Validate SQL Expression' + +- Once the sql request checked, the module analyses the column of the + view, and propose field mapping. For each field, you can decide to + create an index and set if it will be displayed on the pivot graph as + a column, a row or a measure. + + ![](../static/description/03_field_mapping.png) + +- Click on the button 'Create SQL elements'. (this step could take a + while, if view is materialized) + +- If it's a MATERIALIZED view: + + > - a cron task is created to refresh the view. You can so define the + > frequency of the refresh. + > - the size of view (and the indexes is displayed) + + ![](../static/description/04_materialized_view_setting.png) + +- Finally, click on 'Create UI', to create new menu, action, graph view + and search view. diff --git a/bi_sql_editor/readme/CONFIGURE.rst b/bi_sql_editor/readme/CONFIGURE.rst deleted file mode 100644 index 8d4492eaa..000000000 --- a/bi_sql_editor/readme/CONFIGURE.rst +++ /dev/null @@ -1,42 +0,0 @@ -* Go to Dashboard / Configuration / SQL Views - -* tip your SQL request - - .. figure:: ../static/description/01_sql_request.png - :width: 800 px - -* Select the group(s) that could have access to the view - - .. figure:: ../static/description/02_security_access.png - :width: 800 px - -Optionnaly, you can add a domain. - -A tipical domain in a multi company context is to write -``['|', ('company_id', '=', False), ('company_id', 'in', company_ids)]`` -to make reporting depending on the current companies of the user. - -* Click on the button 'Validate SQL Expression' - -* Once the sql request checked, the module analyses the column of the view, - and propose field mapping. For each field, you can decide to create an index - and set if it will be displayed on the pivot graph as a column, a row or a - measure. - - .. figure:: ../static/description/03_field_mapping.png - :width: 800 px - -* Click on the button 'Create SQL elements'. (this step could - take a while, if view is materialized) - -* If it's a MATERIALIZED view: - - * a cron task is created to refresh - the view. You can so define the frequency of the refresh. - * the size of view (and the indexes is displayed) - - .. figure:: ../static/description/04_materialized_view_setting.png - :width: 800 px - -* Finally, click on 'Create UI', to create new menu, action, graph view and - search view. diff --git a/bi_sql_editor/readme/CONTRIBUTORS.md b/bi_sql_editor/readme/CONTRIBUTORS.md new file mode 100644 index 000000000..3999e458c --- /dev/null +++ b/bi_sql_editor/readme/CONTRIBUTORS.md @@ -0,0 +1,17 @@ +- Sylvain LE GAL () + +- Richard deMeester, WilldooIT () + +- David James, WilldooIT () + +- This module is highly inspired by the work of + - Onestein: () Module: + OCA/server-tools/bi_view_editor. Link: + + - Anybox: () Module : + OCA/server-tools/materialized_sql_view link: + + - GRAP, Groupement Régional Alimentaire de Proximité: + () Module: + grap/odoo-addons-misc/pos_sale_reporting link: + diff --git a/bi_sql_editor/readme/CONTRIBUTORS.rst b/bi_sql_editor/readme/CONTRIBUTORS.rst deleted file mode 100644 index 1b4d1c030..000000000 --- a/bi_sql_editor/readme/CONTRIBUTORS.rst +++ /dev/null @@ -1,14 +0,0 @@ -* Sylvain LE GAL (https://twitter.com/legalsylvain) -* Richard deMeester, WilldooIT (http://www.willdooit.com/) -* David James, WilldooIT (http://www.willdooit.com/) - -* This module is highly inspired by the work of - * Onestein: (http://www.onestein.nl/) - Module: OCA/server-tools/bi_view_editor. - Link: https://github.com/OCA/reporting-engine/tree/9.0/bi_view_editor - * Anybox: (https://anybox.fr/) - Module : OCA/server-tools/materialized_sql_view - link: https://github.com/OCA/server-tools/pull/110 - * GRAP, Groupement Régional Alimentaire de Proximité: (http://www.grap.coop/) - Module: grap/odoo-addons-misc/pos_sale_reporting - link: https://github.com/grap/odoo-addons-misc/tree/7.0/pos_sale_reporting diff --git a/bi_sql_editor/readme/DESCRIPTION.md b/bi_sql_editor/readme/DESCRIPTION.md new file mode 100644 index 000000000..e5245f76b --- /dev/null +++ b/bi_sql_editor/readme/DESCRIPTION.md @@ -0,0 +1,42 @@ +This module extends the functionality of reporting, to support creation +of extra custom reports. It allows user to write a custom SQL request. +(Generally, admin users) + +Once written, a new model is generated, and user can map the selected +field with odoo fields. Then user ends the process, creating new menu, +action and graph view. + +Technically, the module create SQL View (or materialized view, if option +is checked). Materialized view duplicates datas, but request are +fastest. If materialized view is enabled, this module will create a cron +task to refresh the data). + +By default, users member of 'SQL Request / User' can see all the views. +You can specify extra groups that have the right to access to a specific +view. + +## Warning + +This module is intended for technician people in a company and for Odoo +integrators. + +It requires the user to know SQL syntax and Odoo models. + +If you don't have such skills, do not try to use this module specially +on a production environment. + +## Use Cases + +this module is interesting for the following use cases + +- You want to realize technical SQL requests, that Odoo framework + doesn't allow (For exemple, UNION with many SELECT) A typical use case + is if you want to have Sale Orders and PoS Orders datas in a same + table +- You want to customize an Odoo report, removing some useless fields and + adding some custom ones. In that case, you can simply select the + fields of the original report (sale.report model for exemple), and add + your custom fields +- You have a lot of data, and classical SQL Views have very bad + performance. In that case, MATERIALIZED VIEW will be a good solution + to reduce display duration diff --git a/bi_sql_editor/readme/DESCRIPTION.rst b/bi_sql_editor/readme/DESCRIPTION.rst deleted file mode 100644 index d232d115a..000000000 --- a/bi_sql_editor/readme/DESCRIPTION.rst +++ /dev/null @@ -1,41 +0,0 @@ -This module extends the functionality of reporting, to support creation -of extra custom reports. -It allows user to write a custom SQL request. (Generally, admin users) - -Once written, a new model is generated, and user can map the selected field -with odoo fields. -Then user ends the process, creating new menu, action and graph view. - -Technically, the module create SQL View (or materialized view, if option is -checked). Materialized view duplicates datas, but request are fastest. If -materialized view is enabled, this module will create a cron task to refresh -the data). - -By default, users member of 'SQL Request / User' can see all the views. -You can specify extra groups that have the right to access to a specific view. - -Warning -------- - -This module is intended for technician people in a company and for Odoo integrators. - -It requires the user to know SQL syntax and Odoo models. - -If you don't have such skills, do not try to use this module specially on a production -environment. - -Use Cases ---------- - -this module is interesting for the following use cases - -* You want to realize technical SQL requests, that Odoo framework doesn't allow - (For exemple, UNION with many SELECT) A typical use case is if you want to have - Sale Orders and PoS Orders datas in a same table - -* You want to customize an Odoo report, removing some useless fields and adding - some custom ones. In that case, you can simply select the fields of the original - report (sale.report model for exemple), and add your custom fields - -* You have a lot of data, and classical SQL Views have very bad performance. - In that case, MATERIALIZED VIEW will be a good solution to reduce display duration diff --git a/bi_sql_editor/readme/USAGE.md b/bi_sql_editor/readme/USAGE.md new file mode 100644 index 000000000..1d3742de5 --- /dev/null +++ b/bi_sql_editor/readme/USAGE.md @@ -0,0 +1,8 @@ +To use this module, you need to: + +1. Go to 'Dashboards \> SQL Reports' +2. Select the desired report + +> ![](../static/description/05_reporting_pivot.png) + +- You can switch to 'Graph' or 'tree' views as any report. diff --git a/bi_sql_editor/readme/USAGE.rst b/bi_sql_editor/readme/USAGE.rst deleted file mode 100644 index 7e19c0efc..000000000 --- a/bi_sql_editor/readme/USAGE.rst +++ /dev/null @@ -1,10 +0,0 @@ -To use this module, you need to: - -#. Go to 'Dashboards > SQL Reports' - -#. Select the desired report - - .. figure:: ../static/description/05_reporting_pivot.png - :width: 800 px - -* You can switch to 'Graph' or 'tree' views as any report.