Skip to content

Commit a959d9c

Browse files
committed
Merge PR #783 into 16.0
Signed-off-by gurneyalex
2 parents 79d6736 + 717f79a commit a959d9c

File tree

19 files changed

+773
-0
lines changed

19 files changed

+773
-0
lines changed

report_context/README.rst

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
==============
2+
Report Context
3+
==============
4+
5+
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6+
!! This file is generated by oca-gen-addon-readme !!
7+
!! changes will be overwritten. !!
8+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
9+
10+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
11+
:target: https://odoo-community.org/page/development-status
12+
:alt: Beta
13+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
14+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
15+
:alt: License: AGPL-3
16+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Freporting--engine-lightgray.png?logo=github
17+
:target: https://github.com/OCA/reporting-engine/tree/14.0/report_context
18+
:alt: OCA/reporting-engine
19+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
20+
:target: https://translation.odoo-community.org/projects/reporting-engine-14-0/reporting-engine-14-0-report_context
21+
:alt: Translate me on Weblate
22+
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
23+
:target: https://runbot.odoo-community.org/runbot/143/14.0
24+
:alt: Try me on Runbot
25+
26+
|badge1| |badge2| |badge3| |badge4| |badge5|
27+
28+
This module adds a context variable to reports. A possible use for this
29+
context could be hiding some fields or many other configuration options.
30+
31+
**Table of contents**
32+
33+
.. contents::
34+
:local:
35+
36+
Usage
37+
=====
38+
39+
To configure this module, you need to:
40+
41+
* Enter Odoo in debug mode.
42+
* To add a specific context to a report, you should go to Settings ->
43+
Reports -> Reporting and look for the report you want to edit on the
44+
list. You will see that now they contain a new field called Context Value
45+
, where you will be able to add all the desired context parameters.
46+
* Go to Settings -> Parameters -> System Parameters. On the system
47+
parameters list, look for report.default.context, which is a Python
48+
dictionary variable where you can add a context that will be common for
49+
all reports.
50+
51+
It can also be added on the developer side using::
52+
53+
<record id="model_name.report_id" model="ir.actions.report">
54+
<field name="context">YOUR CONTEXT HERE</field>
55+
</record>
56+
57+
Bug Tracker
58+
===========
59+
60+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/reporting-engine/issues>`_.
61+
In case of trouble, please check there if your issue has already been reported.
62+
If you spotted it first, help us smashing it by providing a detailed and welcomed
63+
`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**>`_.
64+
65+
Do not contact contributors directly about support or help with technical issues.
66+
67+
Credits
68+
=======
69+
70+
Authors
71+
~~~~~~~
72+
73+
* Creu Blanca
74+
75+
Contributors
76+
~~~~~~~~~~~~
77+
78+
* Jaime Arroyo <[email protected]>
79+
80+
Maintainers
81+
~~~~~~~~~~~
82+
83+
This module is maintained by the OCA.
84+
85+
.. image:: https://odoo-community.org/logo.png
86+
:alt: Odoo Community Association
87+
:target: https://odoo-community.org
88+
89+
OCA, or the Odoo Community Association, is a nonprofit organization whose
90+
mission is to support the collaborative development of Odoo features and
91+
promote its widespread use.
92+
93+
This module is part of the `OCA/reporting-engine <https://github.com/OCA/reporting-engine/tree/14.0/report_context>`_ project on GitHub.
94+
95+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

report_context/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from . import controllers
2+
from . import models

report_context/__manifest__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright 2019 Creu Blanca
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3+
4+
{
5+
"name": "Report Context",
6+
"summary": """
7+
Adding context to reports""",
8+
"version": "16.0.1.0.0",
9+
"license": "AGPL-3",
10+
"author": "Creu Blanca,Odoo Community Association (OCA)",
11+
"website": "https://github.com/OCA/reporting-engine",
12+
"depends": ["web"],
13+
"data": ["views/ir_actions_report.xml", "data/config_parameter.xml"],
14+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import main

report_context/controllers/main.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright 2019 Creu Blanca
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
3+
import json
4+
5+
from odoo.http import request, route
6+
7+
from odoo.addons.web.controllers import report as report
8+
9+
10+
class ReportController(report.ReportController):
11+
@route()
12+
def report_routes(self, reportname, docids=None, converter=None, **data):
13+
report = request.env["ir.actions.report"]._get_report_from_name(reportname)
14+
original_context = json.loads(data.get("context", "{}") or "{}")
15+
data["context"] = json.dumps(
16+
report.with_context(**original_context)._get_context()
17+
)
18+
return super().report_routes(
19+
reportname, docids=docids, converter=converter, **data
20+
)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<odoo noupdate="1">
3+
<record
4+
id="report_default_context"
5+
model="ir.config_parameter"
6+
forcecreate="True"
7+
>
8+
<field name="key">report.default.context</field>
9+
<field name="value">{}</field>
10+
</record>
11+
</odoo>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Translation of Odoo Server.
2+
# This file contains the translation of the following modules:
3+
# * report_context
4+
#
5+
msgid ""
6+
msgstr ""
7+
"Project-Id-Version: Odoo Server 14.0\n"
8+
"Report-Msgid-Bugs-To: \n"
9+
"Last-Translator: \n"
10+
"Language-Team: \n"
11+
"MIME-Version: 1.0\n"
12+
"Content-Type: text/plain; charset=UTF-8\n"
13+
"Content-Transfer-Encoding: \n"
14+
"Plural-Forms: \n"
15+
16+
#. module: report_context
17+
#: model:ir.model.fields,field_description:report_context.field_ir_actions_report__context
18+
msgid "Context Value"
19+
msgstr ""
20+
21+
#. module: report_context
22+
#: model:ir.model.fields,help:report_context.field_ir_actions_report__context
23+
msgid ""
24+
"Context dictionary as Python expression, empty by default (Default: {})"
25+
msgstr ""
26+
27+
#. module: report_context
28+
#: model:ir.model.fields,field_description:report_context.field_ir_actions_report__display_name
29+
msgid "Display Name"
30+
msgstr ""
31+
32+
#. module: report_context
33+
#: model:ir.model.fields,field_description:report_context.field_ir_actions_report__id
34+
msgid "ID"
35+
msgstr ""
36+
37+
#. module: report_context
38+
#: model:ir.model.fields,field_description:report_context.field_ir_actions_report____last_update
39+
msgid "Last Modified on"
40+
msgstr ""
41+
42+
#. module: report_context
43+
#: model:ir.model,name:report_context.model_ir_actions_report
44+
msgid "Report Action"
45+
msgstr ""

report_context/models/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import ir_actions_report
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Copyright 2019 Creu Blanca
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3+
from odoo import fields, models
4+
from odoo.tools.safe_eval import safe_eval
5+
6+
7+
class IrActionsReport(models.Model):
8+
_inherit = "ir.actions.report"
9+
10+
context = fields.Char(
11+
string="Context Value",
12+
default={},
13+
required=True,
14+
help="Context dictionary as Python expression, empty by default "
15+
"(Default: {})",
16+
)
17+
18+
def _get_context(self):
19+
context = (
20+
self.env["ir.config_parameter"]
21+
.sudo()
22+
.get_param("report.default.context", "{}")
23+
)
24+
# We must transform it to a dictionary
25+
context = safe_eval(context or "{}")
26+
report_context = safe_eval(self.context or "{}")
27+
context.update(report_context)
28+
context.update(self.env.context)
29+
return context
30+
31+
def _render(self, report_ref, res_ids, data=None):
32+
return super(IrActionsReport, self.with_context(**self._get_context()))._render(
33+
report_ref, res_ids, data=data
34+
)
35+
36+
def report_action(self, docids, data=None, config=True):
37+
return super(
38+
IrActionsReport, self.with_context(**self._get_context())
39+
).report_action(docids, data=data, config=config)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* Jaime Arroyo <[email protected]>

0 commit comments

Comments
 (0)