summaryrefslogtreecommitdiff
path: root/addons/mail
diff options
context:
space:
mode:
authorFabien Pinckaers <fp@openerp.com>2012-08-15 20:57:13 +0200
committerFabien Pinckaers <fp@openerp.com>2012-08-15 20:57:13 +0200
commitd820e866ee2ce0a69a268c0302cbbeb45e5b0f50 (patch)
treec3e88ba65e7990d5306c87c49c23431100bb4310 /addons/mail
parenta4f9b6ca0971aa5aca6fa30342e6acb950f42c3b (diff)
parent50275e9ec945ba6865a09e9cd708793018bed0dd (diff)
[MERGE] trunk
bzr revid: fp@openerp.com-20120815185713-82zylb0yqqgs008y
Diffstat (limited to 'addons/mail')
-rw-r--r--addons/mail/__init__.py2
-rw-r--r--addons/mail/data/mail_group_data.xml2
-rw-r--r--addons/mail/mail_message.py7
-rw-r--r--addons/mail/mail_thread.py2
-rw-r--r--addons/mail/res_partner.py18
-rw-r--r--addons/mail/res_users.py95
-rw-r--r--addons/mail/res_users_view.xml11
-rw-r--r--addons/mail/static/src/js/mail.js1
-rw-r--r--addons/mail/wizard/mail_compose_message.py6
9 files changed, 90 insertions, 54 deletions
diff --git a/addons/mail/__init__.py b/addons/mail/__init__.py
index 9c1f0d70f6f..54e20a6a9ef 100644
--- a/addons/mail/__init__.py
+++ b/addons/mail/__init__.py
@@ -25,8 +25,8 @@ import mail_mail
import mail_thread
import mail_group
import mail_subscription
-import res_users
import res_partner
+import res_users
import report
import wizard
import res_config
diff --git a/addons/mail/data/mail_group_data.xml b/addons/mail/data/mail_group_data.xml
index 443b43b62d6..2152706d056 100644
--- a/addons/mail/data/mail_group_data.xml
+++ b/addons/mail/data/mail_group_data.xml
@@ -19,7 +19,7 @@
<value>Welcome to OpenERP!</value>
<value>Your homepage is a summary of messages you received and key information about documents you follow.
-The top menu bar contains all applications you installed. You can use this &lt;i&gt;Settings&lt;/i&gt; menu to intall more applications, activate others features or give access to new users.
+The top menu bar contains all applications you installed. You can use this &lt;i&gt;Settings&lt;/i&gt; menu to install more applications, activate others features or give access to new users.
To setup your preferences (name, email signature, avatar), click on the top right corner.</value>
</function>
diff --git a/addons/mail/mail_message.py b/addons/mail/mail_message.py
index 1262cbb9fc7..5994f971deb 100644
--- a/addons/mail/mail_message.py
+++ b/addons/mail/mail_message.py
@@ -70,6 +70,9 @@ class mail_message(osv.Model):
return result
def name_get(self, cr, uid, ids, context=None):
+ # name_get may receive int id instead of an id list
+ if isinstance(ids, (int, long)):
+ ids = [ids]
res = []
for message in self.browse(cr, uid, ids, context=context):
name = ''
@@ -96,11 +99,10 @@ class mail_message(osv.Model):
# this is redundant with notifications ? Yes
'partner_ids': fields.many2many('res.partner',
- 'mail_message_destination_partner_rel',
+ 'mail_message_res_partner_rel',
'message_id', 'partner_id', 'Destination partners',
help="When sending emails through the social network composition wizard"\
"you may choose to send a copy of the mail to partners."),
-
'attachment_ids': fields.one2many('ir.attachment', 'res_id', 'Attachments'
domain=[('res_model','=','mail.message')]),
@@ -204,7 +206,6 @@ class mail_message(osv.Model):
self.check(cr, uid, ids, 'unlink', context=context)
return super(mail_message, self).unlink(cr, uid, ids, context)
- # FP Note: to be simplified, mail.message fields only, not mail.mail
def parse_message(self, message, save_original=False, context=None):
"""Parses a string or email.message.Message representing an
RFC-2822 email, and returns a generic dict holding the
diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py
index 3b475127c87..c8de4f20a2c 100644
--- a/addons/mail/mail_thread.py
+++ b/addons/mail/mail_thread.py
@@ -741,7 +741,7 @@ class mail_thread(osv.Model):
for thread in self.browse(cr, uid, ids, context=context):
l = set()
for message in thread.message_ids:
- l.add((message.user_id and message.user_id.user_email) or '')
+ l.add((message.user_id and message.user_id.email) or '')
l.add(message.email_from or '')
l.add(message.email_cc or '')
res[thread.id] = filter(None, l)
diff --git a/addons/mail/res_partner.py b/addons/mail/res_partner.py
index 7ffb07ee632..062c557b325 100644
--- a/addons/mail/res_partner.py
+++ b/addons/mail/res_partner.py
@@ -20,20 +20,28 @@
##############################################################################
from osv import osv
-from osv import fields
-class res_partner_mail(osv.osv):
+class res_partner_mail(osv.Model):
""" Inherits partner and adds CRM information in the partner form """
_name = "res.partner"
_inherit = ['res.partner', 'mail.thread']
def message_search_get_domain(self, cr, uid, ids, context=None):
""" Override of message_search_get_domain for partner discussion page.
- The purpose is to add messages directly sent to the partner.
+ The purpose is to add messages directly sent to the partner. It also
+ adds messages pushed to the related user, if any, using @login.
"""
initial_domain = super(res_partner_mail, self).message_search_get_domain(cr, uid, ids, context=context)
- if self._name == 'res.partner': # to avoid models inheriting from res.partner
- search_domain = ['|'] + initial_domain + ['|', ('partner_id', 'in', ids), ('partner_ids', 'in', ids)]
+ # to avoid models inheriting from res.partner
+ if self._name != 'res.partner':
+ return initial_domain
+ # add message linked to the partner
+ search_domain = ['|'] + initial_domain + ['|', ('partner_id', 'in', ids), ('partner_ids', 'in', ids)]
+ # if partner is linked to a user: find @login
+ res_users_obj = self.pool.get('res.users')
+ user_ids = res_users_obj.search(cr, uid, [('partner_id', 'in', ids)], context=context)
+ for user in res_users_obj.browse(cr, uid, user_ids, context=context):
+ search_domain = ['|'] + search_domain + ['|', ('body_text', 'like', '@%s' % (user.login)), ('body_html', 'like', '@%s' % (user.login))]
return search_domain
_columns = {
'notification_email_pref': fields.selection([
diff --git a/addons/mail/res_users.py b/addons/mail/res_users.py
index 07e9c557228..af045433936 100644
--- a/addons/mail/res_users.py
+++ b/addons/mail/res_users.py
@@ -28,7 +28,7 @@ from tools.translate import _
_logger = logging.getLogger(__name__)
-class res_users(osv.osv):
+class res_users(osv.Model):
""" Update of res.users class
- add a preference about sending emails about notifications
- make a new user follow itself
@@ -37,11 +37,11 @@ class res_users(osv.osv):
_name = 'res.users'
_inherit = ['res.users']
_inherits = {'mail.alias': 'alias_id'}
-
+
_columns = {
'alias_id': fields.many2one('mail.alias', 'Alias', ondelete="cascade", required=True,
- help="Email address internally associated with this user. Incoming emails will appear "
- "in the user's notifications."),
+ help="Email address internally associated with this user. Incoming "\
+ "emails will appear in the user's notifications."),
}
_defaults = {
@@ -62,13 +62,13 @@ class res_users(osv.osv):
def _auto_init(self, cr, context=None):
"""Installation hook to create aliases for all users and avoid constraint errors."""
-
+
# disable the unique alias_id not null constraint, to avoid spurious warning during
# super.auto_init. We'll reinstall it afterwards.
self._columns['alias_id'].required = False
super(res_users,self)._auto_init(cr, context=context)
-
+
registry = RegistryManager.get(cr.dbname)
mail_alias = registry.get('mail.alias')
res_users_model = registry.get('res.users')
@@ -92,25 +92,29 @@ class res_users(osv.osv):
self._columns['alias_id'].required = True
-
def create(self, cr, uid, data, context=None):
# create default alias same as the login
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
data.pop('alias_name', None) # prevent errors during copy()
+ # create user that follows its related partner
user_id = super(res_users, self).create(cr, uid, data, context=context)
- mail_alias.write(cr, SUPERUSER_ID, [alias_id], {"alias_force_thread_id": user_id}, context)
-
user = self.browse(cr, uid, user_id, context=context)
- # make user follow itself
- self.message_subscribe(cr, uid, [user_id], [user_id], context=context)
+ self.pool.get('res.partner').message_subscribe(cr, uid, [user.partner_id.id], [user_id], context=context)
+ # alias
+ mail_alias.write(cr, SUPERUSER_ID, [alias_id], {"alias_force_thread_id": user_id}, context)
# create a welcome message
- company_name = user.company_id.name if user.company_id else _('the company')
- message = _('%s joined the %s network! Take a moment to welcome %s.') % (user.name, company_name, user.name)
- self.message_append_note(cr, uid, [user_id], body=message, type='comment', context=context)
+ self.create_welcome_message(cr, uid, user, context=context)
return user_id
-
+
+ def create_welcome_message(self, cr, uid, user, context=None):
+ company_name = user.company_id.name if user.company_id else _('the company')
+ subject = '''%s has joined %s.''' % (user.name, company_name)
+ body = '''Welcome to OpenERP !'''
+ return self.pool.get('res.partner').message_append_note(cr, user.id, [user.partner_id.id],
+ subject=subject, body=body, type='comment', content_subtype='html', context=context)
+
def write(self, cr, uid, ids, vals, context=None):
# User alias is sync'ed with login
if vals.get('login'): vals['alias_name'] = vals['login']
@@ -123,28 +127,56 @@ class res_users(osv.osv):
res = super(res_users, self).unlink(cr, uid, ids, context=context)
alias_pool.unlink(cr, uid, alias_ids, context=context)
return res
-
- def message_search_get_domain(self, cr, uid, ids, context=None):
- """ Override of message_search_get_domain for partner discussion page.
- The purpose is to add messages directly sent to user using
- @user_login.
- """
- initial_domain = super(res_users, self).message_search_get_domain(cr, uid, ids, context=context)
- custom_domain = []
+
+ # --------------------------------------------------
+ # Wrappers on partner methods for Chatter
+ # #FIXME: another branch holds a refactoring of mail.thread
+ # that should help cleaning those wrappers
+ # --------------------------------------------------
+
+ def message_append(self, cr, uid, threads, subject, body_text=None, body_html=None,
+ type='email', email_date=None, parent_id=False,
+ content_subtype='plain', state=None,
+ partner_ids=None, email_from=False, email_to=False,
+ email_cc=None, email_bcc=None, reply_to=None,
+ headers=None, message_id=False, references=None,
+ attachments=None, original=None, context=None):
+ for user in self.browse(cr, uid, threads, context=context):
+ user.partner_id.message_append(subject, body_text, body_html, type, email_date, parent_id,
+ content_subtype, state, partner_ids, email_from, email_to, email_cc, email_bcc, reply_to,
+ headers, message_id, references, attachments, original)
+
+ def message_read(self, cr, uid, ids, fetch_ancestors=False, ancestor_ids=None,
+ limit=100, offset=0, domain=None, context=None):
+ for user in self.browse(cr, uid, ids, context=context):
+ return user.partner_id.message_read(fetch_ancestors, ancestor_ids, limit, offset, domain)
+
+ def message_read_subscribers(self, cr, uid, ids, fields=['id', 'name', 'image_small'], context=None):
for user in self.browse(cr, uid, ids, context=context):
- if custom_domain:
- custom_domain += ['|']
- custom_domain += ['|', ('body_text', 'like', '@%s' % (user.login)), ('body_html', 'like', '@%s' % (user.login))]
- return ['|'] + initial_domain + custom_domain
+ return user.partner_id.message_read_subscribers(fields)
-class res_users_mail_group(osv.osv):
+ def message_search(self, cr, uid, ids, fetch_ancestors=False, ancestor_ids=None,
+ limit=100, offset=0, domain=None, count=False, context=None):
+ for user in self.browse(cr, uid, ids, context=context):
+ return user.partner_id.message_search(fetch_ancestors, ancestor_ids, limit, offset, domain, count)
+
+ def message_subscribe(self, cr, uid, ids, user_ids = None, context=None):
+ for user in self.browse(cr, uid, ids, context=context):
+ return user.partner_id.message_subscribe(user_ids)
+
+ def message_unsubscribe(self, cr, uid, ids, user_ids = None, context=None):
+ for user in self.browse(cr, uid, ids, context=context):
+ return user.partner_id.message_unsubscribe(user_ids)
+
+
+class res_users_mail_group(osv.Model):
""" Update of res.groups class
- if adding/removing users from a group, check mail.groups linked to
this user group, and subscribe / unsubscribe them from the discussion
group. This is done by overriding the write method.
"""
_name = 'res.users'
- _inherit = ['res.users', 'mail.thread']
+ _inherit = ['res.users']
def write(self, cr, uid, ids, vals, context=None):
write_res = super(res_users_mail_group, self).write(cr, uid, ids, vals, context=context)
@@ -156,9 +188,8 @@ class res_users_mail_group(osv.osv):
mail_group_ids = mail_group_obj.search(cr, uid, [('group_ids', 'in', user_group_ids)], context=context)
mail_group_obj.message_subscribe(cr, uid, mail_group_ids, ids, context=context)
return write_res
-
-class res_groups_mail_group(osv.osv):
+class res_groups_mail_group(osv.Model):
""" Update of res.groups class
- if adding/removing users from a group, check mail.groups linked to
this user group, and subscribe / unsubscribe them from the discussion
@@ -176,3 +207,5 @@ class res_groups_mail_group(osv.osv):
mail_group_ids = mail_group_obj.search(cr, uid, [('group_ids', 'in', ids)], context=context)
mail_group_obj.message_subscribe(cr, uid, mail_group_ids, user_ids, context=context)
return super(res_groups_mail_group, self).write(cr, uid, ids, vals, context=context)
+
+# vim:et:
diff --git a/addons/mail/res_users_view.xml b/addons/mail/res_users_view.xml
index 29fcea14a8a..005d71cb09f 100644
--- a/addons/mail/res_users_view.xml
+++ b/addons/mail/res_users_view.xml
@@ -9,7 +9,7 @@
<field name="inherit_id" ref="base.view_users_form_simple_modif"/>
<field name="arch" type="xml">
<data>
- <field name="user_email" position="before">
+ <field name="email" position="before">
<field name="notification_email_pref" readonly="0"/>
</field>
</data>
@@ -23,15 +23,10 @@
<field name="inherit_id" ref="base.view_users_form"/>
<field name="arch" type="xml">
<data>
- <field name="user_email" position="before">
+ <field name="email" position="before">
<field name="notification_email_pref"/>
</field>
- <xpath expr="/form/sheet" position="after">
- <div class="oe_chatter">
- <field name="message_ids" colspan="4" widget="mail_thread" nolabel="1"/>
- </div>
- </xpath>
- <field name="user_email" position="after">
+ <field name="email" position="after">
<field name="alias_domain" invisible="1"/>
<field name="alias_id" readonly="1" required="0" attrs="{'invisible': [('alias_domain', '=', False)]}"/>
</field>
diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js
index c068074b457..ba8df2d1671 100644
--- a/addons/mail/static/src/js/mail.js
+++ b/addons/mail/static/src/js/mail.js
@@ -1021,7 +1021,6 @@ openerp.mail = function(session) {
if (this.compose_message_widget) {
this.compose_message_widget.destroy();
}
- debugger;
this.compose_message_widget = new mail.ComposeMessage(this, {
'extended_mode': false, 'uid': this.session.uid, 'res_model': this.params.res_model,
'res_id': this.params.res_id, 'mode': mode || 'comment', 'msg_id': msg_id });
diff --git a/addons/mail/wizard/mail_compose_message.py b/addons/mail/wizard/mail_compose_message.py
index ba081575c06..fafc866b895 100644
--- a/addons/mail/wizard/mail_compose_message.py
+++ b/addons/mail/wizard/mail_compose_message.py
@@ -100,7 +100,7 @@ class mail_compose_message(osv.TransientModel):
# Try to provide default email_from if not specified yet
if not result.get('email_from'):
current_user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
- result['email_from'] = current_user.user_email or False
+ result['email_from'] = current_user.email or False
return result
_columns = {
@@ -133,7 +133,7 @@ class mail_compose_message(osv.TransientModel):
result.update({
'model': model,
'res_id': res_id,
- 'email_from': user.user_email or tools.config.get('email_from', False),
+ 'email_from': user.email or tools.config.get('email_from', False),
'body_html': False,
'body_text': False,
'subject': False,
@@ -223,7 +223,7 @@ class mail_compose_message(osv.TransientModel):
'dest_partner_ids': dest_partner_ids,
'model': message_data.model or False,
'res_id': message_data.res_id or False,
- 'email_from': current_user.user_email or message_data.email_to or False,
+ 'email_from': current_user.email or message_data.email_to or False,
'email_to': message_data.reply_to or message_data.email_from or False,
'email_cc': message_data.email_cc or False,
'user_id': uid,