diff --git a/report_context/README.rst b/report_context/README.rst new file mode 100644 index 0000000000..f1110ed146 --- /dev/null +++ b/report_context/README.rst @@ -0,0 +1,106 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +============== +Report Context +============== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:7f52c9aef799adcdfe67305cc20160ae2fc57ddc8f6c3d1b19aba647d5008c12 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/license-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/19.0/report_context + :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-19-0/reporting-engine-19-0-report_context + :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=19.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module adds a context variable to reports. A possible use for this +context could be hiding some fields or many other configuration options. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +To configure this module, you need to: + +- Enter Odoo in debug mode. +- To add a specific context to a report, you should go to Settings -> + Reports -> Reporting and look for the report you want to edit on the + list. You will see that now they contain a new field called Context + Value , where you will be able to add all the desired context + parameters. +- Go to Settings -> Parameters -> System Parameters. On the system + parameters list, look for report.default.context, which is a Python + dictionary variable where you can add a context that will be common + for all reports. + +It can also be added on the developer side using: + +:: + + + YOUR CONTEXT HERE + + +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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Creu Blanca + +Contributors +------------ + +- Jaime Arroyo +- Do Anh Duy + +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/report_context/__init__.py b/report_context/__init__.py new file mode 100644 index 0000000000..91c5580fed --- /dev/null +++ b/report_context/__init__.py @@ -0,0 +1,2 @@ +from . import controllers +from . import models diff --git a/report_context/__manifest__.py b/report_context/__manifest__.py new file mode 100644 index 0000000000..5c847cfaf3 --- /dev/null +++ b/report_context/__manifest__.py @@ -0,0 +1,14 @@ +# Copyright 2019 Creu Blanca +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Report Context", + "summary": """ + Adding context to reports""", + "version": "19.0.1.0.0", + "license": "AGPL-3", + "author": "Creu Blanca,Odoo Community Association (OCA)", + "website": "https://github.com/OCA/reporting-engine", + "depends": ["web"], + "data": ["views/ir_actions_report.xml", "data/config_parameter.xml"], +} diff --git a/report_context/controllers/__init__.py b/report_context/controllers/__init__.py new file mode 100644 index 0000000000..12a7e529b6 --- /dev/null +++ b/report_context/controllers/__init__.py @@ -0,0 +1 @@ +from . import main diff --git a/report_context/controllers/main.py b/report_context/controllers/main.py new file mode 100644 index 0000000000..700058d7d0 --- /dev/null +++ b/report_context/controllers/main.py @@ -0,0 +1,20 @@ +# Copyright 2019 Creu Blanca +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +import json + +from odoo.http import request, route + +from odoo.addons.web.controllers import report as report + + +class ReportController(report.ReportController): + @route() + def report_routes(self, reportname, docids=None, converter=None, **data): + report = request.env["ir.actions.report"]._get_report_from_name(reportname) + original_context = json.loads(data.get("context", "{}") or "{}") + data["context"] = json.dumps( + report.with_context(**original_context)._get_context() + ) + return super().report_routes( + reportname=reportname, docids=docids, converter=converter, **data + ) diff --git a/report_context/data/config_parameter.xml b/report_context/data/config_parameter.xml new file mode 100644 index 0000000000..5c75c1cf12 --- /dev/null +++ b/report_context/data/config_parameter.xml @@ -0,0 +1,7 @@ + + + + report.default.context + {} + + diff --git a/report_context/i18n/es.po b/report_context/i18n/es.po new file mode 100644 index 0000000000..b4b1ebd774 --- /dev/null +++ b/report_context/i18n/es.po @@ -0,0 +1,35 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * report_context +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-04-22 22:43+0000\n" +"Last-Translator: Ivorra78 \n" +"Language-Team: none\n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: report_context +#: model:ir.model.fields,field_description:report_context.field_ir_actions_report__context +msgid "Context Value" +msgstr "Valor de Contexto" + +#. module: report_context +#: model:ir.model.fields,help:report_context.field_ir_actions_report__context +msgid "" +"Context dictionary as Python expression, empty by default (Default: {})" +msgstr "" +"Diccionario de contexto como expresión Python, vacío por defecto (Por " +"defecto: {})" + +#. module: report_context +#: model:ir.model,name:report_context.model_ir_actions_report +msgid "Report Action" +msgstr "Informar Acción" diff --git a/report_context/i18n/it.po b/report_context/i18n/it.po new file mode 100644 index 0000000000..9ea68687ff --- /dev/null +++ b/report_context/i18n/it.po @@ -0,0 +1,35 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * report_context +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-01-15 09:37+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: report_context +#: model:ir.model.fields,field_description:report_context.field_ir_actions_report__context +msgid "Context Value" +msgstr "Valore context" + +#. module: report_context +#: model:ir.model.fields,help:report_context.field_ir_actions_report__context +msgid "" +"Context dictionary as Python expression, empty by default (Default: {})" +msgstr "" +"Dizionario context come espressione Python, predefinito come vuoto (Default: " +"{})" + +#. module: report_context +#: model:ir.model,name:report_context.model_ir_actions_report +msgid "Report Action" +msgstr "Azione resoconto" diff --git a/report_context/i18n/report_context.pot b/report_context/i18n/report_context.pot new file mode 100644 index 0000000000..72fd041293 --- /dev/null +++ b/report_context/i18n/report_context.pot @@ -0,0 +1,30 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * report_context +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 18.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: report_context +#: model:ir.model.fields,field_description:report_context.field_ir_actions_report__context +msgid "Context Value" +msgstr "" + +#. module: report_context +#: model:ir.model.fields,help:report_context.field_ir_actions_report__context +msgid "" +"Context dictionary as Python expression, empty by default (Default: {})" +msgstr "" + +#. module: report_context +#: model:ir.model,name:report_context.model_ir_actions_report +msgid "Report Action" +msgstr "" diff --git a/report_context/models/__init__.py b/report_context/models/__init__.py new file mode 100644 index 0000000000..a248cf2162 --- /dev/null +++ b/report_context/models/__init__.py @@ -0,0 +1 @@ +from . import ir_actions_report diff --git a/report_context/models/ir_actions_report.py b/report_context/models/ir_actions_report.py new file mode 100644 index 0000000000..1b70bc40f2 --- /dev/null +++ b/report_context/models/ir_actions_report.py @@ -0,0 +1,38 @@ +# Copyright 2019 Creu Blanca +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from odoo import fields, models +from odoo.tools.safe_eval import safe_eval + + +class IrActionsReport(models.Model): + _inherit = "ir.actions.report" + + context = fields.Char( + string="Context Value", + default={}, + required=True, + help="Context dictionary as Python expression, empty by default (Default: {})", + ) + + def _get_context(self): + context = ( + self.env["ir.config_parameter"] + .sudo() + .get_param("report.default.context", "{}") + ) + # We must transform it to a dictionary + context = safe_eval(context or "{}") + report_context = safe_eval(self.context or "{}") + context.update(report_context) + context.update(self.env.context) + return context + + def _render(self, report_ref, res_ids, data=None): + return super(IrActionsReport, self.with_context(**self._get_context()))._render( + report_ref=report_ref, res_ids=res_ids, data=data + ) + + def report_action(self, docids, data=None, config=True): + return super( + IrActionsReport, self.with_context(**self._get_context()) + ).report_action(docids=docids, data=data, config=config) diff --git a/report_context/pyproject.toml b/report_context/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/report_context/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/report_context/readme/CONTRIBUTORS.md b/report_context/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..a438b26241 --- /dev/null +++ b/report_context/readme/CONTRIBUTORS.md @@ -0,0 +1,2 @@ +- Jaime Arroyo \<\> +- Do Anh Duy \<\> diff --git a/report_context/readme/DESCRIPTION.md b/report_context/readme/DESCRIPTION.md new file mode 100644 index 0000000000..f3306e2d22 --- /dev/null +++ b/report_context/readme/DESCRIPTION.md @@ -0,0 +1,2 @@ +This module adds a context variable to reports. A possible use for this +context could be hiding some fields or many other configuration options. diff --git a/report_context/readme/USAGE.md b/report_context/readme/USAGE.md new file mode 100644 index 0000000000..857cf6dd91 --- /dev/null +++ b/report_context/readme/USAGE.md @@ -0,0 +1,18 @@ +To configure this module, you need to: + +- Enter Odoo in debug mode. +- To add a specific context to a report, you should go to Settings -\> + Reports -\> Reporting and look for the report you want to edit on the + list. You will see that now they contain a new field called Context + Value , where you will be able to add all the desired context + parameters. +- Go to Settings -\> Parameters -\> System Parameters. On the system + parameters list, look for report.default.context, which is a Python + dictionary variable where you can add a context that will be common + for all reports. + +It can also be added on the developer side using: + + + YOUR CONTEXT HERE + diff --git a/report_context/static/description/icon.png b/report_context/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/report_context/static/description/icon.png differ diff --git a/report_context/static/description/index.html b/report_context/static/description/index.html new file mode 100644 index 0000000000..731fda01c0 --- /dev/null +++ b/report_context/static/description/index.html @@ -0,0 +1,454 @@ + + + + + +README.rst + + + +
+ + + +Odoo Community Association + +
+

Report Context

+ +

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

+

This module adds a context variable to reports. A possible use for this +context could be hiding some fields or many other configuration options.

+

Table of contents

+ +
+

Usage

+

To configure this module, you need to:

+
    +
  • Enter Odoo in debug mode.
  • +
  • To add a specific context to a report, you should go to Settings -> +Reports -> Reporting and look for the report you want to edit on the +list. You will see that now they contain a new field called Context +Value , where you will be able to add all the desired context +parameters.
  • +
  • Go to Settings -> Parameters -> System Parameters. On the system +parameters list, look for report.default.context, which is a Python +dictionary variable where you can add a context that will be common +for all reports.
  • +
+

It can also be added on the developer side using:

+
+<record id="model_name.report_id" model="ir.actions.report">
+    <field name="context">YOUR CONTEXT HERE</field>
+</record>
+
+
+
+

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.

+

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/report_context/tests/__init__.py b/report_context/tests/__init__.py new file mode 100644 index 0000000000..c72cd7abdf --- /dev/null +++ b/report_context/tests/__init__.py @@ -0,0 +1 @@ +from . import test_report_context diff --git a/report_context/tests/test_report_context.py b/report_context/tests/test_report_context.py new file mode 100644 index 0000000000..99bf8781c2 --- /dev/null +++ b/report_context/tests/test_report_context.py @@ -0,0 +1,60 @@ +# Copyright 2019 Creu Blanca +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from odoo.tests.common import TransactionCase + + +class TestReportContext(TransactionCase): + def test_report_01(self): + company = self.browse_ref("base.main_company") + report = self.browse_ref("web.action_report_internalpreview") + self.env["ir.config_parameter"].sudo().set_param( + "report.default.context", '{"test_parameter": 1}' + ) + report.write({"context": '{"test_parameter": 2}'}) + action = report.with_context(test_parameter=3).report_action(company) + self.assertEqual( + 3, action["context"]["report_action"]["context"]["test_parameter"] + ) + + def test_report_02(self): + company = self.browse_ref("base.main_company") + report = self.browse_ref("web.action_report_internalpreview") + self.env["ir.config_parameter"].sudo().set_param( + "report.default.context", '{"test_parameter": 1}' + ) + report.write({"context": '{"test_parameter": 2}'}) + action = report.report_action(company) + self.assertEqual( + 2, action["context"]["report_action"]["context"]["test_parameter"] + ) + + def test_report_03(self): + company = self.browse_ref("base.main_company") + report = self.browse_ref("web.action_report_internalpreview") + self.env["ir.config_parameter"].sudo().set_param( + "report.default.context", '{"test_parameter": 1}' + ) + action = report.with_context(test_parameter=3).report_action(company) + self.assertEqual( + 3, action["context"]["report_action"]["context"]["test_parameter"] + ) + + def test_report_04(self): + company = self.browse_ref("base.main_company") + report = self.browse_ref("web.action_report_internalpreview") + report.write({"context": '{"test_parameter": 2}'}) + action = report.report_action(company) + self.assertEqual( + 2, action["context"]["report_action"]["context"]["test_parameter"] + ) + + def test_report_05(self): + company = self.browse_ref("base.main_company") + report = self.browse_ref("web.action_report_internalpreview") + self.env["ir.config_parameter"].sudo().set_param( + "report.default.context", '{"test_parameter": 1}' + ) + action = report.report_action(company) + self.assertEqual( + 1, action["context"]["report_action"]["context"]["test_parameter"] + ) diff --git a/report_context/views/ir_actions_report.xml b/report_context/views/ir_actions_report.xml new file mode 100644 index 0000000000..8fdc8b7208 --- /dev/null +++ b/report_context/views/ir_actions_report.xml @@ -0,0 +1,15 @@ + + + + + ir.actions.report.context.form + ir.actions.report + + + + + + + +