-
-
Notifications
You must be signed in to change notification settings - Fork 796
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by gurneyalex
- Loading branch information
Showing
19 changed files
with
773 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
============== | ||
Report Context | ||
============== | ||
|
||
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |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/licence-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/14.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-14-0/reporting-engine-14-0-report_context | ||
:alt: Translate me on Weblate | ||
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png | ||
:target: https://runbot.odoo-community.org/runbot/143/14.0 | ||
:alt: Try me on Runbot | ||
|
||
|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:: | ||
|
||
<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 <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 smashing it by providing a detailed and welcomed | ||
`feedback <https://github.com/OCA/reporting-engine/issues/new?body=module:%20report_context%0Aversion:%2014.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 | ||
~~~~~~~ | ||
|
||
* Creu Blanca | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
* Jaime Arroyo <[email protected]> | ||
|
||
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 <https://github.com/OCA/reporting-engine/tree/14.0/report_context>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import controllers | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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": "16.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"], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, docids=docids, converter=converter, **data | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<odoo noupdate="1"> | ||
<record | ||
id="report_default_context" | ||
model="ir.config_parameter" | ||
forcecreate="True" | ||
> | ||
<field name="key">report.default.context</field> | ||
<field name="value">{}</field> | ||
</record> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * report_context | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 14.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.fields,field_description:report_context.field_ir_actions_report__display_name | ||
msgid "Display Name" | ||
msgstr "" | ||
|
||
#. module: report_context | ||
#: model:ir.model.fields,field_description:report_context.field_ir_actions_report__id | ||
msgid "ID" | ||
msgstr "" | ||
|
||
#. module: report_context | ||
#: model:ir.model.fields,field_description:report_context.field_ir_actions_report____last_update | ||
msgid "Last Modified on" | ||
msgstr "" | ||
|
||
#. module: report_context | ||
#: model:ir.model,name:report_context.model_ir_actions_report | ||
msgid "Report Action" | ||
msgstr "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import ir_actions_report |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# 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, 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, data=data, config=config) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* Jaime Arroyo <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
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> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.