Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

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

Subscribe

Get notified when there's activity on this post

This question has been flagged
javascriptmethodoverride
3 Replies
7422 Views
Avatar
Pascal Tremblay

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
Avatar
Discard
Avatar
Pascal Tremblay
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){}
        }
    });
})();


0
Avatar
Discard
Avatar
Shameem Babu
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 !

1
Avatar
Discard
Pascal Tremblay
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.

Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Sign up
Related Posts Replies Views Activity
How i can override the activity js file in odoo 14?
javascript override
Avatar
Avatar
1
Aug 23
3789
Override JS mail Solved
javascript override
Avatar
Avatar
Avatar
3
Jul 21
5983
inheriting Javascript file Odoo 12
javascript override
Avatar
Avatar
1
Aug 19
4184
override the makeOrder method.
method override
Avatar
0
May 16
4062
override a method inheritance Solved
method override
Avatar
Avatar
Avatar
2
Dec 15
3482
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now