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-03-26 13:38:52 +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-03 17:34:49 +00:00
|
|
|
help="Choose whether 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'
|
|
|
|
message = _('%s has joined %s! You may leave him a message to celebrate his arrival and help him doing its first steps !') % (user.name, company_name)
|
|
|
|
self.message_append_note(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):
|
|
|
|
if context is None:
|
|
|
|
context = {}
|
|
|
|
user_data = self.read(cr, uid, ids, ['id', 'login'], context=context)
|
|
|
|
msg_obj = self.pool.get('mail.message')
|
|
|
|
msg_ids = []
|
|
|
|
for x_id in range(0, len(ids)):
|
|
|
|
msg_ids += msg_obj.search(cr, uid, ['|', ('body_text', 'like', '@%s' % (user_data[x_id]['login'])), '&', ('res_id', '=', ids[x_id]), ('model', '=', self._name)] + domain,
|
|
|
|
limit=limit, offset=offset, context=context)
|
|
|
|
if (ascent): msg_ids = self._message_get_parent_ids(cr, uid, ids, msg_ids, root_ids, context=context)
|
|
|
|
return msg_ids
|