[MIG] report_substitute: Migration to 15.0
parent
5922b46d07
commit
f95496c6ee
|
@ -6,16 +6,20 @@
|
||||||
"summary": """
|
"summary": """
|
||||||
This module allows to create substitution rules for report actions.
|
This module allows to create substitution rules for report actions.
|
||||||
""",
|
""",
|
||||||
"version": "13.0.1.0.0",
|
"version": "15.0.1.0.0",
|
||||||
"license": "AGPL-3",
|
"license": "AGPL-3",
|
||||||
"author": "ACSONE SA/NV," "Odoo Community Association (OCA)",
|
"author": "ACSONE SA/NV," "Odoo Community Association (OCA)",
|
||||||
"website": "https://github.com/OCA/reporting-engine",
|
"website": "https://github.com/OCA/reporting-engine",
|
||||||
"depends": ["base", "mail"],
|
"depends": ["base", "mail"],
|
||||||
"data": [
|
"data": [
|
||||||
"security/ir_actions_report_substitution_rule.xml",
|
"security/ir_actions_report_substitution_rule.xml",
|
||||||
"views/assets_backend.xml",
|
|
||||||
"views/ir_actions_report.xml",
|
"views/ir_actions_report.xml",
|
||||||
],
|
],
|
||||||
"demo": ["demo/action_report.xml"],
|
"demo": ["demo/action_report.xml"],
|
||||||
|
"assets": {
|
||||||
|
"web.assets_backend": [
|
||||||
|
"report_substitute/static/src/js/action_manager.esm.js",
|
||||||
|
],
|
||||||
|
},
|
||||||
"maintainers": ["sbejaoui"],
|
"maintainers": ["sbejaoui"],
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,8 +10,8 @@ class IrActionReport(models.Model):
|
||||||
_inherit = "ir.actions.report"
|
_inherit = "ir.actions.report"
|
||||||
|
|
||||||
action_report_substitution_rule_ids = fields.One2many(
|
action_report_substitution_rule_ids = fields.One2many(
|
||||||
comodel_name="ir.actions.report.substitution.rule",
|
"ir.actions.report.substitution.rule",
|
||||||
inverse_name="action_report_id",
|
"action_report_id",
|
||||||
string="Substitution Rules",
|
string="Substitution Rules",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -47,11 +47,12 @@ class IrActionReport(models.Model):
|
||||||
action_report.model, active_ids
|
action_report.model, active_ids
|
||||||
)
|
)
|
||||||
action.update(action_report.read()[0])
|
action.update(action_report.read()[0])
|
||||||
|
|
||||||
return action
|
return action
|
||||||
|
|
||||||
def render(self, res_ids, data=None):
|
def _render(self, res_ids, data=None):
|
||||||
substitution_report = self.get_substitution_report(res_ids)
|
substitution_report = self.get_substitution_report(res_ids)
|
||||||
return super(IrActionReport, substitution_report).render(res_ids, data)
|
return super(IrActionReport, substitution_report)._render(res_ids, data)
|
||||||
|
|
||||||
def report_action(self, docids, data=None, config=True):
|
def report_action(self, docids, data=None, config=True):
|
||||||
if docids:
|
if docids:
|
||||||
|
@ -66,3 +67,6 @@ class IrActionReport(models.Model):
|
||||||
docids, data, config
|
docids, data, config
|
||||||
)
|
)
|
||||||
return super().report_action(docids, data, config)
|
return super().report_action(docids, data, config)
|
||||||
|
|
||||||
|
def get_action_report_substitution_rule_ids(self):
|
||||||
|
return self.action_report_substitution_rule_ids.ids
|
||||||
|
|
|
@ -19,7 +19,7 @@ class ActionsReportSubstitutionRule(models.Model):
|
||||||
ondelete="cascade",
|
ondelete="cascade",
|
||||||
)
|
)
|
||||||
model = fields.Char(related="action_report_id.model", store=True)
|
model = fields.Char(related="action_report_id.model", store=True)
|
||||||
domain = fields.Char(string="Domain", required=True, default="[]")
|
domain = fields.Char(required=True, default="[]")
|
||||||
substitution_action_report_id = fields.Many2one(
|
substitution_action_report_id = fields.Many2one(
|
||||||
comodel_name="ir.actions.report",
|
comodel_name="ir.actions.report",
|
||||||
string="Substitution Report Action",
|
string="Substitution Report Action",
|
||||||
|
@ -37,7 +37,8 @@ class ActionsReportSubstitutionRule(models.Model):
|
||||||
substitution_rule
|
substitution_rule
|
||||||
) in substitution_report.action_report_substitution_rule_ids:
|
) in substitution_report.action_report_substitution_rule_ids:
|
||||||
_check_infinite_loop(
|
_check_infinite_loop(
|
||||||
original_report, substitution_rule.substitution_action_report_id,
|
original_report,
|
||||||
|
substitution_rule.substitution_action_report_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
for rec in self:
|
for rec in self:
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
/** @odoo-module **/
|
||||||
|
|
||||||
|
import {registry} from "@web/core/registry";
|
||||||
|
|
||||||
|
registry
|
||||||
|
.category("ir.actions.report handlers")
|
||||||
|
.add("sustitution_handler", async function (action, options, env) {
|
||||||
|
const orm = env.services.orm;
|
||||||
|
const action_report_substitution_rule_ids = await orm.call(
|
||||||
|
"ir.actions.report",
|
||||||
|
"get_action_report_substitution_rule_ids",
|
||||||
|
[action.id]
|
||||||
|
);
|
||||||
|
if (
|
||||||
|
action.type === "ir.actions.report" &&
|
||||||
|
action.context.active_ids &&
|
||||||
|
action_report_substitution_rule_ids &&
|
||||||
|
action_report_substitution_rule_ids.length !== 0
|
||||||
|
) {
|
||||||
|
var active_ids = action.context.active_ids;
|
||||||
|
const substitution = await orm.call(
|
||||||
|
"ir.actions.report",
|
||||||
|
"get_substitution_report_action",
|
||||||
|
[action, active_ids]
|
||||||
|
);
|
||||||
|
Object.assign(action, substitution);
|
||||||
|
}
|
||||||
|
return Promise.resolve(false);
|
||||||
|
});
|
|
@ -1,35 +0,0 @@
|
||||||
// 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) {
|
|
||||||
"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" &&
|
|
||||||
action.context.active_ids &&
|
|
||||||
action.action_report_substitution_rule_ids &&
|
|
||||||
action.action_report_substitution_rule_ids !== 0
|
|
||||||
) {
|
|
||||||
var active_ids = action.context.active_ids;
|
|
||||||
var self = this;
|
|
||||||
var _super = this._super;
|
|
||||||
return this._rpc({
|
|
||||||
model: "ir.actions.report",
|
|
||||||
method: "get_substitution_report_action",
|
|
||||||
args: [action, active_ids],
|
|
||||||
}).then(function(substitution_action) {
|
|
||||||
return _super.apply(self, [substitution_action, options]);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return this._super.apply(this, arguments);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -1,11 +0,0 @@
|
||||||
<?xml version="1.0" encoding="utf-8" ?>
|
|
||||||
<odoo>
|
|
||||||
<template id="assets_backend" name="report assets" inherit_id="web.assets_backend">
|
|
||||||
<xpath expr="." position="inside">
|
|
||||||
<script
|
|
||||||
type="text/javascript"
|
|
||||||
src="/report_substitute/static/src/js/action_manager.js"
|
|
||||||
/>
|
|
||||||
</xpath>
|
|
||||||
</template>
|
|
||||||
</odoo>
|
|
|
@ -27,8 +27,8 @@ class MailComposeMessage(models.TransientModel):
|
||||||
active_ids
|
active_ids
|
||||||
)
|
)
|
||||||
onchange_result_with_substituted_report = (
|
onchange_result_with_substituted_report = (
|
||||||
super().onchange_template_id_wrapper()
|
super()._onchange_template_id_wrapper()
|
||||||
)
|
)
|
||||||
self.template_id.report_template = old_tmpl
|
self.template_id.report_template = old_tmpl
|
||||||
return onchange_result_with_substituted_report
|
return onchange_result_with_substituted_report
|
||||||
return super().onchange_template_id_wrapper()
|
return super()._onchange_template_id_wrapper()
|
||||||
|
|
Loading…
Reference in New Issue