mirror of
https://github.com/OCA/reporting-engine.git
synced 2025-02-16 16:30:38 +02:00
[13.0][MIG] - report_substitute migration
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user