From e5e397b01baa6a7a09170fa71a988566c7fad3b6 Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Tue, 7 Jan 2014 11:53:24 +0100 Subject: [PATCH] [FIX] crm_partner_assign: on forward, set section_id if user_id has default section id bzr revid: dle@openerp.com-20140107105324-xaa21r8fnl0ncg66 --- .../wizard/crm_forward_to_partner.py | 2 ++ addons/im/static/src/js/im_common.js | 24 +++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/addons/crm_partner_assign/wizard/crm_forward_to_partner.py b/addons/crm_partner_assign/wizard/crm_forward_to_partner.py index 80fa2f28b04..fca2f9b746f 100644 --- a/addons/crm_partner_assign/wizard/crm_forward_to_partner.py +++ b/addons/crm_partner_assign/wizard/crm_forward_to_partner.py @@ -139,6 +139,8 @@ class crm_lead_forward_to_partner(osv.TransientModel): values = {'partner_assigned_id': partner_id, 'user_id': partner_leads['partner'].user_id.id} if stage_id: values['stage_id'] = stage_id + if partner_leads['partner'].user_id: + values['section_id'] = partner_leads['partner'].user_id.default_section_id.id lead_obj.write(cr, uid, lead_ids, values) self.pool.get('crm.lead').message_subscribe(cr, uid, lead_ids, [partner_id], context=context) return True diff --git a/addons/im/static/src/js/im_common.js b/addons/im/static/src/js/im_common.js index 83f92265ec6..73c35ebce51 100644 --- a/addons/im/static/src/js/im_common.js +++ b/addons/im/static/src/js/im_common.js @@ -88,6 +88,7 @@ function declare($, _, openerp) { this.users_cache = {}; this.last = null; this.unload_event_handler = _.bind(this.unload, this); + this.on("new_conversation", this, this.load_history); }, start_polling: function() { var self = this; @@ -252,11 +253,20 @@ function declare($, _, openerp) { } return def.then(function() {return conv}); }, + load_history: function(conv){ + var self = this; + im_common.connection.model("im.message").call("search", [[["session_id", "=", conv.session_id]], 0, 10]).then(function(message_ids){ + im_common.connection.model("im.message").call("read", [message_ids]).then(function(messages){ + messages.reverse(); + self.received_messages(messages); + }); + }); + }, received_messages: function(messages) { var self = this; var defs = []; var received = false; - _.each(messages, function(message) { + function post_message(message) { if (! message.technical) { defs.push(self.activate_session(message.session_id[0]).then(function(conv) { received = self.my_id !== message.from_id[0]; @@ -267,6 +277,15 @@ function declare($, _, openerp) { message.json = json; defs.push($.when(im_common.technical_messages_handlers[json.type](self, message))); } + } + _.each(messages, function(message){ + if (defs.length > 0){ + debugger; + defs[defs.length - 1].then(post_message(message)); + } + else{ + post_message(message); + } }); return $.when.apply($, defs).then(function(){ if (! self.get("window_focus") && received) { @@ -400,7 +419,7 @@ function declare($, _, openerp) { } else { this.set("pending", this.get("pending") + 1); } - this.c_manager.ensure_users([message.from_id[0]]).then(_.bind(function(users) { + return this.c_manager.ensure_users([message.from_id[0]]).then(_.bind(function(users) { var user = users[0]; if (! _.contains(this.get("users"), user) && ! _.contains(this.others, user)) { this.others.push(user); @@ -447,6 +466,7 @@ function declare($, _, openerp) { return new Array(size - str.length + 1).join('0') + str; }; date = "" + zpad(date.getHours(), 2) + ":" + zpad(date.getMinutes(), 2); + debugger; var to_show = _.map(items, im_common.escape_keep_url); this.last_bubble = $(openerp.qweb.render("im_common.conversation_bubble", {"items": to_show, "user": user, "time": date})); $(this.$(".oe_im_chatview_content").children()[0]).append(this.last_bubble);