Skip to content

Commit

Permalink
CO-1483 Migrate module mail_forward to version 10.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ecino committed Apr 13, 2018
1 parent 7c61dfd commit d6f188a
Show file tree
Hide file tree
Showing 12 changed files with 215 additions and 196 deletions.
16 changes: 8 additions & 8 deletions mail_forward/README.rst
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -83,7 +82,8 @@ Credits
Contributors
------------

* Jairo Llopis <j.llopis@grupoesoc.es>
* Emanuel Cino <ecino@compassion.ch>
* Jairo Llopis <jairo.llopis@tecnativa.com>

Maintainer
----------
Expand Down
6 changes: 3 additions & 3 deletions mail_forward/__openerp__.py → mail_forward/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
{
"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)",
"author": "Odoo Community Association (OCA)"
", Tecnativa",
"license": "AGPL-3",
"application": False,
"installable": True,
Expand Down
10 changes: 5 additions & 5 deletions mail_forward/models/compose_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -40,7 +40,6 @@ def _get_model_selection(self):
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."""
Expand All @@ -56,10 +55,11 @@ def change_destination_object(self):
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):
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
Expand Down
2 changes: 1 addition & 1 deletion mail_forward/models/res_request_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
12 changes: 0 additions & 12 deletions mail_forward/static/src/css/mail_forward.css

This file was deleted.

24 changes: 24 additions & 0 deletions mail_forward/static/src/css/mail_forward.less
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
}
}
156 changes: 94 additions & 62 deletions mail_forward/static/src/js/mail_forward.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,76 +2,108 @@
* 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 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', 'author_id', 'date',
'email_to', '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.author_id[1],
_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);
});
});
},
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);
};
}
});

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 changes: 3 additions & 5 deletions mail_forward/static/src/xml/mail_forward.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 1 addition & 9 deletions mail_forward/tests/test_compose_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -43,14 +43,6 @@ def test_change_destination(self):
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
Expand Down
24 changes: 10 additions & 14 deletions mail_forward/views/assets.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Loading

0 comments on commit d6f188a

Please sign in to comment.