2012-02-22 11:59:24 +00:00
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2009-Today OpenERP SA (<http://www.openerp.com>)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
#
##############################################################################
2012-03-26 13:38:52 +00:00
from osv import osv , fields
from tools . translate import _
2012-02-22 11:59:24 +00:00
class res_users ( osv . osv ) :
2012-04-04 14:15:38 +00:00
""" Update of res.users class
- add a preference about sending emails about notificatoins
- make a new user follow itself
"""
2012-02-22 11:59:24 +00:00
_name = ' res.users '
_inherit = [ ' res.users ' , ' mail.thread ' ]
2012-03-26 13:38:52 +00:00
_columns = {
2012-04-04 07:46:52 +00:00
' notification_email_pref ' : fields . selection ( [
2012-04-03 17:34:49 +00:00
( ' all ' , ' All feeds ' ) ,
( ' comments ' , ' Only comments ' ) ,
( ' to_me ' , ' Only when sent directly to me ' ) ,
2012-04-04 07:46:52 +00:00
( ' none ' , ' Never ' )
] , ' Receive feeds by email ' , required = True ,
2012-04-04 14:15:38 +00:00
help = " Choose in which case you want to receive an email when you receive new feeds. " ) ,
2012-03-26 13:38:52 +00:00
}
2012-04-04 12:27:38 +00:00
_defaults = {
2012-04-04 07:46:52 +00:00
' notification_email_pref ' : ' all ' ,
2012-03-26 13:38:52 +00:00
}
2012-02-22 11:59:24 +00:00
def create ( self , cr , uid , data , context = None ) :
user_id = super ( res_users , self ) . create ( cr , uid , data , context = context )
2012-03-29 10:11:13 +00:00
user = self . browse ( cr , uid , [ user_id ] , context = context ) [ 0 ]
2012-02-22 11:59:24 +00:00
# make user follow itself
self . message_subscribe ( cr , uid , [ user_id ] , [ user_id ] , context = context )
2012-03-29 10:11:13 +00:00
# create a welcome message to broadcast
company_name = user . company_id . name if user . company_id else ' the company '
2012-04-04 14:15:38 +00:00
message = _ ( ' %s has joined %s ! You may leave him/her a message to celebrate a new arrival in the company ! You can help him/her doing its first steps on OpenERP. ' ) % ( user . name , company_name )
2012-04-05 21:04:12 +00:00
self . message_broadcast ( cr , uid , [ user . id ] , ' Welcome notification ' , message , context = context )
2012-02-22 11:59:24 +00:00
return user_id
2012-03-26 14:35:38 +00:00
def message_load_ids ( self , cr , uid , ids , limit = 100 , offset = 0 , domain = [ ] , ascent = False , root_ids = [ False ] , context = None ) :
2012-04-05 21:04:12 +00:00
""" Override of message_load_ids
User discussion page :
- messages posted on res . users , res_id = user . id
- messages directly sent to user with @user_login
"""
2012-03-26 14:35:38 +00:00
if context is None :
context = { }
msg_obj = self . pool . get ( ' mail.message ' )
msg_ids = [ ]
2012-04-05 21:04:12 +00:00
for user in self . browse ( cr , uid , ids , context = context ) :
msg_ids + = msg_obj . search ( cr , uid , [ ' | ' , ' | ' , ( ' body_text ' , ' like ' , ' @ %s ' % ( user . login ) ) , ( ' body_html ' , ' like ' , ' @ %s ' % ( user . login ) ) , ' & ' , ( ' res_id ' , ' = ' , user . id ) , ( ' model ' , ' = ' , self . _name ) ] + domain ,
2012-03-26 14:35:38 +00:00
limit = limit , offset = offset , context = context )
2012-04-04 14:15:38 +00:00
if ( ascent ) : msg_ids = self . _message_add_ancestor_ids ( cr , uid , ids , msg_ids , root_ids , context = context )
2012-03-26 14:35:38 +00:00
return msg_ids