Browse Source

Merge pull request #12 from x620/9.0-res_partner_mails_count

[ADD] add mail_to and fix mail_base
pull/23/head
Ivan Yelizariev 9 years ago
parent
commit
4b41641fc7
  1. 4
      mail_archives/static/src/js/archives.js
  2. 3
      mail_base/README.rst
  3. 2
      mail_base/__init__.py
  4. 18
      mail_base/models.py
  5. 15
      mail_base/static/src/js/base.js
  6. 8
      mail_sent/models.py
  7. 4
      mail_sent/static/src/js/sent.js
  8. 11
      mail_to/README.rst
  9. 1
      mail_to/__init__.py
  10. 28
      mail_to/__openerp__.py
  11. 7
      mail_to/doc/changelog.rst
  12. 12
      mail_to/doc/index.rst
  13. 23
      mail_to/static/src/css/mail_to.css
  14. 29
      mail_to/static/src/js/mail_to.js
  15. 22
      mail_to/static/src/xml/recipient.xml
  16. 13
      mail_to/templates.xml

4
mail_archives/static/src/js/archives.js

@ -13,7 +13,7 @@ var session = require('web.session');
var time = require('web.time'); var time = require('web.time');
var web_client = require('web.web_client'); var web_client = require('web.web_client');
var _t = core._t;
var _lt = core._lt;
//------------------------------------------------------------------------------- //-------------------------------------------------------------------------------
// Inherit class and override methods // Inherit class and override methods
@ -44,7 +44,7 @@ base_obj.chat_manager.is_ready.then(function(){
// Add archive channel // Add archive channel
base_obj.chat_manager.mail_tools.add_channel({ base_obj.chat_manager.mail_tools.add_channel({
id: "channel_archive", id: "channel_archive",
name: _t("Archive"),
name: _lt("Archive"),
type: "static" type: "static"
}); });

3
mail_base/README.rst

@ -2,8 +2,9 @@ Mail Base
========= =========
* makes built-in mail js features extendable. * makes built-in mail js features extendable.
* handle ``search_default_*`` parameters in context.
* handles ``search_default_*`` parameters in context.
* fixes toggling left bar * fixes toggling left bar
* fixes Recipients field. Out-of-box this field could be empty.
Usage Usage
----- -----

2
mail_base/__init__.py

@ -1 +1,3 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import models

18
mail_base/models.py

@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
from openerp import api, models
class MailMessage(models.Model):
_inherit = 'mail.message'
@api.multi
def write(self, values):
if values.get('needaction_partner_ids'):
if not values.get('partner_ids'):
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))
return super(MailMessage, self).write(values)

15
mail_base/static/src/js/base.js

@ -11,6 +11,7 @@ var time = require('web.time');
var web_client = require('web.web_client'); var web_client = require('web.web_client');
var _t = core._t; var _t = core._t;
var _lt = core._lt;
var LIMIT = 100; var LIMIT = 100;
var preview_msg_max_size = 350; // optimal for native english speakers var preview_msg_max_size = 350; // optimal for native english speakers
@ -354,7 +355,7 @@ var MailTools = core.Class.extend({
} else { } else {
channel = chat_manager.mail_tools.make_channel(data, options); channel = chat_manager.mail_tools.make_channel(data, options);
channels.push(channel); channels.push(channel);
channels = _.sortBy(channels, function (channel) { return channel.name.toLowerCase(); });
channels = _.sortBy(channels, function (channel) { return _.isString(channel.name) ? channel.name.toLowerCase() : '' });
if (!options.silent) { if (!options.silent) {
chat_manager.bus.trigger("new_channel", channel); chat_manager.bus.trigger("new_channel", channel);
} }
@ -845,7 +846,7 @@ chat_manager.undo_mark_as_read = function (message_ids, channel) {
chat_manager.mark_channel_as_seen = function (channel) { chat_manager.mark_channel_as_seen = function (channel) {
if (channel.unread_counter > 0 && channel.type !== 'static') { if (channel.unread_counter > 0 && channel.type !== 'static') {
chat_manager.mail_tools.update_channel_unread_counter(channel, 0); chat_manager.mail_tools.update_channel_unread_counter(channel, 0);
chat_manager.mail_tools.channel_seen(channel);
channel_seen(channel);
} }
}; };
chat_manager.get_channels = function () { chat_manager.get_channels = function () {
@ -1043,7 +1044,7 @@ chat_manager.get_channels_preview = function (channels) {
}); });
}; };
chat_manager.get_message_body_preview = function (message_body) { chat_manager.get_message_body_preview = function (message_body) {
return chat_manager.mail_tools.parse_and_transform(message_body, inline);
return chat_manager.mail_tools.parse_and_transform(message_body, chat_manager.mail_tools.inline);
}; };
chat_manager.search_partner = function (search_val, limit) { chat_manager.search_partner = function (search_val, limit) {
return PartnerModel.call('im_search', [search_val, limit || 20], {}, {shadow: true}).then(function(result) { return PartnerModel.call('im_search', [search_val, limit || 20], {}, {shadow: true}).then(function(result) {
@ -1059,7 +1060,7 @@ chat_manager.search_partner = function (search_val, limit) {
}); });
}; };
chat_manager.send_native_notification = function(){ chat_manager.send_native_notification = function(){
chat_manager.mail_tools.send_native_notification.apply(chat_manager.mail_tools, arguments)
return chat_manager.mail_tools.send_native_notification.apply(chat_manager.mail_tools, arguments)
}; };
chat_manager.bus.on('client_action_open', null, function (open) { chat_manager.bus.on('client_action_open', null, function (open) {
client_action_open = open; client_action_open = open;
@ -1069,13 +1070,13 @@ chat_manager.bus.on('client_action_open', null, function (open) {
function init(){ function init(){
chat_manager.mail_tools.add_channel({ chat_manager.mail_tools.add_channel({
id: "channel_inbox", id: "channel_inbox",
name: _t("Inbox"),
name: _lt("Inbox"),
type: "static" type: "static"
}, { display_needactions: true }); }, { display_needactions: true });
chat_manager.mail_tools.add_channel({ chat_manager.mail_tools.add_channel({
id: "channel_starred", id: "channel_starred",
name: _t("Starred"),
name: _lt("Starred"),
type: "static" type: "static"
}); });
@ -1098,6 +1099,8 @@ function init(){
var load_menu_id = ir_model.call("xmlid_to_res_id", ["mail.mail_channel_menu_root_chat"], {}, {shadow: true}); var load_menu_id = ir_model.call("xmlid_to_res_id", ["mail.mail_channel_menu_root_chat"], {}, {shadow: true});
var load_action_id = ir_model.call("xmlid_to_res_id", ["mail.mail_channel_action_client_chat"], {}, {shadow: true}); var load_action_id = ir_model.call("xmlid_to_res_id", ["mail.mail_channel_action_client_chat"], {}, {shadow: true});
// unsubscribe and then subscribe to the event, to avoid duplication of new messages
bus.off('notification');
bus.on('notification', null, chat_manager.mail_tools.on_notification); bus.on('notification', null, chat_manager.mail_tools.on_notification);
return $.when(load_menu_id, load_action_id, load_channels, load_emojis).then(function (menu_id, action_id) { return $.when(load_menu_id, load_action_id, load_channels, load_emojis).then(function (menu_id, action_id) {

8
mail_sent/models.py

@ -8,13 +8,13 @@ class MailMessage(models.Model):
sent = fields.Boolean('Sent', compute="_get_sent", help='Was message sent to someone', store=True) sent = fields.Boolean('Sent', compute="_get_sent", help='Was message sent to someone', store=True)
@api.one @api.one
@api.depends('author_id', 'needaction_partner_ids')
@api.depends('author_id', 'partner_ids')
def _get_sent(self): def _get_sent(self):
self_sudo = self.sudo() self_sudo = self.sudo()
self_sudo.sent = len(self_sudo.needaction_partner_ids) > 1 \
or len(self_sudo.needaction_partner_ids) == 1 \
self_sudo.sent = len(self_sudo.partner_ids) > 1 \
or len(self_sudo.partner_ids) == 1 \
and self_sudo.author_id \ and self_sudo.author_id \
and self_sudo.needaction_partner_ids[0].id != self_sudo.author_id.id
and self_sudo.partner_ids[0].id != self_sudo.author_id.id
@api.multi @api.multi
def message_format(self): def message_format(self):

4
mail_sent/static/src/js/sent.js

@ -13,7 +13,7 @@ var session = require('web.session');
var time = require('web.time'); var time = require('web.time');
var web_client = require('web.web_client'); var web_client = require('web.web_client');
var _t = core._t;
var _lt = core._lt;
//------------------------------------------------------------------------------- //-------------------------------------------------------------------------------
// Inherit class and override methods // Inherit class and override methods
@ -49,7 +49,7 @@ base_obj.chat_manager.is_ready.then(function(){
// Add sent channel // Add sent channel
base_obj.chat_manager.mail_tools.add_channel({ base_obj.chat_manager.mail_tools.add_channel({
id: "channel_sent", id: "channel_sent",
name: _t("Sent"),
name: _lt("Sent"),
type: "static" type: "static"
}); });

11
mail_to/README.rst

@ -0,0 +1,11 @@
=========================
Show message recipients
=========================
Allows you be sure, that all discussion participants were notified. Adds recipients label the right of message.
Further information
-------------------
HTML Description: https://apps.odoo.com/apps/modules/9.0/mail_to/
Tested on Odoo 9.0 d3dd4161ad0598ebaa659fbd083457c77aa9448d

1
mail_to/__init__.py

@ -0,0 +1 @@
# -*- coding: utf-8 -*-

28
mail_to/__openerp__.py

@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
{
"name": """Show message recipients""",
"summary": """Allows you be sure, that all discussion participants were notified""",
"category": "Discuss",
"images": [],
"version": "1.0.0",
"author": "IT-Projects LLC, Pavel Romanchenko",
"website": "https://it-projects.info",
"license": "LGPL-3",
#"price": 9.00,
#"currency": "EUR",
"depends": [
'mail_base',
],
"external_dependencies": {"python": [], "bin": []},
"data": [
'templates.xml',
],
"qweb": [
'static/src/xml/recipient.xml',
],
"demo": [],
"installable": True,
"auto_install": False,
}

7
mail_to/doc/changelog.rst

@ -0,0 +1,7 @@
Changelog
=========
`1.0.0`
-------
- Init version

12
mail_to/doc/index.rst

@ -0,0 +1,12 @@
=========================
Show message recipients
=========================
Usage
=====
* Open Discuss menu.
* Many messages have Recipients info.
* Click Inbox left menu item, click Send mail button, set recipient and send message. This message will show recipient.
* To see the recipient's need hover the mouse over a message.
* For messages created before install module it will not work where the recipients are not set. There is no way to restore recipients value.

23
mail_to/static/src/css/mail_to.css

@ -0,0 +1,23 @@
.recipient_link {
color: grey;
}
.recipient_link:hover {
color: #0d0d0d;
}
.o_mail_thread .o_thread_message span.recipients_info,
.o_mail_thread .o_thread_message i.o_thread_message_star,
.o_mail_thread .o_thread_message i.o_thread_message_reply,
.o_mail_thread .o_thread_message i.o_thread_message_needaction {
opacity: 0.4;
}
.o_mail_thread .o_thread_message:hover i.o_thread_message_star,
.o_mail_thread .o_thread_message:hover i.o_thread_message_reply,
.o_mail_thread .o_thread_message:hover i.o_thread_message_needaction {
opacity: 0.7;
}
.o_mail_thread .o_thread_message:hover span.recipients_info {
opacity: 1;
}

29
mail_to/static/src/js/mail_to.js

@ -0,0 +1,29 @@
odoo.define('mail_to.MailTo', function (require) {
"use strict";
var base_obj = require('mail_base.base');
base_obj.MailTools.include({
make_message: function(data){
var msg = this._super(data);
msg.partner_ids = data.partner_ids;
// msg.needaction_partner_ids = data.needaction_partner_ids;
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 += '; ';
}
}
}
msg.more_recipients = more_recipients;
return msg;
}
});
});

22
mail_to/static/src/xml/recipient.xml

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<template>
<t t-extend="mail.ChatThread.Message">
<t t-jquery="p[class=o_mail_info]>span" t-operation="after">
<span class="recipients_info">
<t t-if="message.partner_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>
</a>
</t>
</t>
<t t-if="message.partner_ids.length &gt; message.more_recipients_value - 1">
<span t-att-title="message.more_recipients">
and <t t-esc="message.partner_ids.length - message.more_recipients_value"/> more
</span>
</t>
</span>
</t>
</t>
</template>

13
mail_to/templates.xml

@ -0,0 +1,13 @@
<?xml version="1.0"?>
<openerp>
<data>
<template id="mail_to_assets_backend"
name="mail_to_assets_backend"
inherit_id="web.assets_backend">
<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>
</xpath>
</template>
</data>
</openerp>
Loading…
Cancel
Save