[IMP] mail cleaning
bzr revid: fp@tinyerp.com-20120816101848-0l3wyu98zjmtkfks
This commit is contained in:
parent
c7c1cb1037
commit
73827c5525
|
@ -107,17 +107,12 @@ class mail_group(osv.Model):
|
|||
|
||||
# FP Note: code to be improved. Check we have a code for res.users
|
||||
# when we give them a new group.
|
||||
def _subscribe_user_with_group_m2m_command(self, cr, uid, ids, group_ids_command, context=None):
|
||||
# form: {'group_ids': [(3, 10), (3, 3), (4, 10), (4, 3)]} or {'group_ids': [(6, 0, [ids]}
|
||||
user_group_ids = [command[1] for command in group_ids_command if command[0] == 4]
|
||||
user_group_ids += [id for command in group_ids_command if command[0] == 6 for id in command[2]]
|
||||
# retrieve the user member of those groups
|
||||
def _subscribe_users(self, cr, uid, ids, context=None):
|
||||
for mail_group in self.browse(cr, uid, ids, context=context):
|
||||
partner_ids = []
|
||||
res_groups_obj = self.pool.get('res.groups')
|
||||
for group in res_groups_obj.browse(cr, uid, user_group_ids, context=context):
|
||||
for group in mail_group.group_ids:
|
||||
partner_ids += [user.partner_id.id for user in group.users]
|
||||
# subscribe the users
|
||||
return self.message_subscribe(cr, uid, ids, partner_ids, context=context)
|
||||
self.message_subscribe(cr, uid, ids, partner_ids, context=context)
|
||||
|
||||
def create(self, cr, uid, vals, context=None):
|
||||
mail_alias = self.pool.get('mail.alias')
|
||||
|
@ -150,8 +145,7 @@ class mail_group(osv.Model):
|
|||
mail_alias.write(cr, uid, [vals['alias_id']], {"alias_force_thread_id": mail_group_id}, context)
|
||||
|
||||
if vals.get('group_ids'):
|
||||
self._subscribe_user_with_group_m2m_command(cr, uid, [mail_group_id], vals.get('group_ids'), context=context)
|
||||
|
||||
self._subscribe_users(cr, uid, [mail_group_id], context=context)
|
||||
return mail_group_id
|
||||
|
||||
def unlink(self, cr, uid, ids, context=None):
|
||||
|
@ -163,7 +157,8 @@ class mail_group(osv.Model):
|
|||
return res
|
||||
|
||||
def write(self, cr, uid, ids, vals, context=None):
|
||||
result = super(mail_group, self).write(cr, uid, ids, vals, context=context)
|
||||
if vals.get('group_ids'):
|
||||
self._subscribe_user_with_group_m2m_command(cr, uid, ids, vals.get('group_ids'), context=context)
|
||||
return super(mail_group, self).write(cr, uid, ids, vals, context=context)
|
||||
self._subscribe_users(cr, uid, ids, vals.get('group_ids'), context=context)
|
||||
return result
|
||||
|
||||
|
|
|
@ -49,6 +49,7 @@ class mail_mail(osv.Model):
|
|||
'content_subtype': 'plain',
|
||||
}
|
||||
|
||||
# FP Note: should we use a dict instead ?
|
||||
def schedule_with_attach(self, cr, uid, email_from, email_to, subject, body, model=False, type='email',
|
||||
email_cc=None, reply_to=False, partner_ids=None, attachments=None,
|
||||
message_id=False, references=False, res_id=False, content_subtype='plain',
|
||||
|
|
|
@ -360,5 +360,3 @@ class mail_message(osv.Model):
|
|||
msg['body'] = msg['body_text']
|
||||
msg['sub_type'] = msg['content_subtype'] or 'plain'
|
||||
return msg
|
||||
|
||||
|
||||
|
|
|
@ -103,8 +103,8 @@ class mail_thread(osv.Model):
|
|||
return res
|
||||
|
||||
# FP Note: todo
|
||||
def _search_state(self, tobj, cr, uid, obj=None, name=None, domain=None, context=None):
|
||||
return [('id','in',[])]
|
||||
def _search_unread(self, tobj, cr, uid, obj=None, name=None, domain=None, context=None):
|
||||
return []
|
||||
|
||||
_columns = {
|
||||
'message_is_follower': fields.function(_get_is_follower,
|
||||
|
@ -116,7 +116,7 @@ class mail_thread(osv.Model):
|
|||
domain=lambda self: [('model','=',self._name)],
|
||||
string='Related Messages',
|
||||
help="All messages related to the current document."),
|
||||
'message_unread': fields.function(_get_message_data, fnct_search=_search_state, 'Message Read',
|
||||
'message_unread': fields.function(_get_message_data, fnct_search=_search_unread, 'Has Unread Messages',
|
||||
help="When checked, new messages require your attention.",
|
||||
multi="_get_message_data"),
|
||||
'message_summary': fields.function(_get_message_data, method=True,
|
||||
|
@ -131,12 +131,10 @@ class mail_thread(osv.Model):
|
|||
#------------------------------------------------------
|
||||
|
||||
def create(self, cr, uid, vals, context=None):
|
||||
""" Override of create to subscribe :
|
||||
- the writer
|
||||
- followers given by the monitored fields
|
||||
""" Override of create to subscribe the current user
|
||||
"""
|
||||
thread_id = super(mail_thread, self).create(cr, uid, vals, context=context)
|
||||
self.message_subscribe(cr, uid, [thread_id], [uid], context=context)
|
||||
self.message_subscribe_users(cr, uid, [thread_id], [uid], context=context)
|
||||
return thread_id
|
||||
|
||||
def unlink(self, cr, uid, ids, context=None):
|
||||
|
@ -155,6 +153,8 @@ class mail_thread(osv.Model):
|
|||
# mail.message wrappers and tools
|
||||
#------------------------------------------------------
|
||||
|
||||
# FP Note: should we support attachment ? Also, this method must be on
|
||||
# the mail.message object, not on the thread.
|
||||
def message_create(self, cr, uid, thread_id, vals, context=None):
|
||||
""" OpenChatter: wrapper of mail.message create method
|
||||
- creates the mail.message
|
||||
|
@ -177,14 +177,7 @@ class mail_thread(osv.Model):
|
|||
# Generic message api
|
||||
#------------------------------------------------------
|
||||
|
||||
def message_capable_models(self, cr, uid, context=None):
|
||||
ret_dict = {}
|
||||
for model_name in self.pool.obj_list():
|
||||
model = self.pool.get(model_name)
|
||||
if 'mail.thread' in getattr(model, '_inherit', []):
|
||||
ret_dict[model_name] = model._description
|
||||
return ret_dict
|
||||
|
||||
# I propose to remove this. Everyone should use message_create instead.
|
||||
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,
|
||||
|
@ -313,6 +306,7 @@ class mail_thread(osv.Model):
|
|||
new_msg_ids.append(self.message_create(cr, uid, thread.id, data, context=context))
|
||||
return new_msg_ids
|
||||
|
||||
# to be removed completly
|
||||
def message_append_dict(self, cr, uid, ids, msg_dict, context=None):
|
||||
"""Creates a new mail.message attached to the given threads (``ids``),
|
||||
with the contents of ``msg_dict``, by calling ``message_append``
|
||||
|
@ -866,19 +860,37 @@ class mail_thread(osv.Model):
|
|||
return True
|
||||
return False
|
||||
|
||||
def message_subscribe(self, cr, uid, ids, partner_ids=None, context=None):
|
||||
def message_subscribe_users(self, cr, uid, ids, user_ids=None, context=None):
|
||||
if not user_ids: user_ids = [uid]
|
||||
partners = {}
|
||||
for user in self.pool.get('res.users').browse(cr, uid, user_ids, context=context):
|
||||
partners[user.partner_id.id] = True
|
||||
return self.message_subscribe(cr, uid, ids, partners.keys(), context=context)
|
||||
|
||||
def message_subscribe(self, cr, uid, ids, partner_ids, context=None):
|
||||
"""
|
||||
:param user_ids: a list of user_ids; if not set, subscribe
|
||||
:param partner_ids: a list of user_ids; if not set, subscribe
|
||||
uid instead
|
||||
:param return: new value of followers, for Chatter
|
||||
"""
|
||||
subscription_obj = self.pool.get('mail.subscription')
|
||||
obj = self.pool.get('mail.followers')
|
||||
objids = obj.search(cr, uid, [
|
||||
('res_id', 'in', ids),
|
||||
('res_model', '=', self._name),
|
||||
('partner_id', 'in', partner_ids),
|
||||
], context=context)
|
||||
followers = {}
|
||||
for follow in obj.browse(cr, uid, objids, context=context)
|
||||
followers.setdefault(follow.partner_id.id, {})[follow.res_id] = True
|
||||
create_ids = []
|
||||
for id in ids:
|
||||
already_subscribed_user_ids = self.message_get_followers(cr, uid, [id], context=context)
|
||||
for user_id in to_subscribe_uids:
|
||||
if user_id in already_subscribed_user_ids: continue
|
||||
create_ids.append(subscription_obj.create(cr, uid, {'res_model': self._name, 'res_id': id, 'user_id': user_id}, context=context))
|
||||
for res_id in ids:
|
||||
for partner_id in partner_ids:
|
||||
if followers.get(partner_id, {}).get(res_id, False):
|
||||
continue
|
||||
create_ids.append(obj.create(cr, uid, {
|
||||
'res_model': self._name,
|
||||
'res_id': res_id, 'partner_id': partner_id
|
||||
}, context=context))
|
||||
return create_ids
|
||||
|
||||
def message_unsubscribe(self, cr, uid, ids, user_ids = None, context=None):
|
||||
|
|
|
@ -31,18 +31,11 @@ class res_partner_mail(osv.Model):
|
|||
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)
|
||||
# to avoid models inheriting from res.partner
|
||||
if self._name != 'res.partner':
|
||||
return initial_domain
|
||||
return super(res_partner_mail, self).message_search_get_domain(cr, uid, ids, context=context)
|
||||
# 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
|
||||
return [('partner_ids', 'in', ids)]
|
||||
|
||||
_columns = {
|
||||
'notification_email_pref': fields.selection([
|
||||
('all', 'All feeds'),
|
||||
|
|
|
@ -98,17 +98,16 @@ class res_users(osv.Model):
|
|||
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)
|
||||
user = self.browse(cr, uid, user_id, context=context)
|
||||
self.pool.get('res.partner').message_subscribe(cr, uid, [user.partner_id.id], [user_id], context=context)
|
||||
self.pool.get('res.partner').message_subscribe_users(cr, uid, [user_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
|
||||
self.create_welcome_message(cr, uid, user, context=context)
|
||||
self._create_welcome_message(cr, uid, user, context=context)
|
||||
return user_id
|
||||
|
||||
def create_welcome_message(self, cr, uid, user, context=None):
|
||||
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 !'''
|
||||
|
@ -135,35 +134,35 @@ class res_users(osv.Model):
|
|||
# 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_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(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_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_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_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)
|
||||
#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):
|
||||
|
@ -175,6 +174,7 @@ class res_users_mail_group(osv.Model):
|
|||
_name = 'res.users'
|
||||
_inherit = ['res.users']
|
||||
|
||||
# FP Note: to improve
|
||||
def write(self, cr, uid, ids, vals, context=None):
|
||||
write_res = super(res_users_mail_group, self).write(cr, uid, ids, vals, context=context)
|
||||
if vals.get('groups_id'):
|
||||
|
@ -195,6 +195,7 @@ class res_groups_mail_group(osv.Model):
|
|||
_name = 'res.groups'
|
||||
_inherit = 'res.groups'
|
||||
|
||||
# FP Note: to improve
|
||||
def write(self, cr, uid, ids, vals, context=None):
|
||||
if vals.get('users'):
|
||||
# form: {'group_ids': [(3, 10), (3, 3), (4, 10), (4, 3)]} or {'group_ids': [(6, 0, [ids]}
|
||||
|
@ -205,4 +206,3 @@ class res_groups_mail_group(osv.Model):
|
|||
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:
|
||||
|
|
Loading…
Reference in New Issue