Skip to content

Commit

Permalink
⚡ mail_to New: channels are displayed in recipients
Browse files Browse the repository at this point in the history
  • Loading branch information
Ommo73 committed Aug 30, 2019
1 parent 5a610a4 commit c5cb7f8
Show file tree
Hide file tree
Showing 11 changed files with 123 additions and 14 deletions.
2 changes: 2 additions & 0 deletions mail_to/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# -*- coding: utf-8 -*-
# License LGPL-3.0 (https://www.gnu.org/licenses/lgpl.html).
from . import models
7 changes: 6 additions & 1 deletion mail_to/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
# -*- coding: utf-8 -*-
# Copyright 2016 x620 <https://github.com/x620>
# Copyright 2016 Ivan Yelizariev <https://it-projects.info/team/yelizariev>
# Copyright 2018 Ruslan Ronzhin
# Copyright 2019 Artem Rafailov <https://it-projects.info/team/Ommo73/>
# License LGPL-3.0 (https://www.gnu.org/licenses/lgpl.html).
{
"name": """Show message recipients""",
"summary": """Allows you be sure, that all discussion participants were notified""",
"category": "Discuss",
"images": ['images/1.png'],
"version": "1.0.1",
"version": "10.0.1.1.0",

"author": "IT-Projects LLC, Pavel Romanchenko",
"support": "[email protected]",
Expand Down
8 changes: 7 additions & 1 deletion mail_to/doc/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
`1.1.0`
-------

- **New**: channels are displayed in recipients


`1.0.1`
-------

- **FIX:** The problem with duplicating the names of recipients was solved.
- **FIX**: the problem with duplicating the names of recipients was solved.

`1.0.0`
-------
Expand Down
2 changes: 2 additions & 0 deletions mail_to/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
from . import mail_message
20 changes: 20 additions & 0 deletions mail_to/models/mail_message.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Copyright 2019 Artem Rafailov <https://it-projects.info/team/Ommo73/>
# License LGPL-3.0 (https://www.gnu.org/licenses/lgpl.html).
from odoo import models, api


class MailMessage(models.Model):
_inherit = 'mail.message'

@api.multi
def message_format(self):
message_values = super(MailMessage, self).message_format()
for i in message_values:
if i['channel_ids']:
i['channel_names'] = []
for channel_id in i['channel_ids']:
channel = self.env['mail.channel'].search([('id', '=', channel_id)])
i['channel_names'].append([channel_id, '#' + channel['display_name']])

return message_values
26 changes: 17 additions & 9 deletions mail_to/static/src/js/mail_to.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/* Copyright 2016 x620 <https://github.com/x620>
* Copyright 2016-2017 Ivan Yelizariev <https://it-projects.info/team/yelizariev>
* Copyright 2017 Artyom Losev <https://it-projects.info/>
* Copyright 2019 Artem Rafailov <https://it-projects.info/team/Ommo73/>
* License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). */
odoo.define('mail_to.MailTo', function (require) {
"use strict";

Expand All @@ -7,23 +12,26 @@ odoo.define('mail_to.MailTo', function (require) {
make_message: function(data){
var msg = this._super(data);
msg.partner_ids = data.partner_ids;
if (!msg.partner_ids) {
msg.channel_names = data.channel_names;
msg.recipients = data.partner_ids.concat(data.channel_names);
if (!msg.partner_ids && !msg.channel_names) {
return msg;
}

var more_recipients = '';
// value which define more recipients
msg.more_recipients_value = 4;
for (var i = 0; i < msg.partner_ids.length; i++){
if (i >= msg.more_recipients_value){
// append names
more_recipients += msg.partner_ids[i][1];
// separate them with semicolon
if (i < msg.partner_ids.length - 1){
more_recipients += '; ';
for (var i = 0; i < msg.recipients.length; i++){
if (i >= msg.more_recipients_value){
// append names
more_recipients += msg.recipients[i][1];
// separate them with semicolon
if (i < msg.recipients.length - 1){
more_recipients += '; ';
}
}
}
}

msg.more_recipients = more_recipients;
return msg;
}
Expand Down
20 changes: 20 additions & 0 deletions mail_to/static/src/js/test_mail_to.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* Copyright 2018 Artem Rafailov <https://it-projects.info/team/KolushovAlexandr>
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).*/
odoo.define('mail_to.tour', function (require) {
"use strict";

var tour = require("web_tour.tour");
var core = require('web.core');
var _t = core._t;

var email = 'mail_private test email';
var steps = [{
trigger: 'a.recipient_link:first',
content: _t("Open Partners Form From Recipient Link"),
position: 'bottom',
timeout: 70000,
}];

tour.register('mail_to_tour', { test: true, url: '/web' }, steps);

});
23 changes: 20 additions & 3 deletions mail_to/static/src/xml/recipient.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--Copyright 2016 x620 <https://github.com/x620>
Copyright 2017 Ivan Yelizariev <https://it-projects.info/team/yelizariev>
Copyright 2019 Artem Rafailov <https://it-projects.info/team/Ommo73/>
License LGPL-3.0 (https://www.gnu.org/licenses/lgpl.html).-->
<template>
<t t-extend="mail.ChatThread.Message">
<t t-jquery="p[class=o_mail_info] span:last" t-operation="after">
<span class="recipients_info"><t t-if="message.partner_ids">
<t t-if="message.partner_ids.length > 0">To: </t>
<t t-else="message.channel_ids.length > 0">To: </t>
<t t-foreach="message.partner_ids.length" t-as="i">
<t t-if="i &lt; message.more_recipients_value">
<a t-att-href="_.str.sprintf('/web?#id=%s&amp;view_type=form&amp;model=res.partner', message.partner_ids[i][0])" class="recipient_link">
<i t-esc="message.partner_ids[i][1]"/><t t-if="i &lt; message.partner_ids.length - 1">; </t>
<i t-esc="message.partner_ids[i][1]"/><t t-if="i &lt; message.partner_ids.length - 1">; </t><t t-else="message.channel_ids.length > 0 and message.partner_ids.length &lt; 4">; </t>
</a>
</t>
</t>
<t t-if="message.partner_ids.length &gt; message.more_recipients_value">

<t t-if="message.channel_names">
<t t-foreach="message.channel_ids.length" t-as="i">
<t t-if="message.partner_ids.length &lt; message.more_recipients_value and (message.partner_ids.length + i) &lt; message.more_recipients_value">
<a t-if="message.channel_names[i]" t-att-href="_.str.sprintf('/web?#id=%s&amp;view_type=form&amp;model=mail.channel', message.channel_names[i][0])" class="recipient_link">
<i t-esc="message.channel_names[i][1]"/><t t-if="i &lt; message.channel_ids.length - 1">; </t>
</a>
</t>
</t>
</t>


<t t-if="message.recipients.length &gt; message.more_recipients_value">
<span t-att-title="message.more_recipients">
and <t t-esc="message.partner_ids.length - message.more_recipients_value"/> more
and <t t-esc="message.recipients.length - message.more_recipients_value"/> more
</span>
</t>
</t></span>
Expand Down
5 changes: 5 additions & 0 deletions mail_to/templates.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<?xml version="1.0"?>
<!--Copyright 2016 x620 <https://github.com/x620>
Copyright 2017 Ivan Yelizariev <https://it-projects.info/team/yelizariev>
Copyright 2019 Artem Rafailov <https://it-projects.info/team/Ommo73/>
License LGPL-3.0 (https://www.gnu.org/licenses/lgpl.html).-->
<openerp>
<data>
<template id="mail_to_assets_backend"
Expand All @@ -7,6 +11,7 @@
<xpath expr="." position="inside">
<link rel="stylesheet" href="/mail_to/static/src/css/mail_to.css"/>
<script src="/mail_to/static/src/js/mail_to.js" type="text/javascript"></script>
<script src="/mail_to/static/src/js/test_mail_to.js" type="text/javascript"></script>
</xpath>
</template>
</data>
Expand Down
3 changes: 3 additions & 0 deletions mail_to/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
# License LGPL-3.0 (https://www.gnu.org/licenses/lgpl.html).
from . import test_default
21 changes: 21 additions & 0 deletions mail_to/tests/test_default.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# Copyright 2019 Artem Rafailov <https://it-projects.info/team/Ommo73/>
# License LGPL-3.0 (https://www.gnu.org/licenses/lgpl.html).
import odoo.tests
from odoo.api import Environment


@odoo.tests.common.at_install(True)
@odoo.tests.common.post_install(True)
class TestUi(odoo.tests.HttpCase):

def test_01_mail_to(self):
cr = self.registry.cursor()
env = Environment(cr, self.uid, {})
env['ir.module.module'].search([('name', '=', 'mail_to')], limit=1).state = 'installed'
cr.release()

self.phantom_js("/web",
"odoo.__DEBUG__.services['web_tour.tour'].run('mail_to_tour', 1000)",
"odoo.__DEBUG__.services['web_tour.tour'].tours.mail_to_tour.ready",
login="admin", timeout=200)

0 comments on commit c5cb7f8

Please sign in to comment.