Browse Source

[IMP] - manage substitution for mail.thread message_post_with_template

pull/307/head
sbejaoui 5 years ago
parent
commit
ed669b00a3
  1. 1
      report_substitute/__init__.py
  2. 2
      report_substitute/__manifest__.py
  3. 1
      report_substitute/models/__init__.py
  4. 33
      report_substitute/models/ir_actions_report.py
  5. 24
      report_substitute/models/mail_thread.py
  6. 12
      report_substitute/static/src/js/action_manager.js
  7. 6
      report_substitute/views/ir_actions_report.xml
  8. 1
      report_substitute/wizards/__init__.py
  9. 28
      report_substitute/wizards/mail_compose_message.py

1
report_substitute/__init__.py

@ -1,2 +1,3 @@
from . import models from . import models
from . import wizards
from . import tests from . import tests

2
report_substitute/__manifest__.py

@ -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
report_substitute/models/__init__.py

@ -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

33
report_substitute/models/ir_actions_report.py

@ -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(
self.model, res_ids
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):
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 substitution_report.render(res_ids, data)
return super().render(res_ids, data)
return super().report_action(docids, data, config)

24
report_substitute/models/mail_thread.py

@ -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

12
report_substitute/static/src/js/action_manager.js

@ -1,25 +1,27 @@
// 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) { _handleAction: function (action, options) {
if (action.type === 'ir.actions.report' &&
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',
method: 'get_substitution_report_dict',
model: "ir.actions.report",
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

6
report_substitute/views/ir_actions_report.xml

@ -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"
domain="[('id', '!=', parent.id)]"/>/>
<field name="domain"/>
</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"

1
report_substitute/wizards/__init__.py

@ -0,0 +1 @@
from . import mail_compose_message

28
report_substitute/wizards/mail_compose_message.py

@ -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…
Cancel
Save