diff options
Diffstat (limited to 'addons/mail/wizard/mail_compose_message.py')
| -rw-r--r-- | addons/mail/wizard/mail_compose_message.py | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/addons/mail/wizard/mail_compose_message.py b/addons/mail/wizard/mail_compose_message.py index 3153ccc2069..03c5a7cfe8b 100644 --- a/addons/mail/wizard/mail_compose_message.py +++ b/addons/mail/wizard/mail_compose_message.py @@ -31,6 +31,7 @@ from tools.translate import _ # main mako-like expression pattern EXPRESSION_PATTERN = re.compile('(\$\{.+?\})') + class mail_compose_message(osv.TransientModel): """ Generic message composition wizard. You may inherit from this wizard at model and view levels to provide specific features. @@ -117,6 +118,7 @@ class mail_compose_message(osv.TransientModel): 'body_text': lambda self, cr, uid, ctx={}: False, 'body': lambda self, cr, uid, ctx={}: '', 'subject': lambda self, cr, uid, ctx={}: False, + 'partner_ids': lambda self, cr, uid, ctx={}: [], } def notify(self, cr, uid, newid, context=None): @@ -152,7 +154,7 @@ class mail_compose_message(osv.TransientModel): # create subject re_prefix = _('Re:') reply_subject = tools.ustr(message_data.subject or '') - if not (reply_subject.startswith('Re:') or reply_subject.startswith(re_prefix)): + if not (reply_subject.startswith('Re:') or reply_subject.startswith(re_prefix)) and message_data.subject: reply_subject = "%s %s" % (re_prefix, reply_subject) # create the reply in the body reply_body = _('<div>On %(date)s, %(sender_name)s wrote:<blockquote>%(body)s</blockquote></div>') % { @@ -176,8 +178,8 @@ class mail_compose_message(osv.TransientModel): return result def toggle_content_subtype(self, cr, uid, ids, context=None): - """ hit toggle formatting mode button: calls onchange_formatting to - emulate an on_change, then writes the value to update the form. """ + """ toggle content_subtype: calls onchange_formatting to emulate an + on_change, then writes the value to update the form. """ for record in self.browse(cr, uid, ids, context=context): content_st_new_value = 'plain' if record.content_subtype == 'html' else 'html' onchange_res = self.onchange_content_subtype(cr, uid, ids, content_st_new_value, record.model, record.res_id, context=context) @@ -185,11 +187,10 @@ class mail_compose_message(osv.TransientModel): return True def onchange_content_subtype(self, cr, uid, ids, value, model, res_id, context=None): - """ onchange_content_subtype (values: 'plain' or 'html'). This onchange - on the subtype allows to have some specific behavior when switching - between text or html mode. - This method can be overridden for models that want to have their - specific behavior. """ + """ This onchange allows to have some specific behavior when switching + between text or html mode. This method can be overridden. + :param values: 'plain' or 'html' + """ return {'value': {'content_subtype': value}} def _verify_partner_email(self, cr, uid, partner_ids, context=None): @@ -211,9 +212,9 @@ class mail_compose_message(osv.TransientModel): } def onchange_partner_ids(self, cr, uid, ids, value, context=None): - """ onchange_partner_ids (value format: [[6, 0, [3, 4]]]). The - basic purpose of this method is to check that destination partners + """ The basic purpose of this method is to check that destination partners effectively have email addresses. Otherwise a warning is thrown. + :param value: value format: [[6, 0, [3, 4]]] """ res = {'value': {}} if not value or not value[0] or not value[0][0] == 6: @@ -221,12 +222,6 @@ class mail_compose_message(osv.TransientModel): res.update(self._verify_partner_email(cr, uid, value[0][2], context=context)) return res - def unlink(self, cr, uid, ids, context=None): - # Cascade delete all attachments, as they are owned by the composition wizard - for wizard in self.read(cr, uid, ids, ['attachment_ids'], context=context): - self.pool.get('ir.attachment').unlink(cr, uid, wizard['attachment_ids'], context=context) - return super(mail_compose_message, self).unlink(cr, uid, ids, context=context) - def dummy(self, cr, uid, ids, context=None): """ TDE: defined to have buttons that do basically nothing. It is currently impossible to have buttons that do nothing special @@ -255,6 +250,7 @@ class mail_compose_message(osv.TransientModel): post_values = { 'subject': wizard.subject if wizard.content_subtype == 'html' else False, 'body': wizard.body if wizard.content_subtype == 'html' else '<pre>%s</pre>' % tools.ustr(wizard.body_text), + 'parent_id': wizard.parent_id and wizard.parent_id.id, 'partner_ids': [(4, 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], } @@ -268,6 +264,8 @@ class mail_compose_message(osv.TransientModel): post_values.update(email_dict) # post the message active_model_pool.message_post(cr, uid, [res_id], type='comment', context=context, **post_values) + # post process: update attachments, because id is not necessarily known when adding attachments in Chatter + self.pool.get('ir.attachment').write(cr, uid, [attach.id for attach in wizard.attachment_ids], {'res_id': wizard.id}, context=context) return {'type': 'ir.actions.act_window_close'} @@ -296,6 +294,7 @@ class mail_compose_message(osv.TransientModel): """ if context is None: context = {} + def merge(match): exp = str(match.group()[2:-1]).strip() result = eval(exp, { |
