Browse Source

Merge pull request #38 from x620/mail-addons-9.0-res_partner_mails_count

[PORT] to 9.0 Sendbox
pull/6/head
Ivan Yelizariev 8 years ago
parent
commit
486053060b
  1. 2
      mail_archives/README.rst
  2. 4
      mail_archives/__openerp__.py
  3. 12
      mail_base/static/src/js/base.js
  4. 12
      mail_sent/README.rst
  5. 2
      mail_sent/__init__.py
  6. 35
      mail_sent/__openerp__.py
  7. 40
      mail_sent/models.py
  8. BIN
      mail_sent/static/description/menu.png
  9. BIN
      mail_sent/static/description/messages.png
  10. 61
      mail_sent/static/src/js/sent.js
  11. 20
      mail_sent/static/src/xml/menu.xml
  12. 38
      mail_sent/views.xml
  13. 12
      mail_sent/views/templates.xml

2
mail_archives/README.rst

@ -5,7 +5,7 @@ Adds Archive menu, which shows all messages
Usage
-----
Click Messaing/Arhive menu -- all messages are displayed
Click Discuss/Archive menu -- all messages are displayed
Further information
-------------------

4
mail_archives/__openerp__.py

@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
{
"name": "mail_archives",
"summary": """Create archive channel""",
"category": "Uncategorized",
"summary": """Adds menu to find old messages""",
"category": "Discuss",
"images": [],
"version": "1.0.0",

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

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

12
mail_sent/README.rst

@ -1,8 +1,16 @@
Sentbox
=======
Description: https://apps.odoo.com/apps/modules/8.0/mail_sent/
Adds Sent menu, which shows sent messages
Usage
-----
Click Discuss/Sent menu -- sent messages are displayed
Further information
-------------------
Further information and discussion: https://yelizariev.github.io/odoo/module/2015/02/19/sentbox.html
Tested on Odoo 8.0 231e02693640325c9a05fa31c680063b9e4b017b
HTML Description: https://apps.odoo.com/apps/modules/9.0/mail_sent/
Tested on Odoo 9.0 b9f206953e3f877adf18643f154d1262842564ee

2
mail_sent/__init__.py

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

35
mail_sent/__openerp__.py

@ -1,15 +1,28 @@
# -*- coding: utf-8 -*-
{
'name' : 'Sentbox',
'version' : '1.0.2',
'author' : 'IT-Projects LLC, Ivan Yelizariev',
'license': 'LGPL-3',
'category' : 'Social Network',
'website' : 'https://twitter.com/yelizariev',
"name": "Sentbox",
"summary": """Quick way to find sent messages""",
"category": "Discuss",
"images": [],
"version": "1.0.3",
"author": "IT-Projects LLC, Ivan Yelizariev, Pavel Romanchenko",
"website": "https://it-projects.info",
"license": "LGPL-3",
'price': 9.00,
'currency': 'EUR',
'depends' : ['mail'],
'data':[
'views.xml',
],
'installable': False
"depends": [
"base",
"mail",
"mail_base"
],
"data": [
"views/templates.xml",
],
"qweb": [
"static/src/xml/menu.xml",
],
'installable': True,
}

40
mail_sent/models.py

@ -1,28 +1,32 @@
# -*- coding: utf-8 -*-
from openerp import api, models, fields
class mail_message(models.Model):
class MailMessage(models.Model):
_inherit = 'mail.message'
sent = fields.Boolean('Sent', compute="_get_sent", help='Was message sent to someone', store=True)
@api.one
@api.depends('author_id', 'notified_partner_ids')
@api.depends('author_id', 'needaction_partner_ids')
def _get_sent(self):
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'
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):
self_sudo.sent = len(self_sudo.needaction_partner_ids) > 1 \
or len(self_sudo.needaction_partner_ids) == 1 \
and self_sudo.author_id \
and self_sudo.needaction_partner_ids[0].id != self_sudo.author_id.id
@api.multi
def message_format(self):
message_values = super(MailMessage, self).message_format()
message_index = {message['id']: message for message in message_values}
for item in self:
msg = message_index.get(item.id)
if msg:
msg['sent'] = item.sent
return message_values
class MailComposeMessage(models.TransientModel):
_inherit = 'mail.compose.message'
sent = fields.Boolean('Sent', help='dummy field to fix inherit error')

BIN
mail_sent/static/description/menu.png

Before

Width: 217  |  Height: 167  |  Size: 5.8 KiB

After

Width: 217  |  Height: 167  |  Size: 8.9 KiB

BIN
mail_sent/static/description/messages.png

Before

Width: 625  |  Height: 217  |  Size: 37 KiB

After

Width: 625  |  Height: 217  |  Size: 39 KiB

61
mail_sent/static/src/js/sent.js

@ -0,0 +1,61 @@
odoo.define('mail_sent.sent', function (require) {
"use strict";
var base_obj = require('mail_base.base');
//-------------------------------------------------------------------------------
var bus = require('bus.bus').bus;
var config = require('web.config');
var core = require('web.core');
var data = require('web.data');
var Model = require('web.Model');
var session = require('web.session');
var time = require('web.time');
var web_client = require('web.web_client');
var _t = core._t;
//-------------------------------------------------------------------------------
// Inherit class and override methods
base_obj.MailTools.include({
get_properties: function(msg){
var properties = this._super.apply(this, arguments);
properties.is_sent = this.property_descr("channel_sent", msg, this);
return properties;
},
set_channel_flags: function(data, msg){
this._super.apply(this, arguments);
if (data.sent && data.author_id[0] == session.partner_id) {
msg.is_sent = true;
}
return msg;
},
get_channel_array: function(msg){
var arr = this._super.apply(this, arguments);
return arr.concat('channel_sent');
},
get_domain: function(channel){
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(){
// Add sent channel
base_obj.chat_manager.mail_tools.add_channel({
id: "channel_sent",
name: _t("Sent"),
type: "static"
});
return $.when();
});
return base_obj.chat_manager;
});

20
mail_sent/static/src/xml/menu.xml

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<template>
<!--Inherit Sidebar and add Sent menu item after Starred -->
<t t-extend="mail.chat.Sidebar">
<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">
<span class="o_channel_name"> <i class="fa fa-send-o"/> Sent </span>
</div>
</t>
</t>
<!--Add message about empty sent page-->
<t t-extend="mail.EmptyChannel">
<t t-jquery="t:last-child" t-operation="after">
<t t-if="options.channel_id==='channel_sent'">
<div class="o_thread_title">No sent messages</div>
<div>You can send messages and then these messages will appear here.</div>
</t>
</t>
</t>
</template>

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>

12
mail_sent/views/templates.xml

@ -0,0 +1,12 @@
<?xml version="1.0"?>
<openerp>
<data>
<template id="mail_sent_assets_backend"
name="mail_sent_assets_backend"
inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script src="/mail_sent/static/src/js/sent.js" type="text/javascript"></script>
</xpath>
</template>
</data>
</openerp>
Loading…
Cancel
Save