diff --git a/report_substitute/__manifest__.py b/report_substitute/__manifest__.py
index 1dab69dc8..a34945e22 100644
--- a/report_substitute/__manifest__.py
+++ b/report_substitute/__manifest__.py
@@ -2,20 +2,19 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
- 'name': 'Report Substitute',
- 'summary': """
+ "name": "Report Substitute",
+ "summary": """
This module allows to create substitution rules for report actions.
""",
- 'version': '12.0.1.0.0',
- 'license': 'AGPL-3',
- 'author': 'ACSONE SA/NV,'
- 'Odoo Community Association (OCA)',
- 'website': 'https://github.com/OCA/reporting-engine',
- 'depends': ['base', 'mail'],
- 'data': [
- 'security/ir_actions_report_substitution_rule.xml',
- 'views/assets_backend.xml',
- 'views/ir_actions_report.xml',
+ "version": "13.0.1.0.0",
+ "license": "AGPL-3",
+ "author": "ACSONE SA/NV," "Odoo Community Association (OCA)",
+ "website": "https://github.com/OCA/reporting-engine",
+ "depends": ["base", "mail"],
+ "data": [
+ "security/ir_actions_report_substitution_rule.xml",
+ "views/assets_backend.xml",
+ "views/ir_actions_report.xml",
],
- 'demo': ['demo/action_report.xml'],
+ "demo": ["demo/action_report.xml"],
}
diff --git a/report_substitute/demo/action_report.xml b/report_substitute/demo/action_report.xml
index e3b85ba22..72d576585 100644
--- a/report_substitute/demo/action_report.xml
+++ b/report_substitute/demo/action_report.xml
@@ -1,29 +1,32 @@
-
+
Substitution Report
-
-
-
+
-
-
+
+
-
Substitution Report 2
-
-
+
diff --git a/report_substitute/models/ir_actions_report.py b/report_substitute/models/ir_actions_report.py
index a987b24f1..94895b716 100644
--- a/report_substitute/models/ir_actions_report.py
+++ b/report_substitute/models/ir_actions_report.py
@@ -7,7 +7,7 @@ from odoo.tools.safe_eval import safe_eval
class IrActionReport(models.Model):
- _inherit = 'ir.actions.report'
+ _inherit = "ir.actions.report"
action_report_substitution_rule_ids = fields.One2many(
comodel_name="ir.actions.report.substitution.rule",
@@ -15,20 +15,16 @@ class IrActionReport(models.Model):
string="Substitution Rules",
)
- @api.multi
def _get_substitution_report(self, model, active_ids):
self.ensure_one()
model = self.env[model]
- for (
- substitution_report_rule
- ) in self.action_report_substitution_rule_ids:
+ for substitution_report_rule in self.action_report_substitution_rule_ids:
domain = safe_eval(substitution_report_rule.domain)
- domain.append(('id', 'in', active_ids))
+ domain.append(("id", "in", active_ids))
if set(model.search(domain).ids) == set(active_ids):
return substitution_report_rule.substitution_action_report_id
return False
- @api.multi
def get_substitution_report(self, active_ids):
self.ensure_one()
action_report = self
@@ -42,8 +38,8 @@ class IrActionReport(models.Model):
@api.model
def get_substitution_report_action(self, action, active_ids):
- if action.get('id'):
- action_report = self.browse(action['id'])
+ if action.get("id"):
+ action_report = self.browse(action["id"])
substitution_report = action_report
while substitution_report:
action_report = substitution_report
@@ -53,12 +49,10 @@ class IrActionReport(models.Model):
action.update(action_report.read()[0])
return action
- @api.multi
def render(self, res_ids, data=None):
substitution_report = self.get_substitution_report(res_ids)
return super(IrActionReport, substitution_report).render(res_ids, data)
- @api.noguess
def report_action(self, docids, data=None, config=True):
if docids:
if isinstance(docids, models.Model):
diff --git a/report_substitute/models/ir_actions_report_substitution_rule.py b/report_substitute/models/ir_actions_report_substitution_rule.py
index 1f5d936fd..65f8f3fb1 100644
--- a/report_substitute/models/ir_actions_report_substitution_rule.py
+++ b/report_substitute/models/ir_actions_report_substitution_rule.py
@@ -1,15 +1,15 @@
# Copyright 2019 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-from odoo import fields, models, api, _
+from odoo import _, api, fields, models
from odoo.exceptions import ValidationError
class ActionsReportSubstitutionRule(models.Model):
- _name = 'ir.actions.report.substitution.rule'
- _description = 'Action Report Substitution Rule'
- _order = 'sequence ASC'
+ _name = "ir.actions.report.substitution.rule"
+ _description = "Action Report Substitution Rule"
+ _order = "sequence ASC"
sequence = fields.Integer(default=10)
action_report_id = fields.Many2one(
@@ -28,7 +28,7 @@ class ActionsReportSubstitutionRule(models.Model):
domain="[('model', '=', model)]",
)
- @api.constrains('substitution_action_report_id', 'action_report_id')
+ @api.constrains("substitution_action_report_id", "action_report_id")
def _check_substitution_infinite_loop(self):
def _check_infinite_loop(original_report, substitution_report):
if original_report == substitution_report:
@@ -37,8 +37,7 @@ class ActionsReportSubstitutionRule(models.Model):
substitution_rule
) in substitution_report.action_report_substitution_rule_ids:
_check_infinite_loop(
- original_report,
- substitution_rule.substitution_action_report_id,
+ original_report, substitution_rule.substitution_action_report_id,
)
for rec in self:
diff --git a/report_substitute/models/mail_thread.py b/report_substitute/models/mail_thread.py
index 7f1a236fd..35a86ee3c 100644
--- a/report_substitute/models/mail_thread.py
+++ b/report_substitute/models/mail_thread.py
@@ -1,23 +1,20 @@
# Copyright 2019 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-from odoo import api, models
+from odoo import models
class MailThread(models.AbstractModel):
- _inherit = 'mail.thread'
+ _inherit = "mail.thread"
- @api.multi
def message_post_with_template(self, template_id, **kwargs):
- template = self.env['mail.template'].browse(template_id)
+ template = self.env["mail.template"].browse(template_id)
old_report = False
if template and template.report_template and self.ids:
active_ids = self.ids
old_report = template.report_template
- template.report_template = old_report.get_substitution_report(
- active_ids
- )
+ template.report_template = old_report.get_substitution_report(active_ids)
res = super().message_post_with_template(template_id, **kwargs)
if old_report:
template.report_template = old_report
diff --git a/report_substitute/security/ir_actions_report_substitution_rule.xml b/report_substitute/security/ir_actions_report_substitution_rule.xml
index e7af09afd..cf06f95ff 100644
--- a/report_substitute/security/ir_actions_report_substitution_rule.xml
+++ b/report_substitute/security/ir_actions_report_substitution_rule.xml
@@ -1,25 +1,22 @@
-
+
-
-
action.report.substitution.rule user access
-
-
-
-
-
+
+
+
+
+
-
action.report.substitution.rule manager access
-
-
-
-
-
-
+
+
+
+
+
+
diff --git a/report_substitute/static/src/js/action_manager.js b/report_substitute/static/src/js/action_manager.js
index 6e4e8f8de..1c244bb48 100644
--- a/report_substitute/static/src/js/action_manager.js
+++ b/report_substitute/static/src/js/action_manager.js
@@ -1,39 +1,35 @@
// Copyright 2019 ACSONE SA/NV
// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-odoo.define("report_substitute.action_report_substitute", function (require) {
+odoo.define("report_substitute.action_report_substitute", function(require) {
"use strict";
var ActionManager = require("web.ActionManager");
ActionManager.include({
-
/**
* Intercept action handling substitute the report action
* @override
*/
- _handleAction: function (action, options) {
- if (action.type === "ir.actions.report" &&
+ _handleAction: function(action, options) {
+ if (
+ action.type === "ir.actions.report" &&
action.context.active_ids &&
action.action_report_substitution_rule_ids &&
- action.action_report_substitution_rule_ids != 0) {
+ action.action_report_substitution_rule_ids !== 0
+ ) {
var active_ids = action.context.active_ids;
var self = this;
var _super = this._super;
- var callersArguments = arguments;
return this._rpc({
model: "ir.actions.report",
method: "get_substitution_report_action",
- args: [action, active_ids]
- }).then(function (substitution_action) {
- callersArguments[0] = substitution_action
- return _super.apply(self, callersArguments);
+ args: [action, active_ids],
+ }).then(function(substitution_action) {
+ return _super.apply(self, [substitution_action, options]);
});
-
}
return this._super.apply(this, arguments);
},
-
});
-
-});
\ No newline at end of file
+});
diff --git a/report_substitute/tests/test_report_substitute.py b/report_substitute/tests/test_report_substitute.py
index 3a3d2fbd3..778853916 100644
--- a/report_substitute/tests/test_report_substitute.py
+++ b/report_substitute/tests/test_report_substitute.py
@@ -1,8 +1,8 @@
# Copyright 2019 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-from odoo.tests.common import TransactionCase
from odoo.exceptions import ValidationError
+from odoo.tests.common import TransactionCase
class TestReportSubstitute(TransactionCase):
@@ -10,11 +10,14 @@ class TestReportSubstitute(TransactionCase):
# In the demo file we create a new report for ir.module.module model
# with a substation rule from the original report action
super(TestReportSubstitute, self).setUp()
- self.action_report = self.env.ref('base.ir_module_reference_print')
- self.res_ids = self.env.ref('base.module_base').ids
+ self.action_report = self.env.ref("base.ir_module_reference_print")
+ self.res_ids = self.env.ref("base.module_base").ids
self.substitution_rule = self.env.ref(
- 'report_substitute.substitution_rule_demo_1'
+ "report_substitute.substitution_rule_demo_1"
)
+ self.env.company.external_report_layout_id = self.env.ref(
+ "web.external_layout_standard"
+ ).id
def test_substitution(self):
res = str(self.action_report.render(res_ids=self.res_ids)[0])
@@ -27,13 +30,13 @@ class TestReportSubstitute(TransactionCase):
def test_recursive_substitution(self):
res = str(self.action_report.render(res_ids=self.res_ids)[0])
self.assertNotIn('
Substitution Report 2
', res)
- self.env['ir.actions.report.substitution.rule'].create(
+ self.env["ir.actions.report.substitution.rule"].create(
{
- 'substitution_action_report_id': self.env.ref(
- 'report_substitute.substitution_report_print_2'
+ "substitution_action_report_id": self.env.ref(
+ "report_substitute.substitution_report_print_2"
).id,
- 'action_report_id': self.env.ref(
- 'report_substitute.substitution_report_print'
+ "action_report_id": self.env.ref(
+ "report_substitute.substitution_report_print"
).id,
}
)
@@ -41,40 +44,38 @@ class TestReportSubstitute(TransactionCase):
self.assertIn('Substitution Report 2
', res)
def test_substitution_with_domain(self):
- self.substitution_rule.write({'domain': "[('name', '=', 'base')]"})
+ self.substitution_rule.write({"domain": "[('name', '=', 'base')]"})
res = str(self.action_report.render(res_ids=self.res_ids)[0])
self.assertIn('Substitution Report
', res)
- self.substitution_rule.write({'domain': "[('name', '!=', 'base')]"})
+ self.substitution_rule.write({"domain": "[('name', '!=', 'base')]"})
res = str(self.action_report.render(res_ids=self.res_ids)[0])
self.assertNotIn('Substitution Report
', res)
def test_substitution_with_action_dict(self):
substitution_report_action = self.env[
- 'ir.actions.report'
- ].get_substitution_report_action(
- self.action_report.read()[0], self.res_ids
- )
+ "ir.actions.report"
+ ].get_substitution_report_action(self.action_report.read()[0], self.res_ids)
self.assertEqual(
- substitution_report_action['id'],
+ substitution_report_action["id"],
self.substitution_rule.substitution_action_report_id.id,
)
def test_substitution_with_report_action(self):
res = self.action_report.report_action(self.res_ids)
self.assertEqual(
- res['report_name'],
+ res["report_name"],
self.substitution_rule.substitution_action_report_id.report_name,
)
def test_substitution_infinite_loop(self):
with self.assertRaises(ValidationError):
- self.env['ir.actions.report.substitution.rule'].create(
+ self.env["ir.actions.report.substitution.rule"].create(
{
- 'action_report_id': self.env.ref(
- 'report_substitute.substitution_report_print'
+ "action_report_id": self.env.ref(
+ "report_substitute.substitution_report_print"
).id,
- 'substitution_action_report_id': self.env.ref(
- 'base.ir_module_reference_print'
+ "substitution_action_report_id": self.env.ref(
+ "base.ir_module_reference_print"
).id,
}
)
diff --git a/report_substitute/views/assets_backend.xml b/report_substitute/views/assets_backend.xml
index 4120d85f1..4fc56b88f 100644
--- a/report_substitute/views/assets_backend.xml
+++ b/report_substitute/views/assets_backend.xml
@@ -1,8 +1,11 @@
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
diff --git a/report_substitute/views/ir_actions_report.xml b/report_substitute/views/ir_actions_report.xml
index e8ab9991f..f51b87b94 100644
--- a/report_substitute/views/ir_actions_report.xml
+++ b/report_substitute/views/ir_actions_report.xml
@@ -1,35 +1,41 @@
-
+
-
-
ir.actions.report.form (in report_substitute)
ir.actions.report
-
+
-
-
-
+
+
+
@@ -38,6 +44,4 @@
-
-
diff --git a/report_substitute/wizards/mail_compose_message.py b/report_substitute/wizards/mail_compose_message.py
index d5ab37ff1..2b15ebab0 100644
--- a/report_substitute/wizards/mail_compose_message.py
+++ b/report_substitute/wizards/mail_compose_message.py
@@ -6,30 +6,29 @@ from odoo import api, models
class MailComposeMessage(models.TransientModel):
- _inherit = 'mail.compose.message'
+ _inherit = "mail.compose.message"
- @api.multi
- @api.onchange('template_id')
+ @api.onchange("template_id")
def onchange_template_id_wrapper(self):
if self.template_id:
report_template = self.template_id.report_template
active_ids = []
- if self.env.context.get('active_ids'):
- active_ids = self.env.context.get('active_ids')
- elif self.env.context.get('default_res_id'):
- active_ids = [self.env.context.get('default_res_id')]
+ if self.env.context.get("active_ids"):
+ active_ids = self.env.context.get("active_ids")
+ elif self.env.context.get("default_res_id"):
+ active_ids = [self.env.context.get("default_res_id")]
if (
report_template
and report_template.action_report_substitution_rule_ids
and active_ids
):
- old_report_template = report_template
- self.template_id.report_template = (
- old_report_template.get_substitution_report(active_ids)
+ old_tmpl = report_template
+ self.template_id.report_template = old_tmpl.get_substitution_report(
+ active_ids
)
onchange_result_with_substituted_report = (
super().onchange_template_id_wrapper()
)
- self.template_id.report_template = old_report_template
+ self.template_id.report_template = old_tmpl
return onchange_result_with_substituted_report
return super().onchange_template_id_wrapper()