1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2012-Today OpenERP SA (<http://www.openerp.com>)
7
# This program is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation, either version 3 of the License, or
10
# (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
17
# You should have received a copy of the GNU General Public License
18
# along with this program. If not, see <http://www.gnu.org/licenses/>
20
##############################################################################
22
from openerp import tools
23
from openerp.osv import osv
24
from openerp.osv import fields
25
from openerp.tools.translate import _
28
class invite_wizard(osv.osv_memory):
29
""" Wizard to invite partners and make them followers. """
30
_inherit = 'mail.wizard.invite'
31
_description = 'Invite wizard'
33
def default_get(self, cr, uid, fields, context=None):
35
Overwrite the original model to add model for the context in the at
36
time use and add in the message all documents to follow
39
result = super(invite_wizard, self).default_get(cr, uid, fields, context=context)
40
model_obj = self.pool.get(result.get('res_model',False) or \
41
context.get('active_model'))
44
if len(context.get('active_ids',[])) > 1:
45
result.update({'res_model':context.get('active_model')})
46
message = _('<div>You have been invited to follow are '
48
for ids in context.get('active_ids',[]):
49
document_name = model_obj.name_get(cr, uid, [ids],
50
context=context)[0][1]
51
message = message + '\n<div>' + document_name + '</div>'
53
result['message'] = message
54
elif 'message' in fields and result.get('res_model') and result.get('res_id'):
55
document_name = self.pool.get(result.get('res_model')).name_get(cr, uid, [result.get('res_id')], context=context)[0][1]
56
message = _('<div>You have been invited to follow %s.</div>' % document_name)
57
result['message'] = message
63
'groups':fields.boolean('Groups', help='Used to add a followers '
64
'group from mail group '
67
'partners':fields.boolean('Partners', help='Used to add a followers '
69
'p_a_g':fields.boolean('Group and Partner', help='Used to add a '
70
'followers for partner '
71
'and group at the same '
75
'mail_groups':fields.many2many('mail.group', string='Mail Groups',
76
help='Select the mail.groups that you '
77
'want add with followers'),
82
def add_followers(self, cr, uid, ids, context=None):
84
Overwrite the original model work with many documents at the same time
85
and add followers in eech.
87
Each id is get by context field
89
res = {'type': 'ir.actions.act_window_close'}
90
for wizard in self.browse(cr, uid, ids, context=context):
91
if context.get('second',False):
92
for res_id in context.get('active_ids',[]):
93
model_obj = self.pool.get(wizard.res_model)
94
document = model_obj.browse(cr, uid, res_id,
96
new_follower_ids = [p.id for p in wizard.partner_ids\
98
document.message_follower_ids]
100
# filter partner_ids to get the new followers, to avoid sending email to already following partners
101
model_obj.message_subscribe(cr, uid, [res_id],
105
# send an email only if a personal message exists
106
if wizard.message and not wizard.message == '<br>': # when deleting the message, cleditor keeps a <br>
108
user_id = self.pool.get("res.users").\
110
fields=["signature"],
113
signature = user_id and user_id["signature"] or ''
116
tools.append_content_to_html(wizard.message,
121
# FIXME 8.0: use notification_email_send, send a wall message and let mail handle email notification + message box
122
for follower_id in new_follower_ids:
123
mail_mail = self.pool.get('mail.mail')
124
# the invite wizard should create a private message not related to any object -> no model, no res_id
125
mail_id = mail_mail.create(cr, uid, {
126
'model': wizard.res_model,
128
'subject': 'Invitation to follow %s' %
129
document.name_get()[0][1],
130
'body_html': '%s' % wizard.message,
133
mail_mail.send(cr, uid, [mail_id],
134
recipient_ids=[follower_id],
137
res = super(invite_wizard,self).add_followers(cr, uid, ids,
143
def load_partners(self, cr, uid, ids, mail_groups, check, check2,
145
''' Used to add all partnes in mail.group selected in the view and
151
mail_obj = self.pool.get('mail.group')
155
for group in mail_groups:
156
group_ids = group and len(group) == 3 and group[2] or []
157
for groups in mail_obj.read(cr, uid,
159
['message_follower_ids'],
161
partner_ids += groups.get('message_follower_ids',[])
163
partner_ids and res['value'].update({'partner_ids':partner_ids})