diff options
| author | Parth Gajjar (Open ERP) <pga@tinyerp.com> | 2013-05-08 18:16:39 +0530 |
|---|---|---|
| committer | Parth Gajjar (Open ERP) <pga@tinyerp.com> | 2013-05-08 18:16:39 +0530 |
| commit | 2c6aeae9112de0ec0d39f8cdbb0690747ecfaa77 (patch) | |
| tree | 31ded50792f7f6fc6a9536c4d2d52e914a087c26 /addons/mail/wizard/mail_compose_message.py | |
| parent | 4ed6734b82f199952f672a812478b283342125ed (diff) | |
| parent | 389f4911147b7cf5191b93e025c7b5c39d9e9eb6 (diff) | |
[MERGE]
bzr revid: pga@tinyerp.com-20130508124639-wfb2mpy15tnzs787
Diffstat (limited to 'addons/mail/wizard/mail_compose_message.py')
| -rw-r--r-- | addons/mail/wizard/mail_compose_message.py | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/addons/mail/wizard/mail_compose_message.py b/addons/mail/wizard/mail_compose_message.py index 66e7149ac6d..dfda3038de8 100644 --- a/addons/mail/wizard/mail_compose_message.py +++ b/addons/mail/wizard/mail_compose_message.py @@ -19,10 +19,8 @@ # ############################################################################## -import base64 import re from openerp import tools - from openerp import SUPERUSER_ID from openerp.osv import osv from openerp.osv import fields @@ -174,12 +172,18 @@ class mail_compose_message(osv.TransientModel): related to. :param int res_id: id of the document record this mail is related to """ - doc_name_get = self.pool.get(model).name_get(cr, uid, [res_id], context=context) + doc_name_get = self.pool[model].name_get(cr, uid, [res_id], context=context) + record_name = False if doc_name_get: record_name = doc_name_get[0][1] - else: - record_name = False - return {'model': model, 'res_id': res_id, 'record_name': record_name} + values = { + 'model': model, + 'res_id': res_id, + 'record_name': record_name, + } + if record_name: + values['subject'] = 'Re: %s' % record_name + return values def get_message_data(self, cr, uid, message_id, context=None): """ Returns a defaults-like dict with initial values for the composition @@ -197,7 +201,7 @@ class mail_compose_message(osv.TransientModel): # create subject re_prefix = _('Re:') - reply_subject = tools.ustr(message_data.subject or '') + reply_subject = tools.ustr(message_data.subject or message_data.record_name or '') if not (reply_subject.startswith('Re:') or reply_subject.startswith(re_prefix)) and message_data.subject: reply_subject = "%s %s" % (re_prefix, reply_subject) # get partner_ids from original message @@ -224,33 +228,35 @@ class mail_compose_message(osv.TransientModel): 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' - if mass_mail_mode: # mass mail: avoid any auto subscription because this could lead to people being follower of plenty of documents - context['mail_create_nosubscribe'] = True - active_model_pool = self.pool.get(wizard.model if wizard.model else 'mail.thread') + active_model_pool = self.pool[wizard.model if wizard.model else 'mail.thread'] # wizard works in batch mode: [res_id] or active_ids res_ids = active_ids if mass_mail_mode and wizard.model and active_ids else [wizard.res_id] for res_id in res_ids: - # default values, according to the wizard options + # mail.message values, according to the wizard options post_values = { 'subject': wizard.subject, 'body': wizard.body, 'parent_id': wizard.parent_id and wizard.parent_id.id, 'partner_ids': [partner.id for partner in wizard.partner_ids], - 'attachments': [(attach.datas_fname or attach.name, base64.b64decode(attach.datas)) for attach in wizard.attachment_ids], + 'attachment_ids': [attach.id for attach in wizard.attachment_ids], } # 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) # email_from: mass mailing only can specify another email_from if email_dict.get('email_from'): @@ -313,7 +319,7 @@ class mail_compose_message(osv.TransientModel): exp = str(match.group()[2:-1]).strip() result = eval(exp, { 'user': self.pool.get('res.users').browse(cr, uid, uid, context=context), - 'object': self.pool.get(model).browse(cr, uid, res_id, context=context), + 'object': self.pool[model].browse(cr, uid, res_id, context=context), 'context': dict(context), # copy context to prevent side-effects of eval }) return result and tools.ustr(result) or '' |
