2012-02-01 16:49:02 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
##############################################################################
|
|
|
|
#
|
|
|
|
# OpenERP, Open Source Management Solution
|
2012-03-13 15:24:52 +00:00
|
|
|
# Copyright (C) 2009-today OpenERP SA (<http://www.openerp.com>)
|
2012-02-01 16:49:02 +00:00
|
|
|
#
|
|
|
|
# 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/>
|
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
from osv import osv
|
|
|
|
from osv import fields
|
|
|
|
|
2012-08-13 19:10:06 +00:00
|
|
|
class mail_followers(osv.Model):
|
|
|
|
""" mail_followers holds the data related to the follow mechanism inside
|
2012-08-16 09:02:43 +00:00
|
|
|
OpenERP. Partners can choose to follow documents (records) of any kind that
|
2012-08-13 19:10:06 +00:00
|
|
|
inherits from mail.thread. Following documents allow to receive
|
|
|
|
notifications for new messages.
|
2012-03-13 15:24:52 +00:00
|
|
|
A subscription is characterized by:
|
2012-04-02 12:59:26 +00:00
|
|
|
:param: res_model: model of the followed objects
|
|
|
|
:param: res_id: ID of resource (may be 0 for every objects)
|
2012-02-01 16:49:02 +00:00
|
|
|
"""
|
2012-08-13 19:10:06 +00:00
|
|
|
_name = 'mail.followers'
|
2012-08-16 09:02:43 +00:00
|
|
|
_rec_name = 'partner_id'
|
2012-08-09 14:43:45 +00:00
|
|
|
_log_access = False
|
2012-08-16 09:02:43 +00:00
|
|
|
_description = 'Document Followers'
|
2012-02-01 16:49:02 +00:00
|
|
|
_columns = {
|
2012-02-06 11:26:23 +00:00
|
|
|
'res_model': fields.char('Related Document Model', size=128,
|
2012-04-02 12:59:26 +00:00
|
|
|
required=True, select=1,
|
|
|
|
help='Model of the followed resource'),
|
|
|
|
'res_id': fields.integer('Related Document ID', select=1,
|
|
|
|
help='Id of the followed resource'),
|
2012-08-16 09:02:43 +00:00
|
|
|
'partner_id': fields.many2one('res.partner', string='Related Partner',
|
2012-02-10 12:42:53 +00:00
|
|
|
ondelete='cascade', required=True, select=1),
|
2012-02-01 16:49:02 +00:00
|
|
|
}
|
2012-02-01 17:05:05 +00:00
|
|
|
|
2012-08-17 11:19:36 +00:00
|
|
|
|
2012-08-09 14:43:45 +00:00
|
|
|
class mail_notification(osv.Model):
|
2012-02-01 17:05:05 +00:00
|
|
|
_name = 'mail.notification'
|
2012-08-16 09:02:43 +00:00
|
|
|
_rec_name = 'partner_id'
|
2012-02-06 09:06:18 +00:00
|
|
|
_log_access = False
|
2012-08-16 09:02:43 +00:00
|
|
|
_description = 'Notifications'
|
2012-02-01 17:05:05 +00:00
|
|
|
_columns = {
|
2012-08-15 18:44:03 +00:00
|
|
|
'partner_id': fields.many2one('res.partner', string='Contact',
|
2012-02-06 09:06:18 +00:00
|
|
|
ondelete='cascade', required=True, select=1),
|
2012-08-15 18:44:03 +00:00
|
|
|
'read': fields.boolean('Read'),
|
2012-08-17 11:19:36 +00:00
|
|
|
# this will be added in mail_message.py
|
|
|
|
#'message_id': fields.many2one('mail.message', string='Message',
|
|
|
|
# ondelete='cascade', required=True, select=1),
|
2012-02-01 17:05:05 +00:00
|
|
|
}
|
|
|
|
_defaults = {
|
2012-02-02 11:26:57 +00:00
|
|
|
'read': False,
|
2012-02-01 17:05:05 +00:00
|
|
|
}
|
2012-08-15 20:02:46 +00:00
|
|
|
# FP Note: todo: check that we can not create a notification for
|
|
|
|
# a message we can not read.
|
|
|
|
# def create(self, ...)
|
|
|
|
|
|
|
|
|
2012-08-15 13:36:43 +00:00
|
|
|
# Create notification in the wall of each user
|
|
|
|
# Send by email the notification depending on the user preferences
|
2012-08-16 16:43:11 +00:00
|
|
|
def notify(self, cr, uid, partner_ids, msg_id, context=None):
|
|
|
|
context = context or {}
|
2012-08-15 18:44:03 +00:00
|
|
|
partner_obj = self.pool.get('res.partner')
|
2012-08-15 13:36:43 +00:00
|
|
|
msg_obj = self.pool.get('mail.message')
|
|
|
|
msg = msg_obj.browse(cr, uid, msg_id, context=context)
|
|
|
|
|
|
|
|
towrite = {
|
2012-08-15 18:44:03 +00:00
|
|
|
'email_to': '',
|
2012-08-15 13:36:43 +00:00
|
|
|
'subject': msg.subject
|
|
|
|
}
|
2012-08-15 18:44:03 +00:00
|
|
|
for partner in partner_obj.browse(cr, uid, partner_ids, context=context):
|
2012-08-15 13:36:43 +00:00
|
|
|
notification_obj.create(cr, uid, {
|
2012-08-15 19:34:06 +00:00
|
|
|
'partner_id': partner.id,
|
2012-08-15 13:36:43 +00:00
|
|
|
'message_id': msg_id
|
|
|
|
}, context=context)
|
2012-08-15 19:34:06 +00:00
|
|
|
if partner.notification_email_pref=='none' or not partner.email:
|
2012-08-15 13:36:43 +00:00
|
|
|
continue
|
|
|
|
|
2012-08-15 18:44:03 +00:00
|
|
|
if partner.notification_email_pref=='comment' and msg.type in ('email','comment'):
|
2012-08-15 13:36:43 +00:00
|
|
|
continue
|
|
|
|
|
|
|
|
if not msg.email_from:
|
|
|
|
current_user = res_users_obj.browse(cr, uid, uid, context=context)
|
2012-08-15 19:34:06 +00:00
|
|
|
towrite['email_from'] = current_user.email
|
2012-08-15 13:36:43 +00:00
|
|
|
|
|
|
|
towrite['state'] = 'outgoing'
|
|
|
|
if not towrite.get('email_to', False):
|
|
|
|
towrite['email_to'] = email_to
|
|
|
|
else:
|
|
|
|
if email_to not in towrite['email_to']:
|
|
|
|
towrite['email_to'] = towrite['email_to'] + ', ' + email_to
|
|
|
|
|
2012-08-16 16:43:11 +00:00
|
|
|
if towrite.get('state', False) and not context.get('noemail', False):
|
2012-08-15 13:36:43 +00:00
|
|
|
if towrite.get('subject', False):
|
|
|
|
towrite['subject'] = msg.name_get(cr, uid, [msg.id], context=context)[0][1]
|
2012-08-15 18:44:03 +00:00
|
|
|
towrite['message_id'] = msg.id
|
|
|
|
self.pool.get('mail.mail').create(cr, uid, towrite, context=context)
|
2012-08-15 13:36:43 +00:00
|
|
|
return True
|
|
|
|
|
|
|
|
|