Browse Source

Merge pull request #235 from Ommo73/11.0-mail_addons-merge2

commit is created by 👷‍♂️ Merge Bot: https://odoo-devops.readthedocs.io/en/latest/git/github-merge-bot.html
pull/245/head
Mitchell Admin 5 years ago
committed by GitHub
parent
commit
0407ce3143
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      .travis.yml
  2. 2
      mail_base/README.rst
  3. 1
      mail_base/__init__.py
  4. 6
      mail_base/__manifest__.py
  5. 3
      mail_base/controllers/main.py
  6. 4
      mail_base/doc/changelog.rst
  7. 7
      mail_base/models.py
  8. 3
      mail_base/static/lib/base.js
  9. 6
      mail_multi_website/README.rst
  10. 2
      mail_multi_website/__manifest__.py
  11. 6
      mail_multi_website/doc/index.rst
  12. 2
      mail_multi_website/static/description/index.html
  13. 1
      mail_private/__init__.py
  14. 10
      mail_private/__manifest__.py
  15. 5
      mail_private/doc/changelog.rst
  16. 4
      mail_private/full_composer_wizard.xml
  17. 15
      mail_private/i18n/mail_private.pot
  18. 58
      mail_private/models.py
  19. 10
      mail_private/static/src/css/mail_private.css
  20. 32
      mail_private/static/src/js/mail_private.js
  21. 25
      mail_private/static/src/xml/mail_private.xml
  22. 3
      mail_private/template.xml
  23. 1
      mail_private/tests/__init__.py
  24. 1
      mail_private/tests/test_js.py
  25. 2
      mail_to/__init__.py
  26. 7
      mail_to/__manifest__.py
  27. 6
      mail_to/doc/changelog.rst
  28. 19
      mail_to/i18n/mail_to.pot
  29. 1
      mail_to/models/__init__.py
  30. 17
      mail_to/models/mail_message.py
  31. 50
      mail_to/static/src/js/mail_to.js
  32. 20
      mail_to/static/src/js/test_mail_to.js
  33. 23
      mail_to/static/src/xml/recipient.xml
  34. 5
      mail_to/templates.xml
  35. 1
      mail_to/tests/__init__.py
  36. 24
      mail_to/tests/test_default.py

3
.travis.yml

@ -22,7 +22,8 @@ env:
matrix:
- LINT_CHECK="1"
- CHECK_TAGS="1"
- TESTS="1" ODOO_REPO="odoo/odoo" MAKEPOT="1"
- TESTS="1" ODOO_REPO="odoo/odoo"
- MAKEPOT="1"
- TESTS="1" ODOO_REPO="OCA/OCB"
install:

2
mail_base/README.rst

@ -7,7 +7,7 @@
* fixes toggling left bar
* fixes Recipients field. Out-of-box this field could be empty.
One can say, that the module do this todo from `addons/mail/static/src/js/chat_manager.js <https://github.com/odoo/odoo/blob/9.0/addons/mail/static/src/js/chat_manager.js#L57>`__
One can say, that the module do this todo from `addons/mail/static/src/js/chat_manager.js <https://github.com/odoo/odoo/blob/11.0/addons/mail/static/src/js/chat_manager.js#L57>`__
// to do: move this to mail.utils

1
mail_base/__init__.py

@ -1,3 +1,4 @@
# License LGPL-3.0 (https://www.gnu.org/licenses/lgpl.html)
from . import models
from . import controllers

6
mail_base/__manifest__.py

@ -1,9 +1,13 @@
# Copyright 2016 x620 <https://github.com/x620>
# Copyright 2018 Ruslan Ronzhin <https://it-projects.info/team/rusllan/>
# Copyright 2016-2019 Ivan Yelizariev <https://it-projects.info/team/yelizariev>
# License LGPL-3.0 (https://www.gnu.org/licenses/lgpl.html)
{
"name": "Mail Base",
"summary": """Makes Mail extendable""",
"category": "Discuss",
"images": [],
"version": "11.0.1.0.5",
"version": "11.0.1.1.0",
"author": "IT-Projects LLC, Pavel Romanchenko",
"support": "apps@it-projects.info",

3
mail_base/controllers/main.py

@ -1,3 +1,6 @@
# Copyright 2017 mikaelh <https://github.com/mikaelh>
# Copyright 2017-2019 Ivan Yelizariev <https://it-projects.info/team/yelizariev>
# License LGPL-3.0 (https://www.gnu.org/licenses/lgpl.html)
from openerp.http import request
from openerp.addons.bus.controllers.main import BusController

4
mail_base/doc/changelog.rst

@ -1,3 +1,7 @@
`1.1.0`
-------
- **New**: added ability to select channels for private message sending.
`1.0.5`
-------
**FIX**: polling errors on heavy server load

7
mail_base/models.py

@ -1,3 +1,6 @@
# Copyright 2016 x620 <https://github.com/x620>
# Copyright 2017 Ivan Yelizariev <https://it-projects.info/team/yelizariev>
# License LGPL-3.0 (https://www.gnu.org/licenses/lgpl.html)
from openerp import api, models
@ -12,8 +15,8 @@ class MailMessage(models.Model):
values['partner_ids'] = []
for triplet in values.get('needaction_partner_ids'):
if triplet[0] == 6:
for id in triplet[2]:
values['partner_ids'].append((4, id, False))
for i in triplet[2]:
values['partner_ids'].append((4, i, False))
return super(MailMessage, self).write(values)

3
mail_base/static/lib/base.js

@ -1,3 +1,6 @@
/* Copyright 2017 Artyom Losev <https://github.com/ArtyomLosev>
Copyright 2019 Artem Rafailov <https://github.com/Ommo73>
License LGPL-3.0 (https://www.gnu.org/licenses/lgpl.html). */
odoo.define('mail_base.base', function (require) {
"use strict";

6
mail_multi_website/README.rst

@ -2,9 +2,9 @@
:target: https://www.gnu.org/licenses/lgpl
:alt: License: LGPL-3
===========================================
Email Addresses and Templates per Website
===========================================
=====================
Multi-Brand Mailing
=====================
Mail-related stuff for multi-website support

2
mail_multi_website/__manifest__.py

@ -1,7 +1,7 @@
# Copyright 2018 Ivan Yelizariev <https://it-projects.info/team/yelizariev>
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
{
"name": """Email Addresses and Templates per Website""",
"name": """Multi-Brand Mailing""",
"summary": """Use single Backend to manage several Websites""",
"category": "Discuss",
# "live_test_url": "http://apps.it-projects.info/shop/product/website-multi-company?version=11.0",

6
mail_multi_website/doc/index.rst

@ -1,6 +1,6 @@
===========================================
Email Addresses and Templates per Website
===========================================
=====================
Multi-Brand Mailing
=====================
Installation
============

2
mail_multi_website/static/description/index.html

@ -1,7 +1,7 @@
<section class="oe_container">
<div class="oe_row oe_spaced">
<div class="oe_span12">
<h2 class="oe_slogan" style="color:#875A7B;">Email Addresses and Templates per Website
<h2 class="oe_slogan" style="color:#875A7B;">Multi-Brand Mailing
</h2>
<h3 class="oe_slogan">Use single Backend to manage several Websites</h3>
</div>

1
mail_private/__init__.py

@ -1,2 +1,3 @@
# License LGPL-3.0 (https://www.gnu.org/licenses/lgpl.html)
from . import models

10
mail_private/__manifest__.py

@ -1,9 +1,17 @@
# Copyright 2016 x620 <https://github.com/x620>
# Copyright 2016 Ilmir Karamov <https://it-projects.info/team/ilmir-k>
# Copyright 2016 Ivan Yelizariev <https://it-projects.info/team/yelizariev>
# Copyright 2017 Artyom Losev <https://github.com/ArtyomLosev>
# Copyright 2018 Ruslan Ronzhin <https://it-projects.info/team/rusllan/>
# Copyright 2018 Kolushov Alexandr <https://it-projects.info/team/KolushovAlexandr>
# Copyright 2019 Artem Rafailov <https://it-projects.info/team/Ommo73/>
# License LGPL-3.0 (https://www.gnu.org/licenses/lgpl.html).
{
"name": """Internal Messaging""",
"summary": """Send private messages to specified recipients, regardless of who are in followers list.""",
"category": "Discuss",
"images": ['images/mail_private_image.png'],
"version": "11.0.1.1.0",
"version": "11.0.1.2.0",
"application": False,
"author": "IT-Projects LLC, Pavel Romanchenko",

5
mail_private/doc/changelog.rst

@ -1,3 +1,8 @@
`1.2.0`
-------
- **New**: added ability to select channels for private message sending.
`1.1.0`
-------

4
mail_private/full_composer_wizard.xml

@ -1,4 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<!--Copyright 2017 Artyom Losev <https://github.com/ArtyomLosev>
Copyright 2018 Kolushov Alexandr <https://it-projects.info/team/KolushovAlexandr>
License LGPL-3.0 (https://www.gnu.org/licenses/lgpl.html).-->
<odoo>
<record model="ir.ui.view" id="email_compose_message_wizard_form_private">

15
mail_private/i18n/mail_private.pot

@ -34,6 +34,11 @@ msgstr ""
msgid "Dummy action"
msgstr ""
#. module: mail_private
#: model:ir.model,name:mail_private.model_mail_thread
msgid "Email Thread"
msgstr ""
#. module: mail_private
#: model:ir.model,name:mail_private.model_mail_compose_message
msgid "Email composition wizard"
@ -60,7 +65,7 @@ msgstr ""
#. module: mail_private
#. openerp-web
#: code:addons/mail_private/static/src/xml/mail_private.xml:6
#: code:addons/mail_private/static/src/xml/mail_private.xml:12
#, python-format
msgid "Send a message to specified recipients only"
msgstr ""
@ -75,21 +80,21 @@ msgstr ""
#. module: mail_private
#. openerp-web
#: code:addons/mail_private/static/src/xml/mail_private.xml:6
#: code:addons/mail_private/static/src/xml/mail_private.xml:12
#, python-format
msgid "Send internal message"
msgstr ""
#. module: mail_private
#. openerp-web
#: code:addons/mail_private/static/src/xml/mail_private.xml:12
#: code:addons/mail_private/static/src/xml/mail_private.xml:18
#, python-format
msgid "To: Followers of"
msgstr ""
#. module: mail_private
#. openerp-web
#: code:addons/mail_private/static/src/xml/mail_private.xml:23
#: code:addons/mail_private/static/src/xml/mail_private.xml:39
#, python-format
msgid "Uncheck all"
msgstr ""
@ -110,7 +115,7 @@ msgstr ""
#. module: mail_private
#. openerp-web
#: code:addons/mail_private/static/src/xml/mail_private.xml:17
#: code:addons/mail_private/static/src/xml/mail_private.xml:23
#, python-format
msgid "this document"
msgstr ""

58
mail_private/models.py

@ -1,3 +1,9 @@
# Copyright 2016 x620 <https://github.com/x620>
# Copyright 2016 manawi <https://github.com/manawi>
# Copyright 2017 Artyom Losev <https://github.com/ArtyomLosev>
# 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, fields, api
@ -13,17 +19,16 @@ class MailMessage(models.Model):
is_private = fields.Boolean(string='Send Internal Message')
def send_recepients_for_internal_message(self, model, domain):
result = []
result = {'partners': [], 'channels': []}
default_resource = self.env[model].search(domain)
follower_ids = default_resource.message_follower_ids
internal_ids = self.get_internal_users_ids()
recipient_ids = [r.partner_id for r in follower_ids if r.partner_id]
# channel_ids = [c.channel_id for c in follower_ids if c.channel_id]
channel_ids = [c.channel_id for c in follower_ids if c.channel_id]
for recipient in recipient_ids:
result.append({
'checked': recipient.user_ids.id in internal_ids,
result['partners'].append({
'checked': recipient.user_ids.id and not any(recipient.user_ids.mapped('share')),
'partner_id': recipient.id,
'full_name': recipient.name,
'name': recipient.name,
@ -31,14 +36,14 @@ class MailMessage(models.Model):
'reason': 'Recipient'
})
# for channel in channel_ids:
# result.append({
# 'checked': True,
# 'channel_id': channel.id,
# 'full_name': channel,
# 'name': '# '+channel.name,
# 'reason': 'Channel',
# })
for channel in channel_ids:
result['channels'].append({
'checked': True,
'channel_id': channel.id,
'full_name': channel.name,
'name': '# '+channel.name,
'reason': 'Channel',
})
return result
@api.multi
@ -54,7 +59,6 @@ class MailMessage(models.Model):
""" Compute recipients to notify based on specified recipients and document
followers. Delegate notification to partners to send emails and bus notifications
and to channels to broadcast messages on channels """
group_user = self.env.ref('base.group_user')
# have a sudoed copy to manipulate partners (public can go here with website modules like forum / blog / ... )
self_sudo = self.sudo()
@ -62,16 +66,6 @@ class MailMessage(models.Model):
partners_sudo = self_sudo.partner_ids
channels_sudo = self_sudo.channel_ids
if self_sudo.subtype_id and self.model and self.res_id:
followers = self_sudo.env['mail.followers'].search([
('res_model', '=', self.model),
('res_id', '=', self.res_id),
('subtype_ids', 'in', self_sudo.subtype_id.id),
])
if self_sudo.subtype_id.internal:
followers = followers.filtered(lambda fol: fol.channel_id or (fol.partner_id.user_ids and group_user in fol.partner_id.user_ids[0].mapped('groups_id')))
channels_sudo |= followers.mapped('channel_id')
# remove author from notified partners
if not self._context.get('mail_notify_author', False) and self_sudo.author_id:
partners_sudo = partners_sudo - self_sudo.author_id
@ -108,6 +102,16 @@ class MailMessage(models.Model):
return True
def get_internal_users_ids(self):
internal_users_ids = self.env['res.users'].search([('share', '=', False)]).ids
return internal_users_ids
class MailThread(models.AbstractModel):
_inherit = 'mail.thread'
@api.multi
@api.returns('self', lambda value: value.id)
def message_post(self, body='', subject=None, message_type='notification', subtype=None, parent_id=False,
attachments=None, content_subtype='html', **kwargs):
if 'channel_ids' in kwargs:
kwargs['channel_ids'] = [(4, pid) for pid in kwargs['channel_ids']]
return super(MailThread, self).message_post(body, subject, message_type,
subtype, parent_id, attachments,
content_subtype, **kwargs)

10
mail_private/static/src/css/mail_private.css

@ -0,0 +1,10 @@
.o_composer_suggested_channels{
margin-top: -5px;
}
.oe_composer_uncheck{
float: bottom;
margin-top:5px;
margin-left:-5px;
}

32
mail_private/static/src/js/mail_private.js

@ -1,8 +1,9 @@
/* Copyright 2016-2018 Ivan Yelizariev <https://it-projects.info/team/yelizariev>
Copyright 2016 manavi <https://github.com/manawi>
Copyright 2017-2018 Artyom Losev <https://github.com/ArtyomLosev>
Copyright 2018 Kolushov Alexandr <https://it-projects.info/team/KolushovAlexandr>
License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). */
/* Copyright 2016 x620 <https://github.com/x620>
Copyright 2016 Ivan Yelizariev <https://it-projects.info/team/yelizariev>
Copyright 2016 manawi <https://github.com/manawi>
Copyright 2017 Artyom Losev <https://github.com/ArtyomLosev>
Copyright 2019 Artem Rafailov <https://it-projects.info/team/Ommo73/>
License LGPL-3.0 (https://www.gnu.org/licenses/lgpl.html). */
odoo.define('mail_private', function (require) {
'use strict';
@ -29,7 +30,8 @@ Chatter.include({
this.fetch_recipients_for_internal_message().then(function (data) {
self._openComposer({
is_private: true,
suggested_partners: data
suggested_partners: data["partners"],
suggested_channels: data["channels"],
});
});
},
@ -48,7 +50,8 @@ Chatter.include({
record_name: this.record_name,
default_body: old_composer && old_composer.$input && old_composer.$input.val(),
default_mention_selections: old_composer && old_composer.mention_get_listener_selections(),
is_private: options.is_private
is_private: options.is_private,
suggested_channels: options.suggested_channels
});
this.composer.on('input_focused', this, function () {
this.composer.mention_set_prefetched_partners(this.mentionSuggestions || []);
@ -64,6 +67,7 @@ Chatter.include({
self.composer.on('post_message', self, function (message) {
if (options.is_private) {
self.composer.options.is_log = true;
self.composer.options.is_private = options.is_private;
}
self.fields.thread.postMessage(message).then(function () {
@ -94,16 +98,18 @@ Chatter.include({
method: 'send_recepients_for_internal_message',
args: [[], self.context.default_model, follower_ids_domain]
}).then(function (res) {
return _.filter(res, function (obj) {
res["partners"] = _.filter(res["partners"], function (obj) {
return obj.partner_id !== session.partner_id;
});
return res;
});
}
},
});
ChatterComposer.include({
init: function (parent, model, suggested_partners, options) {
this._super(parent, model, suggested_partners, options);
this.suggested_channels = options.suggested_channels;
this.events['click .oe_composer_uncheck'] = 'on_uncheck_recipients';
if (typeof options.is_private === 'undefined') {
// otherwise it causes an error in context creating function
@ -154,6 +160,9 @@ ChatterComposer.include({
this.$('.o_composer_suggested_partners input:checked').each(function() {
$(this).prop('checked', false);
});
this.$('.o_composer_suggested_channels input:checked').each(function() {
$(this).prop('checked', false);
});
},
on_open_full_composer: function() {
@ -215,16 +224,15 @@ ChatterComposer.include({
checked_partners = _.uniq(_.filter(checked_partners, function (obj) {
return obj.reason !== 'Channel';
}));
this.get_checked_channel_ids();
return checked_partners;
},
get_checked_channel_ids: function () {
var self = this;
var checked_channels = [];
this.$('.o_composer_suggested_partners input:checked').each(function() {
this.$('.o_composer_suggested_channels input:checked').each(function() {
var full_name = $(this).data('fullname');
checked_channels = checked_channels.concat(_.filter(self.suggested_partners, function(item) {
checked_channels = checked_channels.concat(_.filter(self.suggested_channels, function(item) {
return full_name === item.full_name;
}));
});

25
mail_private/static/src/xml/mail_private.xml

@ -1,9 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--Copyright 2016 x620 <https://github.com/x620>
Copyright 2016 Ivan Yelizariev <https://it-projects.info/team/yelizariev>
Copyright 2016 manawi <https://github.com/manawi>
Copyright 2017 Artyom Losev <https://github.com/ArtyomLosev>
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.Chatter.Buttons">
<t t-jquery="button[title='Send a message']" t-operation="after">
<button class="btn btn-sm btn-link oe_compose_post_private" title="Send a message to specified recipients only">Send internal message</button>
<button t-if="new_message_btn" class="btn btn-sm btn-link oe_compose_post_private" title="Send a message to specified recipients only">Send internal message</button>
</t>
</t>
@ -20,7 +26,22 @@
</small>
</t>
<t t-jquery="div[class='o_composer_suggested_partners']" t-operation="after">
<button class="btn btn-sm btn-link oe_composer_uncheck" t-if="widget.options.is_private">Uncheck all</button>
<div class="o_composer_suggested_channels">
<t t-if="widget.suggested_channels">
<t t-foreach='widget.suggested_channels' t-as='channel'>
<div t-attf-title="Add as channel and follower">
<div class="o_checkbox">
<input type="checkbox"
t-att-checked="channel.checked ? 'checked' : undefined"
t-att-data-fullname="channel.full_name"/>
<span/>
</div>
<t t-esc="channel.name"/>
</div>
</t>
</t>
<button class="btn btn-sm btn-link oe_composer_uncheck" t-if="widget.options.is_private">Uncheck all</button>
</div>
</t>
</t>

3
mail_private/template.xml

@ -1,10 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<!--Copyright 2016 x620 <https://github.com/x620>
License LGPL-3.0 (https://www.gnu.org/licenses/lgpl.html).-->
<odoo>
<template
id="assets_backend"
name="mail_private_assets_backend"
inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<link rel="stylesheet" href="/mail_private/static/src/css/mail_private.css"/>
<script
type="text/javascript"
src="/mail_private/static/src/js/mail_private.js"></script>

1
mail_private/tests/__init__.py

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
from . import test_js

1
mail_private/tests/test_js.py

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2018 Kolushov Alexandr <https://it-projects.info/team/KolushovAlexandr>
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).

2
mail_to/__init__.py

@ -0,0 +1,2 @@
# License LGPL-3.0 (https://www.gnu.org/licenses/lgpl.html).
from . import models

7
mail_to/__manifest__.py

@ -1,9 +1,14 @@
# 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": "11.0.1.0.1",
"version": "11.0.1.1.0",
"author": "IT-Projects LLC, Pavel Romanchenko",
"support": "apps@it-projects.info",

6
mail_to/doc/changelog.rst

@ -1,3 +1,9 @@
`1.1.0`
-------
- **New**: channels are displayed in recipients
`1.0.1`
-------

19
mail_to/i18n/mail_to.pot

@ -13,23 +13,36 @@ msgstr ""
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"
#. module: mail_to
#: model:ir.model,name:mail_to.model_mail_message
msgid "Message"
msgstr ""
#. module: mail_to
#. openerp-web
#: code:addons/mail_to/static/src/js/test_mail_to.js:13
#, python-format
msgid "Open Partners Form From Recipient Link"
msgstr ""
#. module: mail_to
#. openerp-web
#: code:addons/mail_to/static/src/xml/recipient.xml:6
#: code:addons/mail_to/static/src/xml/recipient.xml:10
#: code:addons/mail_to/static/src/xml/recipient.xml:11
#, python-format
msgid "To:"
msgstr ""
#. module: mail_to
#. openerp-web
#: code:addons/mail_to/static/src/xml/recipient.xml:15
#: code:addons/mail_to/static/src/xml/recipient.xml:32
#, python-format
msgid "and"
msgstr ""
#. module: mail_to
#. openerp-web
#: code:addons/mail_to/static/src/xml/recipient.xml:16
#: code:addons/mail_to/static/src/xml/recipient.xml:33
#, python-format
msgid "more"
msgstr ""

1
mail_to/models/__init__.py

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

17
mail_to/models/mail_message.py

@ -0,0 +1,17 @@
# 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):
messages_values = super(MailMessage, self).message_format()
for i in messages_values:
if i['channel_ids']:
i['channel_names'] = self.env['mail.channel'].browse(i['channel_ids']).mapped(
lambda r: [r.id, '#' + r.display_name])
return messages_values

50
mail_to/static/src/js/mail_to.js

@ -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";
@ -5,26 +10,31 @@ var chat_manager = require('mail_base.base').chat_manager;
var make_message_super = chat_manager.make_message;
chat_manager.make_message = function (data) {
var msg = make_message_super.call(this, data);
msg.partner_ids = data.partner_ids;
if (!msg.partner_ids) {
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 += '; ';
var msg = make_message_super.call(this, data);
msg.partner_ids = data.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;
}
}
}
msg.more_recipients = more_recipients;
return msg;
};
var more_recipients = '';
// value which define more recipients
msg.more_recipients_value = 4;
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;
};
return chat_manager;
});

20
mail_to/static/src/js/test_mail_to.js

@ -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
mail_to/static/src/xml/recipient.xml

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

5
mail_to/templates.xml

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

1
mail_to/tests/__init__.py

@ -1 +1,2 @@
# License LGPL-3.0 (https://www.gnu.org/licenses/lgpl.html).
from . import test_default

24
mail_to/tests/test_default.py

@ -1,18 +1,20 @@
# 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(False)
@odoo.tests.common.at_install(True)
@odoo.tests.common.post_install(True)
class TestUi(odoo.tests.HttpCase):
def test_01_mail_to(self):
# checks the presence of an element with a link to the recipient
# TODO: instead of timeout, try to put $('a.recipient_link') as ready argument of phantom_js (third parameter)
code = """
setTimeout(function () {
$('a.recipient_link')[0].click();
console.log('ok');
}, 1000);
"""
link = '/web#action=%s' % self.ref('mail.mail_channel_action_client_chat')
self.phantom_js(link, code, "odoo.__DEBUG__.services['mail_to.MailTo']", login="admin")
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)
Loading…
Cancel
Save