Browse Source

[12.0][IMP] - Add check for substitution infinite loop

pull/307/head
sbejaoui 5 years ago
parent
commit
2eb9253fcf
  1. 2
      report_substitute/__manifest__.py
  2. 23
      report_substitute/models/ir_actions_report_substitution_rule.py
  3. 14
      report_substitute/tests/test_report_substitute.py

2
report_substitute/__manifest__.py

@ -10,7 +10,7 @@
'license': 'AGPL-3',
'author': 'ACSONE SA/NV,'
'Odoo Community Association (OCA)',
'website': 'https://github.com/acsone/reporting-engine',
'website': 'https://github.com/OCA/reporting-engine',
'depends': ['base', 'mail'],
'data': [
'security/ir_actions_report_substitution_rule.xml',

23
report_substitute/models/ir_actions_report_substitution_rule.py

@ -1,7 +1,8 @@
# Copyright 2019 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import fields, models
from odoo import fields, models, api, _
from odoo.exceptions import ValidationError
class ActionsReportSubstitutionRule(models.Model):
@ -24,5 +25,23 @@ class ActionsReportSubstitutionRule(models.Model):
string="Substitution Report Action",
required=True,
ondelete="cascade",
domain="[('model', '=', model)]"
domain="[('model', '=', model)]",
)
@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:
raise ValidationError(_("Substitution infinite loop detected"))
for (
substitution_rule
) in substitution_report.action_report_substitution_rule_ids:
_check_infinite_loop(
original_report,
substitution_rule.substitution_action_report_id,
)
for rec in self:
_check_infinite_loop(
rec.action_report_id, rec.substitution_action_report_id
)

14
report_substitute/tests/test_report_substitute.py

@ -2,6 +2,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.tests.common import TransactionCase
from odoo.exceptions import ValidationError
class TestReportSubstitute(TransactionCase):
@ -64,3 +65,16 @@ class TestReportSubstitute(TransactionCase):
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(
{
'action_report_id': self.env.ref(
'report_substitute.substitution_report_print'
).id,
'substitution_action_report_id': self.env.ref(
'base.ir_module_reference_print'
).id,
}
)
Loading…
Cancel
Save