Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to use our new javascript method in an already overriden method?

By
Pascal Tremblay
on 11/10/16, 12:27 PM 218 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???

0

Pascal Tremblay

--Pascal Tremblay--
1312
| 5 2 7
Alma, Canada
--Pascal Tremblay--


Pascal Tremblay
On 11/11/16, 2:55 PM

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){}
        }
    });
})();


0
shameem@aχoncoms
On 11/11/16, 12:20 AM

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 !

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.

Pascal Tremblay
on 11/11/16, 7:09 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 11/10/16, 12:27 PM
Seen: 218 times
Last updated: 11/11/16, 2:56 PM