-
diff --git a/addons/crm/crm_lead.py b/addons/crm/crm_lead.py
index ddfdb05ca66..fff47205582 100644
--- a/addons/crm/crm_lead.py
+++ b/addons/crm/crm_lead.py
@@ -27,13 +27,15 @@ import time
import tools
from tools.translate import _
+from base.res.res_partner import format_address
+
CRM_LEAD_PENDING_STATES = (
crm.AVAILABLE_STATES[2][0], # Cancelled
crm.AVAILABLE_STATES[3][0], # Done
crm.AVAILABLE_STATES[4][0], # Pending
)
-class crm_lead(base_stage, osv.osv):
+class crm_lead(base_stage, format_address, osv.osv):
""" CRM Lead Case """
_name = "crm.lead"
_description = "Lead/Opportunity"
@@ -105,6 +107,12 @@ class crm_lead(base_stage, osv.osv):
return result, fold
+ def fields_view_get(self, cr, user, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
+ res = super(crm_lead,self).fields_view_get(cr, user, view_id, view_type, context, toolbar=toolbar, submenu=submenu)
+ if view_type == 'form':
+ res['arch'] = self.fields_view_get_address(cr, user, res['arch'], context=context)
+ return res
+
_group_by_full = {
'stage_id': _read_group_stage_ids
}
diff --git a/addons/email_template/tests/test_mail.py b/addons/email_template/tests/test_mail.py
index 85ab3afc902..1091c34ad5c 100644
--- a/addons/email_template/tests/test_mail.py
+++ b/addons/email_template/tests/test_mail.py
@@ -20,17 +20,10 @@
##############################################################################
import base64
-from openerp.tests import common
+from openerp.addons.mail.tests import test_mail
-class test_message_compose(common.TransactionCase):
- def _mock_smtp_gateway(self, *args, **kwargs):
- return True
-
- def _mock_build_email(self, *args, **kwargs):
- self._build_email_args = args
- self._build_email_kwargs = kwargs
- return self.build_email_real(*args, **kwargs)
+class test_message_compose(test_mail.TestMailMockups):
def setUp(self):
super(test_message_compose, self).setUp()
@@ -40,11 +33,6 @@ class test_message_compose(common.TransactionCase):
self.res_users = self.registry('res.users')
self.res_partner = self.registry('res.partner')
- # Install mock SMTP gateway
- self.build_email_real = self.registry('ir.mail_server').build_email
- self.registry('ir.mail_server').build_email = self._mock_build_email
- self.registry('ir.mail_server').send_email = self._mock_smtp_gateway
-
# create a 'pigs' and 'bird' groups that will be used through the various tests
self.group_pigs_id = self.mail_group.create(self.cr, self.uid,
{'name': 'Pigs', 'description': 'Fans of Pigs, unite !'})
diff --git a/addons/mail/__openerp__.py b/addons/mail/__openerp__.py
index 08a98cb0a02..f0ab2c67bcf 100644
--- a/addons/mail/__openerp__.py
+++ b/addons/mail/__openerp__.py
@@ -61,6 +61,7 @@ The main features of the module are:
'website': 'http://www.openerp.com',
'depends': ['base', 'base_tools', 'base_setup'],
'data': [
+ 'wizard/invite_view.xml',
'wizard/mail_compose_message_view.xml',
'res_config_view.xml',
'mail_message_view.xml',
diff --git a/addons/mail/mail_followers.py b/addons/mail/mail_followers.py
index 2aba685c4fa..b8f6c21ecf5 100644
--- a/addons/mail/mail_followers.py
+++ b/addons/mail/mail_followers.py
@@ -23,6 +23,7 @@ from osv import osv
from osv import fields
import tools
+
class mail_followers(osv.Model):
""" mail_followers holds the data related to the follow mechanism inside
OpenERP. Partners can choose to follow documents (records) of any kind
@@ -84,16 +85,44 @@ class mail_notification(osv.Model):
notif_ids = self.search(cr, uid, [('partner_id', '=', partner_id), ('message_id', '=', msg_id)], context=context)
return self.write(cr, uid, notif_ids, {'read': True}, context=context)
+ def get_partners_to_notify(self, cr, uid, partner_ids, message, context=None):
+ """ Return the list of partners to notify, based on their preferences.
+
+ :param browse_record message: mail.message to notify
+ """
+ notify_pids = []
+ for partner in self.pool.get('res.partner').browse(cr, uid, partner_ids, context=context):
+ # Do not send an email to the writer
+ if partner.user_ids and partner.user_ids[0].id == uid:
+ continue
+ # Do not send to partners without email address defined
+ if not partner.email:
+ continue
+ # Partner does not want to receive any emails
+ if partner.notification_email_send == 'none':
+ continue
+ # Partner wants to receive only emails and comments
+ if partner.notification_email_send == 'comment' and message.type not in ('email', 'comment'):
+ continue
+ # Partner wants to receive only emails
+ if partner.notification_email_send == 'email' and message.type != 'email':
+ continue
+ notify_pids.append(partner.id)
+ return notify_pids
+
def notify(self, cr, uid, partner_ids, msg_id, context=None):
""" Send by email the notification depending on the user preferences """
context = context or {}
# mail_noemail (do not send email) or no partner_ids: do not send, return
if context.get('mail_noemail') or not partner_ids:
return True
-
- mail_mail = self.pool.get('mail.mail')
msg = self.pool.get('mail.message').browse(cr, uid, msg_id, context=context)
+ notify_partner_ids = self.get_partners_to_notify(cr, uid, partner_ids, msg, context=context)
+ if not notify_partner_ids:
+ return True
+
+ mail_mail = self.pool.get('mail.mail')
# add signature
body_html = msg.body
signature = msg.author_id and msg.author_id.user_ids[0].signature or ''
@@ -107,27 +136,6 @@ class mail_notification(osv.Model):
'body_html': body_html,
'state': 'outgoing',
}
-
- for partner in self.pool.get('res.partner').browse(cr, uid, partner_ids, context=context):
- # Do not send an email to the writer
- if partner.user_ids and partner.user_ids[0].id == uid:
- continue
- # Do not send to partners without email address defined
- if not partner.email:
- continue
- # Partner does not want to receive any emails
- if partner.notification_email_send == 'none':
- continue
- # Partner wants to receive only emails and comments
- if partner.notification_email_send == 'comment' and msg.type not in ('email', 'comment'):
- continue
- # Partner wants to receive only emails
- if partner.notification_email_send == 'email' and msg.type != 'email':
- continue
- if partner.email not in mail_values['email_to']:
- mail_values['email_to'].append(partner.email)
- if mail_values['email_to']:
- mail_values['email_to'] = ', '.join(mail_values['email_to'])
- email_notif_id = mail_mail.create(cr, uid, mail_values, context=context)
- mail_mail.send(cr, uid, [email_notif_id], context=context)
- return True
+ mail_values['email_to'] = ', '.join(mail_values['email_to'])
+ email_notif_id = mail_mail.create(cr, uid, mail_values, context=context)
+ return mail_mail.send(cr, uid, [email_notif_id], recipient_ids=notify_partner_ids, context=context)
diff --git a/addons/mail/mail_group.py b/addons/mail/mail_group.py
index 175ce650f06..fe0cc3950ae 100644
--- a/addons/mail/mail_group.py
+++ b/addons/mail/mail_group.py
@@ -19,13 +19,11 @@
#
##############################################################################
-import datetime as DT
import openerp
import openerp.tools as tools
-from operator import itemgetter
from osv import osv
from osv import fields
-from tools.translate import _
+
class mail_group(osv.Model):
""" A mail_group is a collection of users sharing messages in a discussion
@@ -47,7 +45,7 @@ class mail_group(osv.Model):
_columns = {
'description': fields.text('Description'),
'menu_id': fields.many2one('ir.ui.menu', string='Related Menu', required=True, ondelete="cascade"),
- 'public': fields.selection([('public','Public'),('private','Private'),('groups','Selected Group Only')], 'Privacy', required=True,
+ 'public': fields.selection([('public', 'Public'), ('private', 'Private'), ('groups', 'Selected Group Only')], 'Privacy', required=True,
help='This group is visible by non members. \
Invisible groups can add members through the invite button.'),
'group_public_id': fields.many2one('res.groups', string='Authorized Group'),
@@ -126,14 +124,14 @@ class mail_group(osv.Model):
search_ref = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'mail', 'view_message_search')
params = {
'search_view_id': search_ref and search_ref[1] or False,
- 'domain': [('model','=','mail.group'), ('res_id','=',mail_group_id)],
+ 'domain': [('model', '=', 'mail.group'), ('res_id', '=', mail_group_id)],
'context': {'default_model': 'mail.group', 'default_res_id': mail_group_id},
'res_model': 'mail.message',
'thread_level': 1,
}
cobj = self.pool.get('ir.actions.client')
newref = cobj.copy(cr, uid, ref[1], default={'params': str(params), 'name': vals['name']}, context=context)
- self.write(cr, uid, [mail_group_id], {'action': 'ir.actions.client,'+str(newref), 'mail_group_id': mail_group_id}, context=context)
+ self.write(cr, uid, [mail_group_id], {'action': 'ir.actions.client,' + str(newref), 'mail_group_id': mail_group_id}, context=context)
mail_alias.write(cr, uid, [vals['alias_id']], {"alias_force_thread_id": mail_group_id}, context)
@@ -142,9 +140,13 @@ class mail_group(osv.Model):
return mail_group_id
def unlink(self, cr, uid, ids, context=None):
+ groups = self.browse(cr, uid, ids, context=context)
# Cascade-delete mail aliases as well, as they should not exist without the mail group.
mail_alias = self.pool.get('mail.alias')
- alias_ids = [group.alias_id.id for group in self.browse(cr, uid, ids, context=context) if group.alias_id]
+ alias_ids = [group.alias_id.id for group in groups if group.alias_id]
+ # Cascade-delete menu entries as well
+ self.pool.get('ir.ui.menu').unlink(cr, uid, [group.menu_id.id for group in groups if group.menu_id], context=context)
+ # Delete mail_group
res = super(mail_group, self).unlink(cr, uid, ids, context=context)
mail_alias.unlink(cr, uid, alias_ids, context=context)
return res
diff --git a/addons/mail/mail_mail.py b/addons/mail/mail_mail.py
index 7b593c5b998..6bbfa9bc30e 100644
--- a/addons/mail/mail_mail.py
+++ b/addons/mail/mail_mail.py
@@ -30,6 +30,7 @@ from tools.translate import _
_logger = logging.getLogger(__name__)
+
class mail_mail(osv.Model):
""" Model holding RFC2822 email messages to send. This model also provides
facilities to queue and send new email messages. """
@@ -58,8 +59,8 @@ class mail_mail(osv.Model):
'body_html': fields.text('Rich-text Contents', help="Rich-text/HTML message"),
# Auto-detected based on create() - if 'mail_message_id' was passed then this mail is a notification
- # and during unlink() we will cascade delete the parent and its attachments
- 'notification': fields.boolean('Is Notification')
+ # and during unlink() we will not cascade delete the parent and its attachments
+ 'notification': fields.boolean('Is Notification')
}
def _get_default_from(self, cr, uid, context=None):
@@ -76,21 +77,21 @@ class mail_mail(osv.Model):
def create(self, cr, uid, values, context=None):
if 'notification' not in values and values.get('mail_message_id'):
values['notification'] = True
- return super(mail_mail,self).create(cr, uid, values, context=context)
+ return super(mail_mail, self).create(cr, uid, values, context=context)
def unlink(self, cr, uid, ids, context=None):
# cascade-delete the parent message for all mails that are not created for a notification
- ids_to_cascade = self.search(cr, uid, [('notification','=',False),('id','in',ids)])
+ ids_to_cascade = self.search(cr, uid, [('notification', '=', False), ('id', 'in', ids)])
parent_msg_ids = [m.mail_message_id.id for m in self.browse(cr, uid, ids_to_cascade, context=context)]
- res = super(mail_mail,self).unlink(cr, uid, ids, context=context)
+ res = super(mail_mail, self).unlink(cr, uid, ids, context=context)
self.pool.get('mail.message').unlink(cr, uid, parent_msg_ids, context=context)
return res
def mark_outgoing(self, cr, uid, ids, context=None):
- return self.write(cr, uid, ids, {'state':'outgoing'}, context=context)
+ return self.write(cr, uid, ids, {'state': 'outgoing'}, context=context)
def cancel(self, cr, uid, ids, context=None):
- return self.write(cr, uid, ids, {'state':'cancel'}, context=context)
+ return self.write(cr, uid, ids, {'state': 'cancel'}, context=context)
def process_email_queue(self, cr, uid, ids=None, context=None):
"""Send immediately queued messages, committing after each
@@ -127,7 +128,7 @@ class mail_mail(osv.Model):
"""Perform any post-processing necessary after sending ``mail``
successfully, including deleting it completely along with its
attachment if the ``auto_delete`` flag of the mail was set.
- Overridden by subclasses for extra post-processing behaviors.
+ Overridden by subclasses for extra post-processing behaviors.
:param browse_record mail: the mail that was just sent
:return: True
@@ -136,14 +137,46 @@ class mail_mail(osv.Model):
mail.unlink()
return True
- def _send_get_mail_subject(self, cr, uid, mail, force=False, context=None):
- """ if void and related document: '
posted on '
- :param mail: mail.mail browse_record """
+ def send_get_mail_subject(self, cr, uid, mail, force=False, partner=None, context=None):
+ """ If subject is void and record_name defined: ' posted on '
+
+ :param boolean force: force the subject replacement
+ :param browse_record mail: mail.mail browse_record
+ :param browse_record partner: specific recipient partner
+ """
if force or (not mail.subject and mail.model and mail.res_id):
return '%s posted on %s' % (mail.author_id.name, mail.record_name)
return mail.subject
- def send(self, cr, uid, ids, auto_commit=False, context=None):
+ def send_get_mail_body(self, cr, uid, mail, partner=None, context=None):
+ """ Return a specific ir_email body. The main purpose of this method
+ is to be inherited by Portal, to add a link for signing in, in
+ each notification email a partner receives.
+
+ :param browse_record mail: mail.mail browse_record
+ :param browse_record partner: specific recipient partner
+ """
+ return mail.body_html
+
+ def send_get_email_dict(self, cr, uid, mail, partner=None, context=None):
+ """ Return a dictionary for specific email values, depending on a
+ partner, or generic to the whole recipients given by mail.email_to.
+
+ :param browse_record mail: mail.mail browse_record
+ :param browse_record partner: specific recipient partner
+ """
+ body = self.send_get_mail_body(cr, uid, mail, partner=partner, context=context)
+ subject = self.send_get_mail_subject(cr, uid, mail, partner=partner, context=context)
+ body_alternative = tools.html2plaintext(body)
+ email_to = [partner.email] if partner else tools.email_split(mail.email_to)
+ return {
+ 'body': body,
+ 'body_alternative': body_alternative,
+ 'subject': subject,
+ 'email_to': email_to,
+ }
+
+ def send(self, cr, uid, ids, auto_commit=False, recipient_ids=None, context=None):
""" Sends the selected emails immediately, ignoring their current
state (mails that have already been sent should not be passed
unless they should actually be re-sent).
@@ -154,50 +187,55 @@ class mail_mail(osv.Model):
:param bool auto_commit: whether to force a commit of the mail status
after sending each mail (meant only for scheduler processing);
should never be True during normal transactions (default: False)
+ :param list recipient_ids: specific list of res.partner recipients.
+ If set, one email is sent to each partner. Its is possible to
+ tune the sent email through ``send_get_mail_body`` and ``send_get_mail_subject``.
+ If not specified, one email is sent to mail_mail.email_to.
:return: True
"""
ir_mail_server = self.pool.get('ir.mail_server')
for mail in self.browse(cr, uid, ids, context=context):
try:
- body = mail.body_html
- subject = self._send_get_mail_subject(cr, uid, mail, context=context)
-
# handle attachments
attachments = []
for attach in mail.attachment_ids:
attachments.append((attach.datas_fname, base64.b64decode(attach.datas)))
-
- # use only sanitized html and set its plaintexted version as alternative
- body_alternative = tools.html2plaintext(body)
- content_subtype_alternative = 'plain'
+ # specific behavior to customize the send email for notified partners
+ email_list = []
+ if recipient_ids:
+ for partner in self.pool.get('res.partner').browse(cr, uid, recipient_ids, context=context):
+ email_list.append(self.send_get_email_dict(cr, uid, mail, partner=partner, context=context))
+ else:
+ email_list.append(self.send_get_email_dict(cr, uid, mail, context=context))
# build an RFC2822 email.message.Message object and send it without queuing
- msg = ir_mail_server.build_email(
- email_from = mail.email_from,
- email_to = tools.email_split(mail.email_to),
- subject = subject,
- body = body,
- body_alternative = body_alternative,
- email_cc = tools.email_split(mail.email_cc),
- reply_to = mail.reply_to,
- attachments = attachments,
- message_id = mail.message_id,
- references = mail.references,
- object_id = mail.res_id and ('%s-%s' % (mail.res_id, mail.model)),
- subtype = 'html',
- subtype_alternative = content_subtype_alternative)
- res = ir_mail_server.send_email(cr, uid, msg,
- mail_server_id=mail.mail_server_id.id, context=context)
+ for email in email_list:
+ msg = ir_mail_server.build_email(
+ email_from = mail.email_from,
+ email_to = email.get('email_to'),
+ subject = email.get('subject'),
+ body = email.get('body'),
+ body_alternative = email.get('body_alternative'),
+ email_cc = tools.email_split(mail.email_cc),
+ reply_to = mail.reply_to,
+ attachments = attachments,
+ message_id = mail.message_id,
+ references = mail.references,
+ object_id = mail.res_id and ('%s-%s' % (mail.res_id, mail.model)),
+ subtype = 'html',
+ subtype_alternative = 'plain')
+ res = ir_mail_server.send_email(cr, uid, msg,
+ mail_server_id=mail.mail_server_id.id, context=context)
if res:
- mail.write({'state':'sent', 'message_id': res})
+ mail.write({'state': 'sent', 'message_id': res})
else:
- mail.write({'state':'exception'})
+ mail.write({'state': 'exception'})
mail.refresh()
if mail.state == 'sent':
self._postprocess_sent_message(cr, uid, mail, context=context)
except Exception:
_logger.exception('failed sending mail.mail %s', mail.id)
- mail.write({'state':'exception'})
+ mail.write({'state': 'exception'})
if auto_commit == True:
cr.commit()
diff --git a/addons/mail/mail_message.py b/addons/mail/mail_message.py
index 18a88bb0b61..44ce76b94b0 100644
--- a/addons/mail/mail_message.py
+++ b/addons/mail/mail_message.py
@@ -20,11 +20,13 @@
##############################################################################
import logging
+import openerp
import tools
from email.header import decode_header
from operator import itemgetter
from osv import osv, fields
+from tools.translate import _
_logger = logging.getLogger(__name__)
@@ -35,6 +37,7 @@ def decode(text):
text = decode_header(text.replace('\r', ''))
return ''.join([tools.ustr(x[0], x[1]) for x in text])
+
class mail_message(osv.Model):
""" Messages model: system notification (replacing res.log notifications),
comments (OpenChatter discussion) and incoming emails. """
@@ -57,7 +60,10 @@ class mail_message(osv.Model):
for message in self.browse(cr, uid, ids, context=context):
if not message.model or not message.res_id:
continue
- result[message.id] = self._shorten_name(self.pool.get(message.model).name_get(cr, uid, [message.res_id], context=context)[0][1])
+ try:
+ result[message.id] = self._shorten_name(self.pool.get(message.model).name_get(cr, uid, [message.res_id], context=context)[0][1])
+ except openerp.exceptions.AccessDenied, e:
+ pass
return result
def _get_unread(self, cr, uid, ids, name, arg, context=None):
@@ -341,3 +347,25 @@ class mail_message(osv.Model):
default = {}
default.update(message_id=False, headers=False)
return super(mail_message, self).copy(cr, uid, id, default=default, context=context)
+
+ #------------------------------------------------------
+ # Tools
+ #------------------------------------------------------
+
+ def check_partners_email(self, cr, uid, partner_ids, context=None):
+ """ Verify that selected partner_ids have an email_address defined.
+ Otherwise throw a warning. """
+ partner_wo_email_lst = []
+ for partner in self.pool.get('res.partner').browse(cr, uid, partner_ids, context=context):
+ if not partner.email:
+ partner_wo_email_lst.append(partner)
+ if not partner_wo_email_lst:
+ return {}
+ warning_msg = _('The following partners chosen as recipients for the email have no email address linked :')
+ for partner in partner_wo_email_lst:
+ warning_msg += '\n- %s' % (partner.name)
+ return {'warning': {
+ 'title': _('Partners email addresses not found'),
+ 'message': warning_msg,
+ }
+ }
diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py
index c0d6ac90fe6..d798007275f 100644
--- a/addons/mail/mail_thread.py
+++ b/addons/mail/mail_thread.py
@@ -623,14 +623,8 @@ class mail_thread(osv.AbstractModel):
return self.message_subscribe(cr, uid, ids, partner_ids, context=context)
def message_subscribe(self, cr, uid, ids, partner_ids, context=None):
- """ Add partners to the records followers.
- :param partner_ids: a list of partner_ids to subscribe
- :param return: new value of followers if read_back key in context
- """
- self.write(cr, uid, ids, {'message_follower_ids': [(4, pid) for pid in partner_ids]}, context=context)
- if context and context.get('read_back'):
- return [follower.id for thread in self.browse(cr, uid, ids, context=context) for follower in thread.message_follower_ids]
- return []
+ """ Add partners to the records followers. """
+ return self.write(cr, uid, ids, {'message_follower_ids': [(4, pid) for pid in partner_ids]}, context=context)
def message_unsubscribe_users(self, cr, uid, ids, user_ids=None, context=None):
""" Wrapper on message_subscribe, using users. If user_ids is not
@@ -640,14 +634,8 @@ class mail_thread(osv.AbstractModel):
return self.message_unsubscribe(cr, uid, ids, partner_ids, context=context)
def message_unsubscribe(self, cr, uid, ids, partner_ids, context=None):
- """ Remove partners from the records followers.
- :param partner_ids: a list of partner_ids to unsubscribe
- :param return: new value of followers if read_back key in context
- """
- self.write(cr, uid, ids, {'message_follower_ids': [(3, pid) for pid in partner_ids]}, context=context)
- if context and context.get('read_back'):
- return [follower.id for thread in self.browse(cr, uid, ids, context=context) for follower in thread.message_follower_ids]
- return []
+ """ Remove partners from the records followers. """
+ return self.write(cr, uid, ids, {'message_follower_ids': [(3, pid) for pid in partner_ids]}, context=context)
#------------------------------------------------------
# Thread state
diff --git a/addons/mail/res_users.py b/addons/mail/res_users.py
index f9ca54c478d..8bbe075f159 100644
--- a/addons/mail/res_users.py
+++ b/addons/mail/res_users.py
@@ -72,6 +72,9 @@ class res_users(osv.Model):
def create(self, cr, uid, data, context=None):
# create default alias same as the login
+ if not data.get('login', False):
+ raise osv.except_osv(_('Invalid Action!'), _('You may not create a user.'))
+
mail_alias = self.pool.get('mail.alias')
alias_id = mail_alias.create_unique_alias(cr, uid, {'alias_name': data['login']}, model_name=self._name, context=context)
data['alias_id'] = alias_id
diff --git a/addons/mail/static/src/css/mail.css b/addons/mail/static/src/css/mail.css
index 92ead6f2432..48a178732b0 100644
--- a/addons/mail/static/src/css/mail.css
+++ b/addons/mail/static/src/css/mail.css
@@ -96,10 +96,6 @@
width: 120px;
}
-.openerp button.oe_mail_button_followers {
- display: inline;
-}
-
.openerp button.oe_mail_button_mouseout {
color: white;
background-color: #8a89ba;
diff --git a/addons/mail/static/src/js/mail_followers.js b/addons/mail/static/src/js/mail_followers.js
index 34976269285..cf33bd64640 100644
--- a/addons/mail/static/src/js/mail_followers.js
+++ b/addons/mail/static/src/js/mail_followers.js
@@ -31,33 +31,52 @@ openerp_mail_followers = function(session, mail) {
},
start: function() {
- var self = this;
- // NB: all the widget should be modified to check the actual_mode property on view, not use
- // any other method to know if the view is in create mode anymore
+ // use actual_mode property on view to know if the view is in create mode anymore
this.view.on("change:actual_mode", this, this._check_visibility);
this._check_visibility();
- this.$el.find('button.oe_mail_button_follow').click(function () { self.do_follow(); })
- .mouseover(function () { $(this).html('Follow').removeClass('oe_mail_button_mouseout').addClass('oe_mail_button_mouseover'); })
- .mouseleave(function () { $(this).html('Not following').removeClass('oe_mail_button_mouseover').addClass('oe_mail_button_mouseout'); });
- this.$el.find('button.oe_mail_button_unfollow').click(function () { self.do_unfollow(); })
- .mouseover(function () { $(this).html('Unfollow').removeClass('oe_mail_button_mouseout').addClass('oe_mail_button_mouseover'); })
- .mouseleave(function () { $(this).html('Following').removeClass('oe_mail_button_mouseover').addClass('oe_mail_button_mouseout'); });
this.reinit();
+ this.bind_events();
},
_check_visibility: function() {
this.$el.toggle(this.view.get("actual_mode") !== "create");
},
- destroy: function () {
- this._super.apply(this, arguments);
- },
-
reinit: function() {
this.$el.find('button.oe_mail_button_follow').hide();
this.$el.find('button.oe_mail_button_unfollow').hide();
},
+ bind_events: function() {
+ var self = this;
+ this.$('button.oe_mail_button_unfollow').on('click', function () { self.do_unfollow(); })
+ .mouseover(function () { $(this).html('Unfollow').removeClass('oe_mail_button_mouseout').addClass('oe_mail_button_mouseover'); })
+ .mouseleave(function () { $(this).html('Following').removeClass('oe_mail_button_mouseover').addClass('oe_mail_button_mouseout'); });
+ this.$el.on('click', 'button.oe_mail_button_follow', function () { self.do_follow(); });
+ this.$el.on('click', 'button.oe_mail_button_invite', function(event) {
+ action = {
+ type: 'ir.actions.act_window',
+ res_model: 'mail.wizard.invite',
+ view_mode: 'form',
+ view_type: 'form',
+ views: [[false, 'form']],
+ target: 'new',
+ context: {
+ 'default_res_model': self.view.dataset.model,
+ 'default_res_id': self.view.datarecord.id
+ },
+ }
+ self.do_action(action, function() { self.read_value(); });
+ });
+ },
+
+ read_value: function() {
+ var self = this;
+ return this.ds_model.read_ids([this.view.datarecord.id], ['message_follower_ids']).pipe(function (results) {
+ return results[0].message_follower_ids;
+ }).pipe(this.proxy('set_value'));
+ },
+
set_value: function(value_) {
this.reinit();
if (! this.view.datarecord.id ||
@@ -65,11 +84,11 @@ openerp_mail_followers = function(session, mail) {
this.$el.find('div.oe_mail_recthread_aside').hide();
return;
}
- return this.fetch_followers(value_);
+ return this.fetch_followers(value_ || this.get_value());
},
fetch_followers: function (value_) {
- return this.ds_follow.call('read', [value_ || this.get_value(), ['name', 'user_ids']]).then(this.proxy('display_followers'));
+ return this.ds_follow.call('read', [value_, ['name', 'user_ids']]).pipe(this.proxy('display_followers'));
},
/** Display the followers, evaluate is_follower directly */
@@ -91,13 +110,13 @@ openerp_mail_followers = function(session, mail) {
},
do_follow: function () {
- var context = new session.web.CompoundContext(this.build_context(), {'read_back': true});
- return this.ds_model.call('message_subscribe_users', [[this.view.datarecord.id], undefined, context]).pipe(this.proxy('set_value'));
+ var context = new session.web.CompoundContext(this.build_context(), {});
+ return this.ds_model.call('message_subscribe_users', [[this.view.datarecord.id], undefined, context]).pipe(this.proxy('read_value'));
},
do_unfollow: function () {
- var context = new session.web.CompoundContext(this.build_context(), {'read_back': true});
- return this.ds_model.call('message_unsubscribe_users', [[this.view.datarecord.id], undefined, context]).pipe(this.proxy('set_value'));
+ var context = new session.web.CompoundContext(this.build_context(), {});
+ return this.ds_model.call('message_unsubscribe_users', [[this.view.datarecord.id], undefined, context]).pipe(this.proxy('read_value'));
},
});
};
diff --git a/addons/mail/static/src/xml/mail.xml b/addons/mail/static/src/xml/mail.xml
index 4d3b56cf62f..bf339f21f1c 100644
--- a/addons/mail/static/src/xml/mail.xml
+++ b/addons/mail/static/src/xml/mail.xml
@@ -114,7 +114,7 @@
-