[WIP] mail.thread: issues about email. Will continue tomorrow.

bzr revid: tde@openerp.com-20120403173449-gm209j5n1pt7cojr
This commit is contained in:
Thibault Delavallée 2012-04-03 19:34:49 +02:00
parent fe6e58a40e
commit 0f0213892e
4 changed files with 46 additions and 11 deletions

View File

@ -222,7 +222,7 @@ class mail_message(osv.osv):
}
_defaults = {
'type': 'comment',
'type': 'email',
'state': 'received',
}

View File

@ -126,6 +126,7 @@
</page>
<page string="Advanced" groups="base.group_extended">
<group col="2" colspan="4">
<field name="type"/>
<field name="mail_server_id" attrs="{'invisible':[('mail_server_id', '=', False)]}"/>
<field name="subtype" attrs="{'invisible':[('subtype', '=', False)]}"/>
<field name="auto_delete"/>
@ -208,7 +209,9 @@
<field name="res_model">mail.message</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<!--
<field name="domain">[('type', '=', 'email')]</field>
-->
<field name="context">{'search_default_received': 1, 'search_default_exception': 1}</field>
<field name="search_view_id" ref="view_email_message_search"/>
</record>

View File

@ -126,26 +126,57 @@ class mail_thread(osv.osv):
"""
if context is None:
context = {}
if context.get('install_mode', False):
print 'zpfinzpefinzofinzoiznef'
return True
else:
print 'ooooooooooh' + str(context) + str(vals)
user_to_push_ids = []
res_users_obj = self.pool.get('res.users')
message_obj = self.pool.get('mail.message')
subscription_obj = self.pool.get('mail.subscription')
notification_obj = self.pool.get('mail.notification')
# create message
msg_id = message_obj.create(cr, uid, vals, context=context)
# automatically subscribe the writer of the message
if vals['user_id']:
self.message_subscribe(cr, uid, [thread_id], [vals['user_id']], context=context)
# push message to users
user_to_push_ids = self.message_create_get_notification_user_ids(cr, uid, [thread_id], msg_id, vals, context=context)
# get users that will get a notification pushed
user_to_push_ids = self.message_create_get_notification_user_ids(cr, uid, [thread_id], vals, context=context)
# set email_from and email_to for comments and notifications
if vals['type'] == 'comment' or vals['type'] == 'notification':
current_user = res_users_obj.browse(cr, uid, [uid], context=context)[0]
if not vals.get('email_from', False):
vals['email_from'] = current_user.user_email
if not vals.get('email_to', False):
email_to = ''
for user in res_users_obj.browse(cr, uid, user_to_push_ids, context=context):
if user.message_email_pref == 'all' or user.message_email_pref == 'comments' and vals['type'] == 'comment':
if (user.user_email):
if email_to:
email_to = '%s, ' % (email_to)
email_to = '%s%s' % (email_to, user.user_email)
if email_to:
vals['email_to'] = email_to
print vals['email_from']
print vals['email_to']
if email_to:
vals['email_to'] = email_to
vals['state'] = 'outgoing'
# create message
msg_id = message_obj.create(cr, uid, vals, context=context)
# push to users
for id in user_to_push_ids:
notification_obj.create(cr, uid, {'user_id': id, 'message_id': msg_id}, context=context)
return msg_id
def message_create_get_notification_user_ids(self, cr, uid, thread_ids, msg_id, new_msg_vals, context=None):
def message_create_get_notification_user_ids(self, cr, uid, thread_ids, new_msg_vals, context=None):
if context is None:
context = {}

View File

@ -32,11 +32,12 @@ class res_users(osv.osv):
_columns = {
'message_email_pref': fields.selection([
('all', 'Everytime'),
('comments', 'Only for comments'),
('me', 'Only when sent directly to me'),
('all', 'All feeds'),
('comments', 'Only comments'),
('to_me', 'Only when sent directly to me'),
('none', 'Never'),
], 'New feeds email', help="Choose whether you want to receive an email when you receive new feeds."),
], string='Receive feeds by email', required=True,
help="Choose whether you want to receive an email when you receive new feeds."),
}
_default = {