summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThibault Delavallée <tde@openerp.com>2012-11-15 13:51:13 +0100
committerThibault Delavallée <tde@openerp.com>2012-11-15 13:51:13 +0100
commit3571ad2a70a8dcdbecd6d749fca6300f393362cc (patch)
tree00c37bc493be57a13edf6b1d380d018c7ba5edb7
parent6227e4b5c04b9ee861511a45f7b50806e27cf33c (diff)
parentda9951baf9e8631e97ae0b8bde69eb03e6f34fdf (diff)
[MERGE] Fixes some posting/email_template issues. Also cleans an old hack about res.users view redirected to its related res.partner.
Addons-side: - res.users wraps the 2 posting methods, because mailboxes are still related to the user, not the partner, due to some technical issues - mail.compose.message using email_template: _reopen is back, as the spec of a wizard should be that hitting a button close it. Therefore _reopen is necessaru to reopen the wizard with its previous value, to continue working on it. bzr revid: tde@openerp.com-20121115125113-oxn2vwunsvkinxkd
-rw-r--r--addons/email_template/wizard/mail_compose_message.py27
-rw-r--r--addons/email_template/wizard/mail_compose_message_view.xml3
-rw-r--r--addons/mail/mail_thread_view.xml2
-rw-r--r--addons/mail/res_partner.py3
-rw-r--r--addons/mail/res_users.py11
-rw-r--r--addons/mail/static/src/js/mail.js19
-rw-r--r--addons/mail/static/src/xml/mail.xml8
-rw-r--r--addons/mail/tests/test_mail.py3
-rw-r--r--addons/mail/wizard/mail_compose_message.py4
9 files changed, 40 insertions, 40 deletions
diff --git a/addons/email_template/wizard/mail_compose_message.py b/addons/email_template/wizard/mail_compose_message.py
index 129c32722f5..9a995985687 100644
--- a/addons/email_template/wizard/mail_compose_message.py
+++ b/addons/email_template/wizard/mail_compose_message.py
@@ -25,6 +25,21 @@ from osv import osv
from osv import fields
+def _reopen(self, res_id, model):
+ return {'type': 'ir.actions.act_window',
+ 'view_mode': 'form',
+ 'view_type': 'form',
+ 'res_id': res_id,
+ 'res_model': self._name,
+ 'target': 'new',
+ # save original model in context, because selecting the list of available
+ # templates requires a model in context
+ 'context': {
+ 'default_model': model,
+ },
+ }
+
+
class mail_compose_message(osv.TransientModel):
_inherit = 'mail.compose.message'
@@ -42,10 +57,8 @@ class mail_compose_message(osv.TransientModel):
else:
model = context.get('default_model', context.get('active_model'))
- if model:
- record_ids = email_template_obj.search(cr, uid, [('model', '=', model)], context=context)
- return email_template_obj.name_get(cr, uid, record_ids, context) + [(False, '')]
- return []
+ record_ids = email_template_obj.search(cr, uid, [('model', '=', model)], context=context)
+ return email_template_obj.name_get(cr, uid, record_ids, context) + [(False, '')]
def default_get(self, cr, uid, fields, context=None):
if context is None:
@@ -109,7 +122,7 @@ class mail_compose_message(osv.TransientModel):
onchange_res['partner_ids'] = [(4, partner_id) for partner_id in onchange_res.pop('partner_ids', [])]
onchange_res['attachment_ids'] = [(4, attachment_id) for attachment_id in onchange_res.pop('attachment_ids', [])]
record.write(onchange_res)
- return True
+ return _reopen(self, record.id, record.model)
def onchange_use_template(self, cr, uid, ids, use_template, template_id, composition_mode, model, res_id, context=None):
""" onchange_use_template (values: True or False). If use_template is
@@ -141,8 +154,8 @@ class mail_compose_message(osv.TransientModel):
'attachment_ids': [(6, 0, [att.id for att in record.attachment_ids])]
}
template_id = email_template.create(cr, uid, values, context=context)
- record.write({'template_id': template_id, 'use_template': True})
- return True
+ record.write(record.onchange_template_id(True, template_id, record.composition_mode, record.model, record.res_id)['value'])
+ return _reopen(self, record.id, record.model)
#------------------------------------------------------
# Wizard validation and send
diff --git a/addons/email_template/wizard/mail_compose_message_view.xml b/addons/email_template/wizard/mail_compose_message_view.xml
index 0a530299d4a..5afaf9745e1 100644
--- a/addons/email_template/wizard/mail_compose_message_view.xml
+++ b/addons/email_template/wizard/mail_compose_message_view.xml
@@ -14,12 +14,11 @@
</xpath>
<xpath expr="//footer" position="inside">
<group class="oe_right" col="1">
- <div>Use template
+ <div attrs="{'invisible':[('use_template','=',False)]}">Use template
<field name="template_id" attrs="{'invisible':[('use_template','=',False)]}"
nolabel="1"
on_change="onchange_template_id(use_template, template_id, composition_mode, model, res_id, context)"/>
</div>
- or
<button icon="/email_template/static/src/img/email_template_save.png"
type="object" name="save_as_template" string="Save as new template" class="oe_link"
help="Save as a new template"
diff --git a/addons/mail/mail_thread_view.xml b/addons/mail/mail_thread_view.xml
index cdeade04d84..3a37218c813 100644
--- a/addons/mail/mail_thread_view.xml
+++ b/addons/mail/mail_thread_view.xml
@@ -7,7 +7,7 @@
<field name="res_model">mail.message</field>
<field name="context">{
'default_model': 'res.users',
- 'default_res_id': uid
+ 'default_res_id': uid,
}</field>
<field name="params" eval="&quot;{
'domain': [
diff --git a/addons/mail/res_partner.py b/addons/mail/res_partner.py
index df85ac3f17f..157699bd330 100644
--- a/addons/mail/res_partner.py
+++ b/addons/mail/res_partner.py
@@ -57,7 +57,8 @@ class res_partner_mail(osv.Model):
if thread_id not in partner_ids:
partner_ids.append(thread_id)
kwargs['partner_ids'] = partner_ids
- return super(res_partner_mail, self).message_post(cr, uid, False, body=body, subject=subject,
+ thread_id = False
+ return super(res_partner_mail, self).message_post(cr, uid, thread_id, body=body, subject=subject,
type=type, subtype=subtype, parent_id=parent_id, attachments=attachments, context=context, **kwargs)
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/addons/mail/res_users.py b/addons/mail/res_users.py
index 932c4dd9518..fcca12024b7 100644
--- a/addons/mail/res_users.py
+++ b/addons/mail/res_users.py
@@ -113,7 +113,8 @@ class res_users(osv.Model):
alias_pool.unlink(cr, uid, alias_ids, context=context)
return res
- def message_post_api(self, cr, uid, thread_id, body='', subject=False, parent_id=False, attachment_ids=None, context=None):
+ def message_post_user_api(self, cr, uid, thread_id, body='', subject=False, parent_id=False,
+ attachment_ids=None, context=None, content_subtype='plaintext', **kwargs):
""" Redirect the posting of message on res.users to the related partner.
This is done because when giving the context of Chatter on the
various mailboxes, we do not have access to the current partner_id.
@@ -124,8 +125,8 @@ class res_users(osv.Model):
if isinstance(thread_id, (list, tuple)):
thread_id = thread_id[0]
partner_id = self.pool.get('res.users').read(cr, uid, thread_id, ['partner_id'], context=context)['partner_id'][0]
- return self.pool.get('res.partner').message_post_api(cr, uid, partner_id, body=body, subject=subject,
- parent_id=parent_id, attachment_ids=attachment_ids, context=context)
+ return self.pool.get('res.partner').message_post_user_api(cr, uid, partner_id, body=body, subject=subject,
+ parent_id=parent_id, attachment_ids=attachment_ids, context=context, content_subtype=content_subtype, **kwargs)
def message_post(self, cr, uid, thread_id, context=None, **kwargs):
""" Redirect the posting of message on res.users to the related partner.
@@ -140,10 +141,6 @@ class res_users(osv.Model):
partner_id = self.pool.get('res.users').read(cr, uid, thread_id, ['partner_id'], context=context)['partner_id'][0]
return self.pool.get('res.partner').message_post(cr, uid, partner_id, context=context, **kwargs)
- def message_update(self, cr, uid, ids, msg_dict, update_vals=None, context=None):
- partner_id = self.pool.get('res.users').browse(cr, uid, ids)[0].partner_id.id
- return self.pool.get('res.partner').message_update(cr, uid, [partner_id], msg_dict,
- update_vals=update_vals, context=context)
class res_users_mail_group(osv.Model):
""" Update of res.users class
diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js
index e93a762981b..dc265a343d5 100644
--- a/addons/mail/static/src/js/mail.js
+++ b/addons/mail/static/src/js/mail.js
@@ -24,7 +24,7 @@ openerp.mail = function (session) {
*/
var context_keys = ['default_template_id', 'default_composition_mode',
'default_use_template', 'default_partner_ids', 'default_model',
- 'default_res_id', 'default_content_subtype', , 'default_subject',
+ 'default_res_id', 'default_content_subtype', 'default_subject',
'default_body', 'active_id', 'lang', 'bin_raw', 'tz',
'active_model', 'edi_web_url_view', 'active_ids',
'default_attachment_ids']
@@ -521,8 +521,6 @@ openerp.mail = function (session) {
on_compose_fullmail: function (default_composition_mode) {
if (default_composition_mode == 'reply') {
var context = {
- 'default_model': this.context.default_model,
- 'default_res_id': this.context.default_res_id,
'default_composition_mode': default_composition_mode,
'default_parent_id': this.id,
'default_body': mail.ChatterUtils.get_text2html(this.$el ? (this.$el.find('textarea:not(.oe_compact)').val() || '') : ''),
@@ -532,7 +530,6 @@ openerp.mail = function (session) {
var context = {
'default_model': this.context.default_model,
'default_res_id': this.context.default_res_id,
- 'default_content_subtype': 'html',
'default_composition_mode': default_composition_mode,
'default_parent_id': this.id,
'default_body': mail.ChatterUtils.get_text2html(this.$el ? (this.$el.find('textarea:not(.oe_compact)').val() || '') : ''),
@@ -601,16 +598,15 @@ openerp.mail = function (session) {
this.parent_thread.context
]).done(function (record) {
var thread = self.parent_thread;
-
if (self.options.display_indented_thread < self.thread_level && thread.parent_message) {
- thread = thread.parent_message.parent_thread;
+ var thread = thread.parent_message.parent_thread;
}
+ var root = thread == self.options.root_thread;
// create object and attach to the thread object
thread.message_fetch([['id', 'child_of', [self.id]]], false, [record], function (arg, data) {
- data[0].no_sorted = true;
var message = thread.create_message_object( data[0] );
// insert the message on dom
- thread.insert_message( message, self.$el );
+ thread.insert_message( message, root ? undefined : self.$el, root );
if (thread.parent_message) {
self.$el.remove();
self.parent_thread.compose_message = null;
@@ -1275,7 +1271,7 @@ openerp.mail = function (session) {
* The sort is define by the thread_level (O for newer on top).
* @param : {object} ThreadMessage object
*/
- insert_message: function (message, dom_insert_after) {
+ insert_message: function (message, dom_insert_after, prepend) {
var self=this;
if (this.options.show_compact_message > this.thread_level) {
this.instantiate_compose_message();
@@ -1287,6 +1283,8 @@ openerp.mail = function (session) {
if (dom_insert_after) {
message.insertAfter(dom_insert_after);
+ }if (prepend) {
+ message.prependTo(self.$el);
} else {
message.appendTo(self.$el);
}
@@ -1699,7 +1697,6 @@ openerp.mail = function (session) {
views: [[false, 'form']],
target: 'new',
context: {
- 'default_content_subtype': 'html',
},
};
session.client.action_manager.do_action(action);
@@ -1733,7 +1730,7 @@ openerp.mail = function (session) {
view_type: 'form',
views: [[false, 'form']],
target: 'new',
- context: { 'default_content_subtype': 'html' },
+ context: {},
};
session.client.action_manager.do_action(action);
},
diff --git a/addons/mail/static/src/xml/mail.xml b/addons/mail/static/src/xml/mail.xml
index 2ba1733043a..89fbe45dc36 100644
--- a/addons/mail/static/src/xml/mail.xml
+++ b/addons/mail/static/src/xml/mail.xml
@@ -95,14 +95,6 @@
</t>
</t>
- <t t-name="mail.thread.message.private">
- <div>
- <span class="oe_placeholder_checkbox_private"/>
- <span class="oe_send_private">This email is private.</span>
- <span class="oe_send_public">I wrote for contacts and all my followers.</span>
- </div>
- </t>
-
<!--
template to the recipients list
-->
diff --git a/addons/mail/tests/test_mail.py b/addons/mail/tests/test_mail.py
index 1cdb966ccbc..02b55cef9f7 100644
--- a/addons/mail/tests/test_mail.py
+++ b/addons/mail/tests/test_mail.py
@@ -463,7 +463,8 @@ class test_mail(test_mail_mockup.TestMailMockups):
# 1. Comment group_pigs with body_text and subject
compose_id = mail_compose.create(cr, uid,
{'subject': _subject, 'body_text': _body_text, 'partner_ids': [(4, p_c_id), (4, p_d_id)]},
- {'default_composition_mode': 'comment', 'default_model': 'mail.group', 'default_res_id': self.group_pigs_id})
+ {'default_composition_mode': 'comment', 'default_model': 'mail.group', 'default_res_id': self.group_pigs_id,
+ 'default_content_subtype': 'plaintext'})
compose = mail_compose.browse(cr, uid, compose_id)
# Test: mail.compose.message: composition_mode, model, res_id
self.assertEqual(compose.composition_mode, 'comment', 'mail.compose.message incorrect composition_mode')
diff --git a/addons/mail/wizard/mail_compose_message.py b/addons/mail/wizard/mail_compose_message.py
index 45082b9be4d..839a3a6970e 100644
--- a/addons/mail/wizard/mail_compose_message.py
+++ b/addons/mail/wizard/mail_compose_message.py
@@ -114,7 +114,7 @@ class mail_compose_message(osv.TransientModel):
_defaults = {
'composition_mode': 'comment',
- 'content_subtype': lambda self, cr, uid, ctx={}: 'plain',
+ 'content_subtype': lambda self, cr, uid, ctx={}: 'html',
'body_text': lambda self, cr, uid, ctx={}: False,
'body': lambda self, cr, uid, ctx={}: '',
'subject': lambda self, cr, uid, ctx={}: False,
@@ -135,7 +135,7 @@ 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.get(model).name_get(cr, uid, [res_id], context=context)
if doc_name_get:
record_name = doc_name_get[0][1]
else: