#
##############################################################################
-import base64
import re
from openerp import tools
++<<<<<<< TREE
++=======
+
+ from openerp import SUPERUSER_ID
++>>>>>>> MERGE-SOURCE
from openerp.osv import osv
from openerp.osv import fields
from openerp.tools.safe_eval import safe_eval as eval
email(s), rendering any template patterns on the fly if needed. """
if context is None:
context = {}
+ ir_attachment_obj = self.pool.get('ir.attachment')
active_ids = context.get('active_ids')
+ is_log = context.get('mail_compose_log', False)
for wizard in self.browse(cr, uid, ids, context=context):
mass_mail_mode = wizard.composition_mode == 'mass_mail'
# mass mailing: render and override default values
if mass_mail_mode and wizard.model:
email_dict = self.render_message(cr, uid, wizard, res_id, context=context)
- new_partner_ids = email_dict.pop('partner_ids', [])
- post_values['partner_ids'] += new_partner_ids
- new_attachments = email_dict.pop('attachments', [])
- post_values['attachments'] += new_attachments
+ post_values['partner_ids'] += email_dict.pop('partner_ids', [])
+ post_values['attachments'] = email_dict.pop('attachments', [])
+ attachment_ids = []
+ for attach_id in post_values.pop('attachment_ids'):
+ new_attach_id = ir_attachment_obj.copy(cr, uid, attach_id, {'res_model': self._name, 'res_id': wizard.id}, context=context)
+ attachment_ids.append(new_attach_id)
+ post_values['attachment_ids'] = attachment_ids
post_values.update(email_dict)
# post the message
- subtype = 'mail.mt_comment' if not context.get('mail_compose_log', False) else False
- active_model_pool.message_post(cr, uid, [res_id], type='comment', subtype=subtype, context=context, **post_values)
+ subtype = 'mail.mt_comment'
+ if is_log: # log a note: subtype is False
+ subtype = False
+ elif mass_mail_mode: # mass mail: is a log pushed to recipients, author not added
+ subtype = False
+ context = dict(context, mail_create_nosubscribe=True) # add context key to avoid subscribing the author
+ msg_id = active_model_pool.message_post(cr, uid, [res_id], type='comment', subtype=subtype, context=context, **post_values)
+ # mass_mailing: notify specific partners, because subtype was False, and no-one was notified
+ if mass_mail_mode and post_values['partner_ids']:
+ self.pool.get('mail.notification')._notify(cr, uid, msg_id, post_values['partner_ids'], context=context)
return {'type': 'ir.actions.act_window_close'}