[IMP] - manage substitution for mail.thread message_post_with_template
parent
6f831d7f48
commit
2249f37cee
|
@ -1,2 +1,3 @@
|
||||||
from . import models
|
from . import models
|
||||||
|
from . import wizards
|
||||||
from . import tests
|
from . import tests
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
'author': 'ACSONE SA/NV,'
|
'author': 'ACSONE SA/NV,'
|
||||||
'Odoo Community Association (OCA)',
|
'Odoo Community Association (OCA)',
|
||||||
'website': 'https://github.com/acsone/reporting-engine',
|
'website': 'https://github.com/acsone/reporting-engine',
|
||||||
'depends': ['base'],
|
'depends': ['base', 'mail'],
|
||||||
'data': [
|
'data': [
|
||||||
'security/ir_actions_report_substitution_rule.xml',
|
'security/ir_actions_report_substitution_rule.xml',
|
||||||
'views/assets_backend.xml',
|
'views/assets_backend.xml',
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
from . import ir_actions_report
|
from . import ir_actions_report
|
||||||
from . import ir_actions_report_substitution_rule
|
from . import ir_actions_report_substitution_rule
|
||||||
|
from . import mail_thread
|
||||||
|
|
|
@ -28,6 +28,18 @@ class IrActionReport(models.Model):
|
||||||
return substitution_report_rule.substitution_action_report_id
|
return substitution_report_rule.substitution_action_report_id
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@api.multi
|
||||||
|
def get_substitution_report(self, active_ids):
|
||||||
|
self.ensure_one()
|
||||||
|
action_report = self
|
||||||
|
substitution_report = action_report
|
||||||
|
while substitution_report:
|
||||||
|
action_report = substitution_report
|
||||||
|
substitution_report = action_report._get_substitution_report(
|
||||||
|
action_report.model, active_ids
|
||||||
|
)
|
||||||
|
return action_report
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def get_substitution_report_dict(self, action_report_dict, active_ids):
|
def get_substitution_report_dict(self, action_report_dict, active_ids):
|
||||||
if action_report_dict.get('id'):
|
if action_report_dict.get('id'):
|
||||||
|
@ -43,9 +55,20 @@ class IrActionReport(models.Model):
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def render(self, res_ids, data=None):
|
def render(self, res_ids, data=None):
|
||||||
substitution_report = self._get_substitution_report(
|
substitution_report = self.get_substitution_report(res_ids)
|
||||||
self.model, 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):
|
||||||
|
active_ids = docids.ids
|
||||||
|
elif isinstance(docids, int):
|
||||||
|
active_ids = [docids]
|
||||||
|
elif isinstance(docids, list):
|
||||||
|
active_ids = docids
|
||||||
|
substitution_report = self.get_substitution_report(active_ids)
|
||||||
|
return super(IrActionReport, substitution_report).report_action(
|
||||||
|
docids, data, config
|
||||||
)
|
)
|
||||||
if substitution_report:
|
return super().report_action(docids, data, config)
|
||||||
return substitution_report.render(res_ids, data)
|
|
||||||
return super().render(res_ids, data)
|
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
# Copyright 2019 ACSONE SA/NV
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
|
from odoo import api, models
|
||||||
|
|
||||||
|
|
||||||
|
class MailThread(models.AbstractModel):
|
||||||
|
|
||||||
|
_inherit = 'mail.thread'
|
||||||
|
|
||||||
|
@api.multi
|
||||||
|
def message_post_with_template(self, template_id, **kwargs):
|
||||||
|
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
|
||||||
|
)
|
||||||
|
res = super().message_post_with_template(template_id, **kwargs)
|
||||||
|
if old_report:
|
||||||
|
template.report_template = old_report
|
||||||
|
return res
|
|
@ -1,27 +1,29 @@
|
||||||
// Copyright 2019 ACSONE SA/NV
|
// Copyright 2019 ACSONE SA/NV
|
||||||
// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
// 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";
|
"use strict";
|
||||||
|
|
||||||
var ActionManager = require('web.ActionManager');
|
var ActionManager = require("web.ActionManager");
|
||||||
|
|
||||||
ActionManager.include({
|
ActionManager.include({
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Intercept action handling substitute the report action
|
* Intercept action handling substitute the report action
|
||||||
* @override
|
* @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.context.active_ids) {
|
||||||
var active_ids = action.context.active_ids;
|
var active_ids = action.context.active_ids;
|
||||||
var self = this;
|
var self = this;
|
||||||
var _super = this._super;
|
var _super = this._super;
|
||||||
var callersArguments = arguments;
|
var callersArguments = arguments;
|
||||||
return this._rpc({
|
return this._rpc({
|
||||||
model: 'ir.actions.report',
|
model: "ir.actions.report",
|
||||||
method: 'get_substitution_report_dict',
|
method: "get_substitution_report_dict",
|
||||||
args: [action, active_ids]
|
args: [action, active_ids]
|
||||||
}).then(function(action_id) {
|
}).then(function (action_id) {
|
||||||
callersArguments[0] = action_id
|
callersArguments[0] = action_id
|
||||||
return _super.apply(self, callersArguments);
|
return _super.apply(self, callersArguments);
|
||||||
});
|
});
|
||||||
|
|
|
@ -16,8 +16,7 @@
|
||||||
<tree>
|
<tree>
|
||||||
<field name="sequence" widget="handle"/>
|
<field name="sequence" widget="handle"/>
|
||||||
<field name="substitution_action_report_id"/>
|
<field name="substitution_action_report_id"/>
|
||||||
<field name="domain"
|
<field name="domain"/>
|
||||||
domain="[('id', '!=', parent.id)]"/>/>
|
|
||||||
</tree>
|
</tree>
|
||||||
<form>
|
<form>
|
||||||
<sheet>
|
<sheet>
|
||||||
|
@ -26,7 +25,8 @@
|
||||||
invisible="1" readonly="1"
|
invisible="1" readonly="1"
|
||||||
required="0"/>
|
required="0"/>
|
||||||
<field name="model" invisible="1"/>
|
<field name="model" invisible="1"/>
|
||||||
<field name="substitution_action_report_id"/>
|
<field name="substitution_action_report_id"
|
||||||
|
domain="[('model', '=', model), ('id', '!=', parent.id)]"/>
|
||||||
</group>
|
</group>
|
||||||
<group>
|
<group>
|
||||||
<field name="domain" widget="domain"
|
<field name="domain" widget="domain"
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
from . import mail_compose_message
|
|
@ -0,0 +1,28 @@
|
||||||
|
# Copyright 2019 ACSONE SA/NV
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
|
from odoo import api, models
|
||||||
|
|
||||||
|
|
||||||
|
class MailComposeMessage(models.TransientModel):
|
||||||
|
|
||||||
|
_inherit = 'mail.compose.message'
|
||||||
|
|
||||||
|
@api.multi
|
||||||
|
@api.onchange('template_id')
|
||||||
|
def onchange_template_id_wrapper(self):
|
||||||
|
old_report_template = False
|
||||||
|
if (
|
||||||
|
self.template_id
|
||||||
|
and self.template_id.report_template
|
||||||
|
and self.env.context.get('active_ids')
|
||||||
|
):
|
||||||
|
active_ids = self.env.context.get('active_ids')
|
||||||
|
old_report_template = self.template_id.report_template
|
||||||
|
self.template_id.report_template = (
|
||||||
|
old_report_template.get_substitution_report(active_ids)
|
||||||
|
)
|
||||||
|
res = super().onchange_template_id_wrapper()
|
||||||
|
if old_report_template:
|
||||||
|
self.template_id.report_template = old_report_template
|
||||||
|
return res
|
Loading…
Reference in New Issue