This question has been flagged
3 Replies
5258 Views

Hello there,

We have made an override of the received_message javascript method of the im_chat module.


/home/odoo-iv/addons_pt/im_chat_lapagept/override.xml

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
        <template id="override_im_chat_backend" name="" inherit_id="web.assets_backend">
            <xpath expr="." position="inside">
                <script type="text/javascript" src="/im_chat_lapagept/static/src/js/override.js"></script>
            </xpath>
        </template>
        <template id="override_im_chat_frontend" inherit_id="website.assets_frontend" name="">
            <xpath expr="." position="inside">
                <script type="text/javascript" src="/im_chat_lapagept/static/src/js/override.js"></script>
            </xpath>
        </template>
    </data>
</openerp>


/home/odoo-iv/addons_pt/im_chat_lapagept/static/src/js/override.js

openerp.im_chat_lapagept = function(instance) {
    instance.im_chat.ConversationManager.include({
       received_message: function(message) {
            var self = this;
            var session_id = message.to_id[0];
            var uuid = message.to_id[1];
            //This code has been commented by us
            //if (! this.get("window_focus")) {

                //alert('gjhgjhg');
                this.set("waiting_messages", this.get("waiting_messages") + 1);
            //}
            var conv = this.sessions[uuid];
            if(!conv){
                // fetch the session, and init it with the message
                var def_session = new openerp.Model("im_chat.session").call("session_info", [], {"ids" : [session_id]}).then(function(session){
                    conv = self.activate_session(session, false);
                    conv.received_message(message);
                });
            }else{
                conv.received_message(message);
            }
        },
    })
  }


This new code works well in the backend. But not on the frontend.


On the frontend, it seems that the original received_message method is still used.

We think that the problem is in the im_livechat.js file where the original received_message method is also overriden.


/home/odoo-iv/odoo-8.0-20161109/openerp/addons/im_livechat/static/src/js/im_livechat.js

    openerp.im_chat.ConversationManager.include({
        received_message: function(message) {
            try{
                this._super(message);
            }catch(e){}
        }
    });


So our question is : how could we use our new method also in im_livechat.js???

Avatar
Discard
Author Best Answer

Thanks for your comments.

Here is how we managed to do it.


In/home/odoo-iv/addons_pt/im_chat_lapagept/override.xml

<template id="override_im_livechat" inherit_id="im_livechat.internal_lib" name="">
            <xpath expr="//script[@src='/im_livechat/static/src/js/im_livechat.js']" position="after">
                <script type="text/javascript" src="/im_chat_lapagept/static/src/js/im_livechat_override.js"></script>
            </xpath>
        </template>


In/home/odoo-iv/addons_pt/im_chat_lapagept/static/src/js/im_livechat_override.js

(function() {
    "use strict";
    var _t = openerp._t;
    var im_chat_lapagept = {};
    openerp.im_chat_lapagept = im_chat_lapagept;
       
    // To avoid exeption when the anonymous has close his
    // conversation and when operator send him a message.
    openerp.im_chat.ConversationManager.include({
        received_message: function(message) {
            try{
                //alert('received_message dans im_livechat_override.js');
                var self = this;
                var session_id = message.to_id[0];
                var uuid = message.to_id[1];
                //Commented by us to have a sound notification even if the window doesn't have the focus.
                //if (! this.get("window_focus")) {
                    //alert('emettre le son livechat-js');
                    this.set("waiting_messages", this.get("waiting_messages") + 1);
                //}
                var conv = this.sessions[uuid];
                if(!conv){
                    // fetch the session, and init it with the message
                    var def_session = new openerp.Model("im_chat.session").call("session_info", [], {"ids" : [session_id]}).then(function(session){                        conv = self.activate_session(session, false);
                        conv.received_message(message);
                    });
                }else{
                    conv.received_message(message);
                }
            }catch(e){}
        }
    });
})();


Avatar
Discard
Best Answer

Pascal,

I faced the same issue and I solved by overriding the template of assets.

Copy both template and set id to module_name.template_name then comment the js link of that (Blocking that Js). 

<template id="im_chat_lapagept.override_im_chat_backend" name="" inherit_id="web.assets_backend">
    <xpath expr="." position="inside">

        <!--<script type="text/javascript" src="/im_chat_lapagept/static/src/js/override.js"></script>
        -->
    </xpath>
</template>


<template id="im_chat_lapagept.override_im_chat_frontend" inherit_id="website.assets_frontend" name="">
    <xpath expr="." position="inside">

        <!--<script type="text/javascript" src="/im_chat_lapagept/static/src/js/override.js"></script>
        -->
    </xpath>
</template>

 Copy all contents of override.js (ctrl+A , ctrl+C) to im_livechat.js(ctrl+V).
It may override the complete override.js.

All the best !

Avatar
Discard
Author

im_livechat.js is a file in the official distribution of odoo. SHould I not put my code in a custom module rather? Thanks for your help.