[IMP] mail: open wizard(s) to create partner(s) before send message from email

bzr revid: chm@openerp.com-20121221101232-od1owyxhkhmorx5t
This commit is contained in:
Christophe Matthieu
2012-12-21 11:12:32 +01:00
parent bfa8c20431
commit e5c67bc1b9
2 changed files with 74 additions and 64 deletions
+10 -18
View File
@@ -455,9 +455,8 @@ class mail_thread(osv.AbstractModel):
else:
assert thread_id == 0, "Posting a message without model should be with a null res_id, to create a private message."
model_pool = self.pool.get('mail.thread')
new_msg_informations = model_pool.message_post_user_api(cr, uid, [thread_id], context=context, content_subtype='html', **msg)
new_msg_id = new_msg_informations['message_id'];
new_msg_id = model_pool.message_post_user_api(cr, uid, [thread_id], context=context, content_subtype='html', **msg)
if partner_ids:
# postponed after message_post, because this is an external message and we don't want to create
# duplicate emails due to notifications
@@ -773,17 +772,14 @@ class mail_thread(osv.AbstractModel):
body = tools.plaintext2html(body)
new_partner_ids = set([])
link_partner_ids = set([])
for partner in extra_email:
part_ids = self.pool.get('res.partner').search(cr, uid, [('email', '=', partner)], context=context)
if not part_ids:
# create a new partner
part_ids = [self.pool.get('res.partner').name_create(cr, uid, partner, context=dict())[0]]
new_partner_ids |= set(part_ids)
else:
# partners is already create
link_partner_ids |= set(part_ids)
# create a new partner if not exists
if not part_ids:
part_ids = [self.pool.get('res.partner').name_create(cr, uid, partner, context=dict())[0]]
new_partner_ids |= set(part_ids)
self.message_subscribe(cr, uid, [thread_id], part_ids, context=context)
# link mail with this from mail to the new partner id
@@ -791,9 +787,8 @@ class mail_thread(osv.AbstractModel):
if part_ids and message_ids:
mail_message.write(cr, uid, message_ids, {'email_from': None, 'author_id': part_ids[0]}, context=context)
partner_ids = set(kwargs.pop('partner_ids', [])) | set(new_partner_ids) | set(link_partner_ids)
partner_ids = set(kwargs.pop('partner_ids', [])) | set(new_partner_ids)
if parent_id:
parent_message = self.pool.get('mail.message').browse(cr, uid, parent_id, context=context)
partner_ids |= set([(4, partner.id) for partner in parent_message.partner_ids])
@@ -826,10 +821,7 @@ class mail_thread(osv.AbstractModel):
ir_attachment.write(cr, SUPERUSER_ID, attachment_ids, {'res_model': model, 'res_id': thread_id}, context=context)
mail_message.write(cr, SUPERUSER_ID, [new_message_id], {'attachment_ids': [(6, 0, [pid for pid in attachment_ids])]}, context=context)
return {
'message_id': new_message_id,
'new_partner_ids': list(new_partner_ids),
}
return new_message_id
#------------------------------------------------------
# Followers API
+64 -46
View File
@@ -564,57 +564,75 @@ openerp.mail = function (session) {
}
},
/*post a message and fetch the message*/
check_recipient_partners: function (emails) {
var self = this;
var deferreds = [];
_.each(emails, function (email) {
var deferred = $.Deferred();
var pop = new session.web.form.FormOpenPopup(this);
pop.show_element(
'res.partner',
0,
{
'default_email': email,
'force_email': true,
'ref': "compound_context",
},
{
title: _t("Please complete partner's informations"),
}
);
pop.on('write_completed, closed', self, function () {
deferred.resolve();
});
deferreds.push(deferred);
});
return $.when.apply( $, deferreds );
},
on_message_post: function (event) {
var self = this;
var comment_node = this.$('textarea');
var body = comment_node.val();
if (this.do_check_attachment_upload() && (this.attachment_ids.length || body.match(/\S+/))) {
//session.web.blockUI();
var values = [
this.context.default_res_id, //thread_id
body, //body
false, //subject
this.context.default_parent_id, //parent_id
_.map(this.attachment_ids, function (file) {return file.id;}), //attachment_ids
_.map(_.filter(this.emails_from, function (f) {return f[1]}), function (f) {return f[0]}), //extra_email
this.parent_thread.context, // context
];
this.parent_thread.ds_thread.call('message_post_user_api', values).done(function (record) {
var thread = self.parent_thread;
var root = thread == self.options.root_thread;
if (self.options.display_indented_thread < self.thread_level && thread.parent_message) {
var thread = thread.parent_message.parent_thread;
}
// create object and attach to the thread object
thread.message_fetch([["id", "=", record.message_id]], false, [record.message_id], function (arg, data) {
var message = thread.create_message_object( data[0] );
// insert the message on dom
thread.insert_message( message, root ? undefined : self.$el, root );
});
self.on_cancel();
if (record.new_partner_ids && record.new_partner_ids.length) {
_.each(record.new_partner_ids, function (id) {
var pop = new session.web.form.FormOpenPopup(self);
pop.show_element(
'res.partner',
id,
self.parent_thread.context,
{
title: _t("Please complete partner's informations"),
}
);
});
}
//session.web.unblockUI();
});
return true;
if (this.do_check_attachment_upload() && (this.attachment_ids.length || this.$('textarea').val().match(/\S+/))) {
// create list of new partners
var extra_email = _.map(_.filter(this.emails_from, function (f) {return f[1]}), function (f) {return f[0]});
this.check_recipient_partners(extra_email).done(function () {
self.do_send_message_post();
});
}
},
/*do post a message and fetch the message*/
do_send_message_post: function () {
console.log(arguments);
return;
var self = this;
//session.web.blockUI();
var values = [
this.context.default_res_id, //thread_id
this.$('textarea').val(), //body
false, //subject
this.context.default_parent_id, //parent_id
_.map(this.attachment_ids, function (file) {return file.id;}), //attachment_ids
_.map(_.filter(this.emails_from, function (f) {return f[1]}), function (f) {return f[0]}), //extra_email
this.parent_thread.context, // context
];
this.parent_thread.ds_thread.call('message_post_user_api', values).done(function (message_id) {
var thread = self.parent_thread;
var root = thread == self.options.root_thread;
if (self.options.display_indented_thread < self.thread_level && thread.parent_message) {
var thread = thread.parent_message.parent_thread;
}
// create object and attach to the thread object
thread.message_fetch([["id", "=", message_id]], false, [message_id], function (arg, data) {
var message = thread.create_message_object( data[0] );
// insert the message on dom
thread.insert_message( message, root ? undefined : self.$el, root );
});
self.on_cancel();
//session.web.unblockUI();
});
},
/* convert the compact mode into the compose message
*/
on_compose_expandable: function (event) {