Browse Source

[FIX] sent.js correction set_channel_flags() and get_domain() methods for correct sent messages filtration

[FIX] base.js correction "cls" to "chat_manager.mail_tools"
[FIX] models.py correction _get_sent() method and remove outdated notification method
[REF] menu.xml move "sent" menu item to after "inbox" menu item and change icon
pull/6/head
x620 9 years ago
parent
commit
74fa3eda6a
  1. 12
      mail_base/static/src/js/base.js
  2. 2
      mail_sent/__init__.py
  3. 26
      mail_sent/models.py
  4. 1
      mail_sent/models/__init__.py
  5. 13
      mail_sent/static/src/js/sent.js
  6. 4
      mail_sent/static/src/xml/menu.xml
  7. 38
      mail_sent/views.xml

12
mail_base/static/src/js/base.js

@ -160,9 +160,9 @@ var MailTools = core.Class.extend({
_.each(msg.channel_ids, function (channel_id) { _.each(msg.channel_ids, function (channel_id) {
var channel = chat_manager.get_channel(channel_id); var channel = chat_manager.get_channel(channel_id);
if (channel) { if (channel) {
cls.add_to_cache(msg, []);
chat_manager.mail_tools.add_to_cache(msg, []);
if (options.domain && options.domain !== []) { if (options.domain && options.domain !== []) {
cls.add_to_cache(msg, options.domain);
chat_manager.mail_tools.add_to_cache(msg, options.domain);
} }
if (channel.hidden) { if (channel.hidden) {
channel.hidden = false; channel.hidden = false;
@ -412,7 +412,7 @@ var MailTools = core.Class.extend({
_.each(message.channel_ids, function (channel_id) { _.each(message.channel_ids, function (channel_id) {
var channel = chat_manager.get_channel(channel_id); var channel = chat_manager.get_channel(channel_id);
if (channel) { if (channel) {
var channel_cache = cls.get_channel_cache(channel, domain);
var channel_cache = chat_manager.mail_tools.get_channel_cache(channel, domain);
var index = _.sortedIndex(channel_cache.messages, message, 'id'); var index = _.sortedIndex(channel_cache.messages, message, 'id');
if (channel_cache.messages[index] !== message) { if (channel_cache.messages[index] !== message) {
channel_cache.messages.splice(index, 0, message); channel_cache.messages.splice(index, 0, message);
@ -586,12 +586,12 @@ var MailTools = core.Class.extend({
_.each(data.message_ids, function (msg_id) { _.each(data.message_ids, function (msg_id) {
var message = _.findWhere(messages, { id: msg_id }); var message = _.findWhere(messages, { id: msg_id });
if (message) { if (message) {
cls.invalidate_caches(message.channel_ids);
chat_manager.mail_tools.invalidate_caches(message.channel_ids);
message.is_starred = data.starred; message.is_starred = data.starred;
if (!message.is_starred) { if (!message.is_starred) {
cls.remove_message_from_channel("channel_starred", message);
chat_manager.mail_tools.remove_message_from_channel("channel_starred", message);
} else { } else {
cls.add_to_cache(message, []);
chat_manager.mail_tools.add_to_cache(message, []);
var channel_starred = chat_manager.get_channel('channel_starred'); var channel_starred = chat_manager.get_channel('channel_starred');
channel_starred.cache = _.pick(channel_starred.cache, "[]"); channel_starred.cache = _.pick(channel_starred.cache, "[]");
} }

2
mail_sent/__init__.py

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

26
mail_sent/models.py

@ -1,28 +1,22 @@
# -*- coding: utf-8 -*-
from openerp import api, models, fields from openerp import api, models, fields
class mail_message(models.Model):
class MailMessage(models.Model):
_inherit = 'mail.message' _inherit = 'mail.message'
sent = fields.Boolean('Sent', compute="_get_sent", help='Was message sent to someone', store=True)
@api.one @api.one
@api.depends('author_id', 'notified_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.notified_partner_ids) > 1 or len(self_sudo.notified_partner_ids) == 1 and self_sudo.author_id and self_sudo.notified_partner_ids[0].id != self_sudo.author_id.id
sent = fields.Boolean('Sent', compute=_get_sent, help='Was message sent to someone', store=True)
class mail_notification(models.Model):
_inherit = 'mail.notification'
self_sudo.sent = len(self_sudo.partner_ids) > 1 \
or len(self_sudo.partner_ids) == 1 \
and self_sudo.author_id \
and self_sudo.partner_ids[0].id != self_sudo.author_id.id
def _notify(self, cr, uid, message_id, **kwargs):
super(mail_notification, self)._notify(cr, uid, message_id, **kwargs)
self.pool['mail.message'].browse(cr, uid, message_id)._get_sent()
class mail_compose_message(models.TransientModel):
class MailComposeMessage(models.TransientModel):
_inherit = 'mail.compose.message' _inherit = 'mail.compose.message'
sent = fields.Boolean('Sent', help='dummy field to fix inherit error') sent = fields.Boolean('Sent', help='dummy field to fix inherit error')

1
mail_sent/models/__init__.py

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

13
mail_sent/static/src/js/sent.js

@ -20,13 +20,15 @@ var _t = core._t;
base_obj.MailTools.include({ base_obj.MailTools.include({
get_properties: function(msg){ get_properties: function(msg){
var properties = this._super.apply(this, arguments); var properties = this._super.apply(this, arguments);
properties.is_archive = this.property_descr("channel_sent", msg, this);
properties.is_sent = this.property_descr("channel_sent", msg, this);
return properties; return properties;
}, },
set_channel_flags: function(data, msg){ set_channel_flags: function(data, msg){
this._super.apply(this, arguments); this._super.apply(this, arguments);
msg.is_archive = true;
if (_.contains(data.author_id, session.partner_id) && data.partner_ids.length > 0) {
msg.is_sent = true;
}
return msg; return msg;
}, },
@ -36,12 +38,15 @@ base_obj.MailTools.include({
}, },
get_domain: function(channel){ get_domain: function(channel){
return (channel.id === "channel_sent") ? [] : this._super.apply(this, arguments);
return (channel.id === "channel_sent") ? [
['sent', '=', true],
['author_id.user_ids', 'in', [openerp.session.uid]]
] : this._super.apply(this, arguments);
} }
}); });
base_obj.chat_manager.is_ready.then(function(){ base_obj.chat_manager.is_ready.then(function(){
// Add archive 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: _t("Sent"),

4
mail_sent/static/src/xml/menu.xml

@ -2,9 +2,9 @@
<template> <template>
<!--Inherit Sidebar and add Sent menu item after Starred --> <!--Inherit Sidebar and add Sent menu item after Starred -->
<t t-extend="mail.chat.Sidebar"> <t t-extend="mail.chat.Sidebar">
<t t-jquery="div[data-channel-id=channel_starred]" t-operation="after">
<t t-jquery="div[data-channel-id=channel_inbox]" t-operation="after">
<div t-attf-class="o_mail_chat_channel_item #{(active_channel_id == 'channel_sent') ? 'o_active': ''}" data-channel-id="channel_sent"> <div t-attf-class="o_mail_chat_channel_item #{(active_channel_id == 'channel_sent') ? 'o_active': ''}" data-channel-id="channel_sent">
<span class="o_channel_name"> <i class="fa fa-send"/> Sent </span>
<span class="o_channel_name"> <i class="fa fa-send-o"/> Sent </span>
</div> </div>
</t> </t>
</t> </t>

38
mail_sent/views.xml

@ -1,38 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="action_mail_sent_feeds" model="ir.actions.client">
<field name="name">Sent</field>
<field name="tag">mail.wall</field>
<field name="context">{
'default_model': 'res.users',
'default_res_id': uid,
'thread_model': 'res.partner',
'needaction_menu_ref': ['mail.mail_tomefeeds', 'mail.mail_starfeeds', 'mail.mail_inboxfeeds']
}</field>
<field name="params" eval="&quot;{
'domain': [
('author_id.user_ids', 'in', [uid]),
('sent', '=', True),
],
'view_mailbox': True,
'show_compose_message': False
}&quot;"/>
<field name="help" type="html">
<p>
No message found and no message sent yet.
</p><p>
Click on the top-right icon to compose a message. This
message will be sent by email if it's an internal contact.
</p>
</field>
</record>
<record id="mail_sentfeeds" model="ir.ui.menu">
<field name="name">Sent</field>
<field name="sequence" eval="10"/>
<field name="action" ref="action_mail_sent_feeds"/>
<field name="parent_id" ref="mail.mail_feeds"/>
</record>
</data>
</openerp>
Loading…
Cancel
Save