[IMP] mail.message, mail.thread: cleaned code
bzr revid: tde@openerp.com-20120322120836-0fuffo5g2jjft3p2
This commit is contained in:
parent
4bf486869e
commit
287be191fb
|
@ -102,18 +102,16 @@ class mail_message(osv.osv):
|
|||
'''Model holding messages: system notification (replacing res.log
|
||||
notifications), comments (for OpenSocial feature) and
|
||||
RFC2822 email messages. This model also provides facilities to
|
||||
parse, queue and send new email messages.
|
||||
|
||||
Messages that do not have a value for the email_from column
|
||||
are simple log messages (e.g. document state changes), while
|
||||
actual e-mails have the email_from value set.
|
||||
parse, queue and send new email messages. Type of messages
|
||||
are differentiated using the 'type' column.
|
||||
|
||||
The ``display_text`` field will have a slightly different
|
||||
presentation for real emails and for log messages.
|
||||
'''
|
||||
|
||||
_name = 'mail.message'
|
||||
_inherit = 'mail.message.common'
|
||||
_description = 'Generic Message (Email, Comment, Notification)'
|
||||
_description = 'Mail Message (Email, Comment, Notification)'
|
||||
_order = 'date desc'
|
||||
|
||||
# XXX to review - how to determine action to use?
|
||||
|
|
|
@ -65,9 +65,9 @@ class mail_thread(osv.osv):
|
|||
|
||||
def _get_message_ids(self, cr, uid, ids, name, arg, context=None):
|
||||
res = {}
|
||||
for thread in self.browse(cr, uid, ids, context=context):
|
||||
records = self.message_load(cr, uid, [thread.id], context=context)
|
||||
res[thread.id] = [obj['id'] for obj in records]
|
||||
for id in ids:
|
||||
records = self.message_load(cr, uid, [id], context=context)
|
||||
res[id] = [obj['id'] for obj in records]
|
||||
return res
|
||||
|
||||
# OpenSocial: message_ids_social is a dummy field that should not be used
|
||||
|
@ -114,7 +114,7 @@ class mail_thread(osv.osv):
|
|||
msg_to_del_ids = msg_obj.search(cr, uid, [('model', '=', self._name), ('res_id', 'in', ids)], context=context)
|
||||
msg_obj.unlink(cr, uid, msg_to_del_ids, context=context)
|
||||
|
||||
super(mail_thread, self).unlink(cr, uid, ids, context=context)
|
||||
return super(mail_thread, self).unlink(cr, uid, ids, context=context)
|
||||
|
||||
#------------------------------------------------------
|
||||
# Generic message api
|
||||
|
@ -127,8 +127,6 @@ class mail_thread(osv.osv):
|
|||
- push the message to subscribed users"""
|
||||
if context is None:
|
||||
context = {}
|
||||
|
||||
need_action_pushed = False
|
||||
user_to_push_ids = []
|
||||
subscription_obj = self.pool.get('mail.subscription')
|
||||
notification_obj = self.pool.get('mail.notification')
|
||||
|
@ -146,10 +144,10 @@ class mail_thread(osv.osv):
|
|||
user_to_push_ids += [user['id'] for user in users]
|
||||
# parse message to get requested users
|
||||
user_to_push_ids += self.message_parse_users(cr, uid, [msg_id], vals['body_text'], context=context)
|
||||
# push to need_action_user_id if set
|
||||
#if thread_obj.need_action_user_id and thread_obj.need_action_user_id.id not in user_to_push_ids:
|
||||
#user_to_push_ids.append(thread_obj.need_action_user_id.id)
|
||||
|
||||
# push to need_action_user_ids
|
||||
user_to_push_ids += self.needaction_get_records_user_ids(cr, uid, [thread_id], context=context)
|
||||
# remove duplicate entries
|
||||
user_to_push_ids = list(set(user_to_push_ids))
|
||||
# effectively push message to users
|
||||
for id in user_to_push_ids:
|
||||
notification_obj.create(cr, uid, {'user_id': id, 'message_id': msg_id}, context=context)
|
||||
|
@ -175,7 +173,7 @@ class mail_thread(osv.osv):
|
|||
def message_append(self, cr, uid, threads, subject, parent_id=False, body_text=None, type='email',
|
||||
email_to=False, email_from=False, email_cc=None, email_bcc=None,
|
||||
reply_to=None, email_date=None, message_id=False, references=None,
|
||||
attachments=None, body_html=None, subtype=None, headers=None,
|
||||
attachments=None, body_html=None, subtype='plain', headers=None,
|
||||
original=None, context=None):
|
||||
"""Creates a new mail.message attached to the current mail.thread,
|
||||
containing all the details passed as parameters. All attachments
|
||||
|
@ -253,41 +251,33 @@ class mail_thread(osv.osv):
|
|||
'model' : thread._name,
|
||||
'partner_id': partner_id,
|
||||
'res_id': thread.id,
|
||||
'date': time.strftime('%Y-%m-%d %H:%M:%S'),
|
||||
'date': email_date or fields.datetime.now(),
|
||||
'message_id': message_id,
|
||||
'body_text': body_text or (hasattr(thread, 'description') and thread.description or ''),
|
||||
'body_html': body_html or '',
|
||||
'attachment_ids': [(6, 0, to_attach)],
|
||||
'state': 'received',
|
||||
'type': type,
|
||||
'subtype': subtype,
|
||||
}
|
||||
|
||||
if email_from:
|
||||
if email_from or type == 'email':
|
||||
for param in (email_to, email_cc, email_bcc):
|
||||
if isinstance(param, list):
|
||||
param = ", ".join(param)
|
||||
data = {
|
||||
|
||||
data.update({
|
||||
'subject': subject or _('History'),
|
||||
'user_id': uid,
|
||||
'model' : thread._name,
|
||||
'res_id': thread.id,
|
||||
'date': email_date or time.strftime('%Y-%m-%d %H:%M:%S'),
|
||||
'body_text': body_text,
|
||||
'body_text': body_text or '',
|
||||
'email_to': email_to,
|
||||
'email_from': email_from or \
|
||||
(hasattr(thread, 'user_id') and thread.user_id and thread.user_id.user_email),
|
||||
'email_cc': email_cc,
|
||||
'email_bcc': email_bcc,
|
||||
'partner_id': partner_id,
|
||||
'references': references,
|
||||
'message_id': message_id,
|
||||
'attachment_ids': [(6, 0, to_attach)],
|
||||
'state' : 'received',
|
||||
'body_html': body_html,
|
||||
'subtype': subtype,
|
||||
'headers': headers,
|
||||
'reply_to': reply_to,
|
||||
'original': original,
|
||||
}
|
||||
'original': original, })
|
||||
|
||||
self.message_create(cr, uid, thread.id, data, context=context)
|
||||
return True
|
||||
|
||||
|
@ -307,20 +297,18 @@ class mail_thread(osv.osv):
|
|||
to determine the model of the thread to
|
||||
update (instead of the current model).
|
||||
"""
|
||||
# OpenSocial: add default email type for old API
|
||||
if not 'type' in msg_dict: msg_dict['type'] = 'email'
|
||||
return self.message_append(cr, uid, ids,
|
||||
subject = msg_dict.get('subject'),
|
||||
parent_id = msg_dict.get('parent_id', False),
|
||||
body_text = msg_dict.get('body_text'),
|
||||
type = msg_dict.get('type'),
|
||||
email_to = msg_dict.get('to'),
|
||||
email_from = msg_dict.get('from'),
|
||||
email_cc = msg_dict.get('cc'),
|
||||
email_bcc = msg_dict.get('bcc'),
|
||||
reply_to = msg_dict.get('reply'),
|
||||
body_text = msg_dict.get('body_text', None),
|
||||
type = msg_dict.get('type', 'email'),
|
||||
email_from = msg_dict.get('from', msg_dict.get('email_from')),
|
||||
email_to = msg_dict.get('to', msg_dict.get('email_to')),
|
||||
email_cc = msg_dict.get('cc', msg_dict.get('email_cc')),
|
||||
email_bcc = msg_dict.get('bcc', msg_dict.get('email_bcc')),
|
||||
reply_to = msg_dict.get('reply', msg_dict.get('reply_to')),
|
||||
email_date = msg_dict.get('date'),
|
||||
message_id = msg_dict.get('message-id'),
|
||||
message_id = msg_dict.get('rmessage-id', msg_dict.get('message_id')),
|
||||
references = msg_dict.get('references')\
|
||||
or msg_dict.get('in-reply-to'),
|
||||
attachments = msg_dict.get('attachments'),
|
||||
|
@ -335,13 +323,13 @@ class mail_thread(osv.osv):
|
|||
if context is None:
|
||||
context = {}
|
||||
msg_obj = self.pool.get('mail.message')
|
||||
msgs_tmp = msg_obj.read(cr, uid, child_ids, context=context)
|
||||
msgs_tmp = msg_obj.read(cr, uid, child_ids, ['id', 'parent_id'], context=context)
|
||||
parent_ids = [msg['parent_id'][0] for msg in msgs_tmp if msg['parent_id'] not in root_ids and msg['parent_id'][0] not in child_ids]
|
||||
child_ids += parent_ids
|
||||
cur_iter = 0; max_iter = 10;
|
||||
while (parent_ids and (cur_iter < max_iter)):
|
||||
cur_iter += 1
|
||||
msgs_tmp = msg_obj.read(cr, uid, parent_ids, context=context)
|
||||
msgs_tmp = msg_obj.read(cr, uid, parent_ids, ['id', 'parent_id'], context=context)
|
||||
parent_ids = [msg['parent_id'][0] for msg in msgs_tmp if msg['parent_id'] not in root_ids and msg['parent_id'][0] not in child_ids]
|
||||
child_ids += parent_ids
|
||||
return child_ids
|
||||
|
@ -393,12 +381,12 @@ class mail_thread(osv.osv):
|
|||
# Message tools
|
||||
def message_get_discussions_nbr(self, cr, uid, ids, context=None):
|
||||
message_obj = self.pool.get('mail.message')
|
||||
count = message_obj.search(cr, uid, [('model', '=', self._name), ('res_id', '=', ids), ('parent_id', '=', False)], count=True)
|
||||
count = message_obj.search(cr, uid, [('model', '=', self._name), ('res_id', '=', ids), ('parent_id', '=', False)], count=True, context=context)
|
||||
return count
|
||||
|
||||
def message_get_messages_nbr(self, cr, uid, ids, context=None):
|
||||
message_obj = self.pool.get('mail.message')
|
||||
count = message_obj.search(cr, uid, [('model', '=', self._name), ('res_id', 'in', ids)], count=True)
|
||||
count = message_obj.search(cr, uid, [('model', '=', self._name), ('res_id', 'in', ids)], count=True, context=context)
|
||||
return count
|
||||
|
||||
#------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue