Browse Source

[MIG] module mail_forward: Migration to version 10.0

CO-1483
pull/256/head
Emanuel Cino 7 years ago
committed by Pedro M. Baeza
parent
commit
092a6912bc
  1. 16
      mail_forward/README.rst
  2. 7
      mail_forward/__manifest__.py
  3. 12
      mail_forward/models/compose_message.py
  4. 2
      mail_forward/models/res_request_link.py
  5. 12
      mail_forward/static/src/css/mail_forward.css
  6. 24
      mail_forward/static/src/css/mail_forward.less
  7. 170
      mail_forward/static/src/js/mail_forward.js
  8. 8
      mail_forward/static/src/xml/mail_forward.xml
  9. 10
      mail_forward/tests/test_compose_message.py
  10. 24
      mail_forward/views/assets.xml
  11. 97
      mail_forward/views/compose_message.xml
  12. 46
      mail_forward/views/res_request_link.xml

16
mail_forward/README.rst

@ -1,6 +1,6 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
===============
Message forward
@ -70,11 +70,10 @@ For further information, please visit:
Bug Tracker
===========
Bugs are tracked on `GitHub Issues <https://github.com/OCA/social/issues>`_. In
case of trouble, please check there if your issue has already been reported. If
you spotted it first, help us smashing it by providing a detailed and welcomed
feedback `here
<https://github.com/OCA/social/issues/new?body=module:%20mail_forward%0Aversion:%208.0.7.0.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Bugs are tracked on `GitHub Issues
<https://github.com/OCA/social/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smashing it by providing a detailed and welcomed feedback.
Credits
@ -83,7 +82,8 @@ Credits
Contributors
------------
* Jairo Llopis <j.llopis@grupoesoc.es>
* Jairo Llopis <jairo.llopis@tecnativa.com>
* Emanuel Cino <ecino@compassion.ch>
Maintainer
----------

7
mail_forward/__openerp__.py → mail_forward/__manifest__.py

@ -5,11 +5,10 @@
{
"name": "Message Forward",
"summary": "Add option to forward messages",
"version": "8.0.7.0.0",
"version": "10.0.1.0.0",
"category": "Social Network",
"website": "https://grupoesoc.es",
"author": "Grupo ESOC Ingeniería de Servicios, "
"Odoo Community Association (OCA)",
"website": "https://github.com/OCA/social",
"author": "Tecnativa, Odoo Community Association (OCA)",
"license": "AGPL-3",
"application": False,
"installable": True,

12
mail_forward/models/compose_message.py

@ -2,7 +2,7 @@
# © 2014-2015 Grupo ESOC <www.grupoesoc.es>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp import api, fields, models
from odoo import api, fields, models
class MailForwardComposeMessage(models.TransientModel):
@ -40,7 +40,6 @@ class MailForwardComposeMessage(models.TransientModel):
order="name")
return [(m.object, m.name) for m in model_objs]
@api.one
@api.onchange("destination_object_id")
def change_destination_object(self):
"""Update some fields for the new message."""
@ -56,10 +55,13 @@ class MailForwardComposeMessage(models.TransientModel):
record_name = "%s %s" % (model_name, record_name)
self.record_name = record_name
else:
self.model = self.res_id = self.record_name = False
@api.one
@api.multi
def send_mail_action(self):
# action buttons call with positional arguments only, so we need an
# intermediary function to ensure the context is passed correctly
return self.send_mail()
def send_mail(self):
"""Send mail and execute the attachment relocation if needed."""
# Let the original wizard do de hard work

2
mail_forward/models/res_request_link.py

@ -2,7 +2,7 @@
# © 2014-2015 Grupo ESOC <www.grupoesoc.es>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp import fields, models
from odoo import fields, models
class ResRequestLink(models.Model):

12
mail_forward/static/src/css/mail_forward.css

@ -1,12 +0,0 @@
/* © 2014-2015 Grupo ESOC <www.grupoesoc.es>
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
*/
.openerp .oe_mail .oe_msg .oe_msg_icons .oe_forward:hover a {
color: #1FC0FF;
text-shadow: 0px 1px #184FC5,
0px -1px #184FC5,
-1px 0px #184FC5,
1px 0px #184FC5,
0px 3px 3px rgba(0, 0, 0, 0.1);
}

24
mail_forward/static/src/css/mail_forward.less

@ -0,0 +1,24 @@
/* (C) 2018 CompassionCH <www.compassion.ch>
/* (C) 2014-2015 Grupo ESOC <www.grupoesoc.es>
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
*/
@mail-thread-icon-opacity: 0.6;
.o_mail_thread {
.o_thread_message {
i.o_forward {
cursor: pointer;
opacity: 0;
}
&:hover, &.o_thread_selected_message {
i.o_forward {
opacity: @mail-thread-icon-opacity;
&:hover {
opacity: 1;
}
}
}
}
}

170
mail_forward/static/src/js/mail_forward.js

@ -2,76 +2,122 @@
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
*/
"use strict";
openerp.mail_forward = function (instance) {
var _t = instance.web._t;
instance.mail.ThreadMessage.include({
bind_events: function () {
this._super.apply(this, arguments);
this.$('.oe_forward').on('click', this.on_message_forward);
},
odoo.define('mail_forward.forward', function (require) {
"use strict";
var core = require('web.core');
var ChatThread = require('mail.ChatThread');
var chat_manager = require('mail.chat_manager');
var Model = require('web.Model');
var session = require('web.session');
var MessageModel = new Model('mail.message', session.user_context);
var _t = core._t;
on_message_forward: function () {
ChatThread.include({
on_message_forward: function (message_id) {
var self = this;
var read_fields = ['record_name', 'parent_id', 'subject', 'attachment_ids', 'date',
'email_to', 'email_from', 'email_cc', 'model', 'res_id', 'body'];
// Generate email subject as possible from record_name and subject
var subject = [_t("FWD")];
if (this.record_name && (this.show_record_name ||
this.parent_id))
{
subject.push(this.record_name);
}
if (this.subject) {
subject.push(this.subject);
} else if (subject.length < 2) {
subject.push(_t("(No subject)"));
}
MessageModel.call('read', [message_id, read_fields], {context: session.user_context}).then(function (result) {
var message = result[0];
var subject = [_t("FWD")];
if (message.record_name && message.parent_id) {
subject.push(message.record_name);
}
if (message.subject) {
subject.push(message.subject);
} else if (subject.length < 2) {
subject.push(_t("(No subject)"));
}
// Get only ID from the attachments
var attachment_ids = [];
for (var n in this.attachment_ids) {
attachment_ids.push(this.attachment_ids[n].id);
}
// Get only ID from the attachments
var attachment_ids = [];
for (var n in message.attachment_ids) {
attachment_ids.push(message.attachment_ids[n]);
}
// Get necessary fields from the forwarded message
var header = [
"----------" + _t("Forwarded message") + "----------",
_t("From: ") + this.author_id[1],
_t("Date: ") + this.date,
];
if (this.subject) {
header.push(_t("Subject: ") + this.subject);
}
if (this.email_to) {
header.push(_t("To: ") + this.email_to);
}
if (this.email_cc) {
header.push(_t("CC: ") + this.email_cc);
}
header = header.map(_.str.escapeHTML).join("<br/>")
// Get necessary fields from the forwarded message
var header = [
"----------" + _t("Forwarded message") + "----------",
_t("From: ") + message.email_from,
_t("Date: ") + message.date
];
if (message.subject) {
header.push(_t("Subject: ") + message.subject);
}
if (message.email_to) {
header.push(_t("To: ") + message.email_to);
}
if (message.email_cc) {
header.push(_t("CC: ") + message.email_cc);
}
header = header.map(_.str.escapeHTML).join("<br/>");
var context = {
default_attachment_ids: attachment_ids,
default_body:
var context = {
default_attachment_ids: attachment_ids,
default_body:
"<p><i>" + header + "</i></p><br/>" +
this.body,
default_model: this.model,
default_res_id: this.res_id,
default_subject: subject.join(": "),
};
message.body,
default_model: message.model,
default_res_id: message.res_id,
default_subject: subject.join(": ")
};
if (this.model && this.res_id) {
context.default_destination_object_id =
[this.model, this.res_id].join();
}
if (message.model && message.res_id) {
context.default_destination_object_id =
[message.model, message.res_id].join();
}
// Get the action data and execute it to open the composer wizard
var do_action = this.do_action;
this.rpc("/web/action/load", {
"action_id": "mail_forward.compose_action",
})
.done(function(action) {
action.context = context;
do_action(action);
// Get the action data and execute it to open the composer wizard
var do_action = self.do_action;
self.rpc("/web/action/load", {
"action_id": "mail_forward.compose_action"
})
.done(function (action) {
action.context = context;
do_action(action, {
on_close: $.proxy(self.thread_reload, self)
});
});
});
},
init: function (parent, options) {
this._super.apply(this, arguments);
// Add click reaction in the events of the thread object
this.events['click .o_forward'] = function (event) {
var message_id = $(event.currentTarget).data('message-id');
this.trigger("message_forward", message_id);
};
},
thread_reload: function(){
var parent = this.getParent();
var domain = [['model', '=', parent.model], ['res_id', '=', parent.res_id]];
var self = this;
MessageModel.call('message_fetch', [domain], {limit: 30}).then(function (msgs) {
var messages = _.map(msgs, chat_manager.make_message);
// Avoid displaying in reverse order
self.options.display_order = 1;
self.render(messages, self.options)
});
}
});
};
var chatter = require('mail.Chatter');
chatter.include({
start: function () {
var result = this._super.apply(this, arguments);
this.thread.on('message_forward', this, this.thread.on_message_forward);
return result;
}
});
var ChatAction = core.action_registry.get('mail.chat.instant_messaging');
ChatAction.include({
start: function () {
var result = this._super.apply(this, arguments);
// For show wizard in the channels
this.thread.on('message_forward', this, this.thread.on_message_forward);
return result;
}
});
});

8
mail_forward/static/src/xml/mail_forward.xml

@ -4,11 +4,9 @@
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -->
<template>
<t t-extend="mail.thread.message">
<t t-jquery=".oe_msg_icons .oe_reply" t-operation="before">
<span class="oe_forward">
<a title="Forward" class="oe_e">*</a>
</span>
<t t-extend="mail.ChatThread.Message">
<t t-jquery=".o_thread_message_reply" t-operation="after">
<i class="fa fa-share o_forward" title="Forward" t-att-data-message-id="message.id"/>
</t>
</t>
</template>

10
mail_forward/tests/test_compose_message.py

@ -3,7 +3,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from os import path
from openerp.tests.common import TransactionCase
from odoo.tests.common import TransactionCase
class ForwardMailCase(TransactionCase):
@ -43,14 +43,6 @@ class ForwardMailCase(TransactionCase):
self.assertEqual(self.fwd.record_name,
"%s %s" % (model.name, self.partner.name))
# Remove the destination object
self.fwd.destination_object_id = False
self.fwd.change_destination_object()
self.assertFalse(self.fwd.model)
self.assertFalse(self.fwd.res_id)
self.assertFalse(self.fwd.record_name)
def test_move_attachments(self):
"""Attachments moved correctly."""
self.fwd.attachment_ids |= self.attachment

24
mail_forward/views/assets.xml

@ -3,19 +3,15 @@
<!-- © 2014-2015 Grupo ESOC <www.grupoesoc.es>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -->
<openerp>
<data>
<odoo>
<template id="assets_backend"
name="Mail forward assets"
inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<link rel="stylesheet"
href="/mail_forward/static/src/css/mail_forward.css"/>
<script type="text/javascript"
src="/mail_forward/static/src/js/mail_forward.js"/>
</xpath>
</template>
<template id="assets_backend"
name="Mail forward assets"
inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<link rel="stylesheet" href="/mail_forward/static/src/css/mail_forward.less" type="text/less"/>
<script type="text/javascript" src="/mail_forward/static/src/js/mail_forward.js"/>
</xpath>
</template>
</data>
</openerp>
</odoo>

97
mail_forward/views/compose_message.xml

@ -3,62 +3,53 @@
<!-- © 2014-2015 Grupo ESOC <www.grupoesoc.es>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -->
<openerp>
<data>
<record id="compose_form" model="ir.ui.view">
<field name="name">Forward Email Form</field>
<field name="model">mail_forward.compose_message</field>
<field name="inherit_id" ref="mail.email_compose_message_wizard_form"/>
<field name="arch" type="xml">
<data>
<!-- It's required to fill either `partner_ids` or
`destination_object_id` -->
<xpath expr="//field[@name='partner_ids']" position="attributes">
<attribute name="attrs">{
'required': [('destination_object_id', '=', False)]
}</attribute>
</xpath>
<xpath expr="//label[@for='partner_ids']" position="before">
<!-- Object where the message will be attached -->
<field
attrs="{
<odoo>
<record id="compose_form" model="ir.ui.view">
<field name="name">Forward Email Form</field>
<field name="model">mail_forward.compose_message</field>
<field name="inherit_id" ref="mail.email_compose_message_wizard_form"/>
<field name="arch" type="xml">
<data>
<!-- It's required to fill either `partner_ids` or
`destination_object_id` -->
<xpath expr="//field[@name='partner_ids']" position="attributes">
<attribute name="attrs">{
'required': [('destination_object_id', '=', False)]
}
</attribute>
</xpath>
<xpath expr="//label[@for='partner_ids']" position="before">
<!-- Object where the message will be attached -->
<field
attrs="{
'required': [('partner_ids', '=', [[6, False, []]])]}"
name="destination_object_id"/>
name="destination_object_id"/>
<!-- If the message has attachments, should we move them to the
new object? -->
<field
name="move_attachments"
attrs="{
<!-- If the message has attachments, should we move them to the
new object? -->
<field
name="move_attachments"
attrs="{
'invisible': [
'|',
('destination_object_id', '=', False),
('attachment_ids', '=', [[6, False, []]])]}"/>
</xpath>
<!-- If there's no document to follow, hide the message -->
<xpath expr="//span[text()='Followers of the document and']"
position="attributes">
<attribute name="attrs">{
'invisible': [('destination_object_id', '=', False)]
}</attribute>
</xpath>
</data>
</field>
</record>
<record id="compose_action" model="ir.actions.act_window">
<field name="name">Forward Email</field>
<field name="res_model">mail_forward.compose_message</field>
<field name="src_model">mail.message</field>
<field name="type">ir.actions.act_window</field>
<field name="view_id" ref="compose_form"/>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
</data>
</openerp>
</xpath>
</data>
</field>
</record>
<record id="compose_action" model="ir.actions.act_window">
<field name="name">Forward Email</field>
<field name="res_model">mail_forward.compose_message</field>
<field name="src_model">mail.message</field>
<field name="type">ir.actions.act_window</field>
<field name="view_id" ref="compose_form"/>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
</odoo>

46
mail_forward/views/res_request_link.xml

@ -3,30 +3,28 @@
<!-- © 2014-2015 Grupo ESOC <www.grupoesoc.es>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -->
<openerp>
<data>
<odoo>
<record id="res_request_link_view_form" model="ir.ui.view">
<field name="name">Add option to forward mails</field>
<field name="model">res.request.link</field>
<field name="inherit_id" ref="base.res_request_link-view"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='priority']" position="after">
<field name="mail_forward_target"/>
</xpath>
</field>
</record>
<record id="res_request_link_view_form" model="ir.ui.view">
<field name="name">Add option to forward mails</field>
<field name="model">res.request.link</field>
<field name="inherit_id" ref="base.res_request_link-view"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='priority']" position="after">
<field name="mail_forward_target"/>
</xpath>
</field>
</record>
<record id="res_request_link_view_tree" model="ir.ui.view">
<field name="name">Add option to forward mails</field>
<field name="model">res.request.link</field>
<field name="inherit_id" ref="base.res_request_link_tree-view"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='object']" position="after">
<field name="mail_forward_target"/>
</xpath>
</field>
</record>
<record id="res_request_link_view_tree" model="ir.ui.view">
<field name="name">Add option to forward mails</field>
<field name="model">res.request.link</field>
<field name="inherit_id" ref="base.res_request_link_tree-view"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='object']" position="after">
<field name="mail_forward_target"/>
</xpath>
</field>
</record>
</data>
</openerp>
</odoo>
Loading…
Cancel
Save