[FIX] invite: do not send invite notification emails to partners having 'none' or opt_out.
bzr revid: tde@openerp.com-20130306080306-86k0pmzqiqilknzw
This commit is contained in:
parent
b2ebd26e8c
commit
ade7c33f18
|
@ -19,6 +19,7 @@
|
||||||
#
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
|
from openerp import SUPERUSER_ID
|
||||||
from openerp import tools
|
from openerp import tools
|
||||||
from openerp.osv import osv
|
from openerp.osv import osv
|
||||||
from openerp.osv import fields
|
from openerp.osv import fields
|
||||||
|
@ -51,12 +52,19 @@ class invite_wizard(osv.osv_memory):
|
||||||
}
|
}
|
||||||
|
|
||||||
def add_followers(self, cr, uid, ids, context=None):
|
def add_followers(self, cr, uid, ids, context=None):
|
||||||
for wizard in self.browse(cr, uid, ids, context=context):
|
# TDE FIXME HACK: as notification_email_send is not present on the partner
|
||||||
|
# form view, and as opt_out can be used once CRM is installed, we have to
|
||||||
|
# perform this ugly columns check to use the parameter
|
||||||
|
# Please remove me in 8.0 (hint: remove opt_out -> notification to 'never')
|
||||||
|
has_opt_out = self.pool.get('res.partner')._all_columns.get('opt_out')
|
||||||
|
|
||||||
|
for wizard in self.browse(cr, SUPERUSER_ID, ids, context=context):
|
||||||
model_obj = self.pool.get(wizard.res_model)
|
model_obj = self.pool.get(wizard.res_model)
|
||||||
document = model_obj.browse(cr, uid, wizard.res_id, context=context)
|
document = model_obj.browse(cr, uid, wizard.res_id, context=context)
|
||||||
|
|
||||||
# filter partner_ids to get the new followers, to avoid sending email to already following partners
|
# filter partner_ids to get the new followers, to avoid sending email to already following partners
|
||||||
new_follower_ids = [p.id for p in wizard.partner_ids if p.id not in document.message_follower_ids]
|
new_followers = [p for p in wizard.partner_ids if p.id not in document.message_follower_ids]
|
||||||
|
new_follower_ids = [p.id for p in new_followers]
|
||||||
model_obj.message_subscribe(cr, uid, [wizard.res_id], new_follower_ids, context=context)
|
model_obj.message_subscribe(cr, uid, [wizard.res_id], new_follower_ids, context=context)
|
||||||
|
|
||||||
# send an email
|
# send an email
|
||||||
|
@ -66,8 +74,10 @@ class invite_wizard(osv.osv_memory):
|
||||||
signature = user_id and user_id["signature"] or ''
|
signature = user_id and user_id["signature"] or ''
|
||||||
if signature:
|
if signature:
|
||||||
wizard.message = tools.append_content_to_html(wizard.message, signature, plaintext=True, container_tag='div')
|
wizard.message = tools.append_content_to_html(wizard.message, signature, plaintext=True, container_tag='div')
|
||||||
# send mail to new followers
|
# send mail to new followers, unless it is opt-out or notifications is set to None
|
||||||
for follower_id in new_follower_ids:
|
for follower in new_followers:
|
||||||
|
if follower.notification_email_send == 'none' or (has_opt_out and follower.opt_out):
|
||||||
|
continue
|
||||||
mail_mail = self.pool.get('mail.mail')
|
mail_mail = self.pool.get('mail.mail')
|
||||||
# the invite wizard should create a private message not related to any object -> no model, no res_id
|
# the invite wizard should create a private message not related to any object -> no model, no res_id
|
||||||
mail_id = mail_mail.create(cr, uid, {
|
mail_id = mail_mail.create(cr, uid, {
|
||||||
|
@ -77,5 +87,5 @@ class invite_wizard(osv.osv_memory):
|
||||||
'body_html': '%s' % wizard.message,
|
'body_html': '%s' % wizard.message,
|
||||||
'auto_delete': True,
|
'auto_delete': True,
|
||||||
}, context=context)
|
}, context=context)
|
||||||
mail_mail.send(cr, uid, [mail_id], recipient_ids=[follower_id], context=context)
|
mail_mail.send(cr, uid, [mail_id], recipient_ids=[follower.id], context=context)
|
||||||
return {'type': 'ir.actions.act_window_close'}
|
return {'type': 'ir.actions.act_window_close'}
|
||||||
|
|
Loading…
Reference in New Issue