result = super(mail_compose_message, self).default_get(cr, uid, fields, context=context)
# v6.1 compatibility mode
- result['composition_mode'] = result.get('composition_mode', context.get('mail.compose.message.mode'))
+ result['composition_mode'] = result.get('composition_mode', context.get('mail.compose.message.mode', 'comment'))
result['model'] = result.get('model', context.get('active_model'))
result['res_id'] = result.get('res_id', context.get('active_id'))
result['parent_id'] = result.get('parent_id', context.get('message_id'))
+ if not result['model'] or not self.pool.get(result['model']) or not hasattr(self.pool[result['model']], 'message_post'):
+ result['no_auto_thread'] = True
+
# default values according to composition mode - NOTE: reply is deprecated, fall back on comment
if result['composition_mode'] == 'reply':
result['composition_mode'] = 'comment'
if result['model'] == 'res.users' and result['res_id'] == uid:
result['model'] = 'res.partner'
result['res_id'] = self.pool.get('res.users').browse(cr, uid, uid).partner_id.id
+
+ if fields is not None:
+ [result.pop(field, None) for field in result.keys() if field not in fields]
return result
def _get_composition_mode_selection(self, cr, uid, context=None):
# mass mode options
'notify': fields.boolean('Notify followers',
help='Notify followers of the document (mass post only)'),
- 'same_thread': fields.boolean('Replies in the document',
- help='Replies to the messages will go into the selected document (mass mail only)'),
}
- #TODO change same_thread to False in trunk (Require view update)
_defaults = {
'composition_mode': 'comment',
'body': lambda self, cr, uid, ctx={}: '',
'subject': lambda self, cr, uid, ctx={}: False,
'partner_ids': lambda self, cr, uid, ctx={}: [],
- 'same_thread': True,
}
def check_access_rule(self, cr, uid, ids, operation, context=None):
def send_mail(self, cr, uid, ids, context=None):
""" Process the wizard content and proceed with sending the related
email(s), rendering any template patterns on the fly if needed. """
- if context is None:
- context = {}
+ context = dict(context or {})
# clean the context (hint: mass mailing sets some default values that
# could be wrongly interpreted by mail_mail)
else:
res_ids = [wizard.res_id]
- sliced_res_ids = [res_ids[i:i + self._batch_size] for i in range(0, len(res_ids), self._batch_size)]
+ batch_size = int(self.pool['ir.config_parameter'].get_param(cr, SUPERUSER_ID, 'mail.batch_size')) or self._batch_size
+
+ sliced_res_ids = [res_ids[i:i + batch_size] for i in range(0, len(res_ids), batch_size)]
for res_ids in sliced_res_ids:
all_mail_values = self.get_mail_values(cr, uid, wizard, res_ids, context=context)
for res_id, mail_values in all_mail_values.iteritems():
# render all template-based value at once
if mass_mail_mode and wizard.model:
rendered_values = self.render_message_batch(cr, uid, wizard, res_ids, context=context)
+ # compute alias-based reply-to in batch
+ reply_to_value = dict.fromkeys(res_ids, None)
+ if mass_mail_mode and not wizard.no_auto_thread:
+ reply_to_value = self.pool['mail.thread'].message_get_reply_to(cr, uid, res_ids, default=wizard.email_from, context=dict(context, thread_model=wizard.model))
for res_id in res_ids:
# static wizard (mail.message) values
'author_id': wizard.author_id.id,
'email_from': wizard.email_from,
'record_name': wizard.record_name,
+ 'no_auto_thread': wizard.no_auto_thread,
}
# mass mailing: rendering override wizard static values
if mass_mail_mode and wizard.model:
email_dict = rendered_values[res_id]
mail_values['partner_ids'] += email_dict.pop('partner_ids', [])
mail_values.update(email_dict)
- if wizard.same_thread:
+ if not wizard.no_auto_thread:
mail_values.pop('reply_to')
- elif not mail_values.get('reply_to'):
+ if reply_to_value.get(res_id):
+ mail_values['reply_to'] = reply_to_value[res_id]
+ if wizard.no_auto_thread and not mail_values.get('reply_to'):
mail_values['reply_to'] = mail_values['email_from']
# mail_mail values: body -> body_html, partner_ids -> recipient_ids
mail_values['body_html'] = mail_values.get('body', '')