İçereği Atla
Odoo Menü
  • Portal
  • Ücretsiz deneyin
  • Uygulamalar
    Finans
    • Muhasebe
    • Faturalama
    • Masraf Yönetimi
    • Elektronik Çizelge (BI)
    • Belgeler
    • İmza
    Satış
    • Müşteri İlişkileri Yönetimi (CRM)
    • Satış
    • Satış Noktası Mağaza
    • Satış Noktası Restoran
    • Abonelikler
    • Kiralama
    Web Sitesi
    • Web Sitesi Oluşturucu
    • eTicaret
    • Blog
    • Forum
    • Canlı Sohbet
    • eÖğrenme
    Tedarik Zinciri
    • Envanter
    • Üretim
    • Ürün Yaşam Döngüsü Yönetimi
    • Satın Alma
    • Bakım
    • Kalite
    İnsan Kaynakları
    • Çalışanlar
    • İşe Alım
    • İzin
    • Değerlendirme
    • Referans
    • Filo Yönetimi
    Pazarlama
    • Sosyal Medyada Pazarlama
    • E-posta ile Pazarlama
    • SMS ile Pazarlama
    • Etkinlikler
    • Pazarlama Otomasyonu
    • Anket
    Hizmetler
    • Proje Yönetimi
    • Çalışma Çizelgeleri
    • Saha Hizmeti
    • Yardım Masası
    • Planlama
    • Randevular
    Verimlilik
    • Sohbet
    • Onay
    • Nesnelerin İnterneti
    • VoIP
    • Bilgi Bankası
    • WhatsApp
    Üçüncü taraf uygulamalar Odoo Stüdyo Odoo Bulut Platformu
  • Sektörler
    Perakende satış
    • Kitapçı
    • Giyim Mağazası
    • Mobilya Mağazası
    • Gıda Marketi
    • Hırdavat Dükkanı
    • Oyuncak Dükkanı
    Gıda ve Konaklama
    • Bar ve Pub
    • Restoran
    • Fast Food Restoranı
    • Konuk Evi
    • İçecek Distribütörü
    • Otel
    Gayrimenkul
    • Emlak Acentesi
    • Mimarlık Firması
    • İnşaat
    • Emlak Yönetimi
    • Bahçe Tasarımı
    • Mülk Sahipleri Derneği
    Uzmanlık
    • Muhasebe Firması
    • Odoo Partner
    • Pazarlama Ajansı
    • Hukuk Firması
    • Yetenek Kazanımı
    • Denetim ve Belgelendirme
    Üretim
    • Tekstil
    • Metal
    • Mobilyalar
    • Gıda
    • Bira fabrikası
    • Kurumsal Hediye
    Sağlık ve Spor
    • Spor Kulübü
    • Optik Mağazası
    • Fitness Merkezi
    • Sağlıklı Yaşam Merkezi
    • Eczane
    • Kuaför Salonu
    Ticaret
    • Tamirci
    • BT Donanım & Destek
    • Güneş Enerjisi Sistemleri
    • Ayakkabı İmalatçısı
    • Temizlik Hizmetleri
    • HVAC Hizmetleri
    Diğerleri
    • Kar Amacı Gütmeyen Kuruluş
    • Çevre Ajansı
    • Reklam Panosu Kiralama
    • Fotoğrafçılık
    • Bisiklet Kiralama
    • Yazılım Bayisi
    Tüm Sektörlere Göz Atın
  • Topluluk
    Öğrenim
    • Eğitim Araçları
    • Dokümantasyon
    • Sertifikasyonlar
    • Eğitim Etkinlikleri
    • Blog
    • Podcast
    Eğitim ve Gelişim
    • Eğitim Programı
    • Scale Up! İşletme Oyunu
    • Odoo'yu Ziyaret Edin
    Yazılım
    • İndirin
    • Sürümleri Kıyaslayın
    • Sürümler
    İş Birliği
    • Github
    • Forum
    • Etkinlikler
    • Çeviriler
    • Partner Olun
    • Partnerler için Hizmetler
    • Muhasebe Firmanızı Kaydettirin
    Hizmetler
    • Partner Bulun
    • Muhasebeci Bulun
    • Bir danışmanla görüşün
    • Kurulum Hizmetleri
    • Müşteri Referansları
    • Destek
    • Sürüm Yükseltme
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Demo randevusu alın
  • Fiyatlandırma
  • Yardım

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

  • Müşteri İlişkileri Yönetimi
  • e-Commerce
  • Muhasebe
  • Envanter
  • PoS
  • Proje Yönetimi
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiketler (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiketler (View all)
odoo accounting v14 pos v15
About this forum
Yardım

How to override JS code in Odoo?

Abone Ol

Get notified when there's activity on this post

Bu soru işaretlendi
securityv8jsgroups
2 Cevaplar
21740 Görünümler
Avatar
Alejandro Santana

Summary:

  • I have a situation where I inherit from im_chat module and I want to hide the top menu chat button from all users but the ones belonging to a group I created.
  • I can add the button in case user belongs to that group, but I am not able to remove the one created by inherited module, nor prevent its creation because my JS function is executed before the one in im_chat.
  • First I have tried to set the groups policy in the button with qweb, but without any luck (see forum thread: https://www.odoo.com/forum/help-1/question/how-to-use-groups-policies-in-qweb-templates-74256 and bug issue report in Github: https://github.com/odoo/odoo/issues/5058 )
  • This is my first encounter with JS

Detailed explanation:

I am writing a new module that depends on im_chat module. I want to hide the top menu chat button (the one with the chat bubbles) from all users but the ones belonging to a security group I created.

In the im_chat module, I find what I should modify. In addons/im_chat/static/src/js/im_chat.js I find this code, starting with:

(function(){

    "use strict";

    console.log("Original WTF");
    var _t = openerp._t;
    var _lt = openerp._lt;
    var QWeb = openerp.qweb;
    var NBR_LIMIT_HISTORY = 20;
    var USERS_LIMIT = 20;
    var im_chat = openerp.im_chat = {};

...code continues almost till the end, where is the key part, an isolated if condition, which adds the button if user belongs to base.group_users and is an employee:

    im_chat.ImTopButton = openerp.Widget.extend({
        template:'im_chat.ImTopButton',
        events: {
            "click": "clicked",
        },
        clicked: function(ev) {
            ev.preventDefault();
            this.trigger("clicked");
        },
    });

    if(openerp.web && openerp.web.UserMenu) {
        openerp.web.UserMenu.include({
            do_update: function(){
                var self = this;
                var Users = new openerp.web.Model('res.users');
                Users.call('has_group', ['base.group_user']).done(function(is_employee) {
                    if (is_employee) {
                        self.update_promise.then(function() {
                            var im = new openerp.im_chat.InstantMessaging(self);
                            openerp.im_chat.single = im;
                            im.appendTo(openerp.client.$el);
                            var button = new openerp.im_chat.ImTopButton(this);
                            button.on("clicked", im, im.switch_display);
                            button.appendTo(window.$('.oe_systray'));
                        });
                    }
                });

                return this._super.apply(this, arguments);
            },
        });
    }

    return im_chat;
})();

But, when I create addons/my_module/static/src/js/im_chat.js, I find no way to replace that behaviour, nor to extend or whatever. The function has no name, as file starts with just:

(function(){

and the if condition is not inheritable (no id, no name, no class).

So, if I put this code in addons/my_module/static/src/js/im_chat.js:

(function (){
    
    "use strict";
    var _t = openerp._t;
    var _lt = openerp._lt;
    var QWeb = openerp.qweb;
    var NBR_LIMIT_HISTORY = 20;
    var USERS_LIMIT = 20;
    var im_chat = openerp.im_chat = {};

    if(openerp.web && openerp.web.UserMenu) {
        openerp.web.UserMenu.include({
            do_update: function(){
                $("#oe_topbar_imbutton_icon").remove();
                var self = this;
                var Users = new openerp.web.Model('res.users');
                Users.call('has_group', ['my_module.group_my_module_manager']).done(function(is_employee) {
                    if (is_employee) {
                        self.update_promise.then(function() {
                            var im = new openerp.im_chat.InstantMessaging(self);
                            openerp.im_chat.single = im;
                            im.appendTo(openerp.client.$el);
                            var button = new openerp.im_chat.ImTopButton(this);
                            button.on("clicked", im, im.switch_display);
                            button.appendTo(window.$('.oe_systray'));
                        });
                    }
                });
                return this._super.apply(this, arguments);
            },
        });
    }

    return im_chat;
})();

It works fine... in its own. It adds a button if user belongs to group 'my_module.group_my_module_manager', but I have no control over im_chat. So I may get two buttons.

Even more... I cannot remove the button creaated in im_chat with mine, because my code seems to execute always after the code in im_chat.

 

So... how do I remove that im_chat button and keep the one I add in my module?

 

0
Avatar
Vazgeç
Avatar
Alejandro Santana
Üretici En İyi Yanıt

The only way I have found so far (remember I am completely new to JS and could not get rid of its uncontrollable asynchronous behaviour) is to override the original im_chat.js file with the one in my module. How? Using this my_module/views/im_chat.xml file:

<?xml version="1.0" encoding="utf-8"?>

<openerp>
    <data>
        <template id="im_chat.assets_backend" name="im_chat assets" inherit_id="web.assets_backend">
            <xpath expr="." position="inside">
                <link rel="stylesheet" href="/im_chat/static/src/css/im_common.css"/>
                <link rel="stylesheet" href="/im_chat/static/src/css/im_chat.css"/>
                <script type="text/javascript" src="/my_module/static/src/js/im_chat.js"></script>
            </xpath>
        </template>
    </data>
</openerp>

And in /my_module/static/src/js/im_chat.js, I had to duplicate the whole code in /im_chat/static/src/js/im_chat.js but changing some lines almost at the end. Not pretty but it works. Final if condition, modified:


    if(openerp.web && openerp.web.UserMenu) {
        openerp.web.UserMenu.include({
            do_update: function(){
                var self = this;
                var Users = new openerp.web.Model('res.users');
                var im = new openerp.im_chat.InstantMessaging(self);
                Users.call('has_group', ['base.group_user']).done(function(is_employee) {
                    if (is_employee) {
                        self.update_promise.then(function() {
                            openerp.im_chat.single = im;
                            im.appendTo(openerp.client.$el);
                            console.log("Creating im_chat for users");
                        });
                    }
                });
                Users.call('has_group', ['my_module.group_my_modulemanager']).done(function(is_employee) {
                    if (is_employee) {
                        self.update_promise.then(function() {
                            openerp.im_chat.single = im;
                            im.appendTo(openerp.client.$el);
                            var button = new openerp.im_chat.ImTopButton(this);
                            button.on("clicked", im, im.switch_display);
                            button.appendTo(window.$('.oe_systray'));
                            console.log("Creating im_chat button for managers");
                        });
                    }
                });
                return this._super.apply(this, arguments);
            },
        });
    }

 

 

 

0
Avatar
Vazgeç
Avatar
Shawn Varghese
En İyi Yanıt

I dont have a resolution, but I may be able to give some idea as to why this happens.

I think the problem is that you are returning the super method:

return this._super.apply(this, arguments);

As I understand it, 'super' calls the parent method, which in this case is the original function. Therefore, your function as well as the original function gets invoked. If you comment that return statement, you will find that only your custom button appears and the default button does not. At least, that's what I observed in my case. But obviously, that is not the way to go. The only thing that I have been able to do in such cases is to create a copy of the whole im_chat module, make all the modifications in the copy and only install that and not the original module.

0
Avatar
Vazgeç
Enjoying the discussion? Don't just read, join in!

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

Üye Ol
İlgili Gönderiler Cevaplar Görünümler Aktivite
Is it correct to define a group as base.group_name in custom modules?
security v8 groups
Avatar
0
May 16
5802
How to use groups policies in qweb templates? Çözüldü
security v8 qweb groups
Avatar
Avatar
1
Nis 19
18294
Get id of new Group Çözüldü
security v8 buttons groups
Avatar
Avatar
2
Tem 15
7290
Security Fear: Make fields of a model secret without using groups attribute
security groups
Avatar
0
Kas 15
5616
In Javascript, how to set a boolean variable for Users.call? Çözüldü
v8 js
Avatar
1
Nis 15
6900
Topluluk
  • Eğitim Araçları
  • Dokümantasyon
  • Forum
Açık Kaynak
  • İndirin
  • Github
  • Runbot
  • Çeviriler
Hizmetler
  • Odoo.sh Hosting
  • Destek
  • Sürüm Yükseltme
  • Özel Geliştirmeler
  • Eğitim
  • Muhasebeci Bulun
  • Partner Bulun
  • Partner Olun
Hakkında
  • Şirketimiz
  • Pazarlama Gereçleri
  • İletişim
  • Kariyer
  • Etkinlikler
  • Podcast
  • Blog
  • Müşteriler
  • Hukuki • Gizlilik
  • Güvenlik
الْعَرَبيّة 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, müşteri ilişkileri yönetimi, eTicaret, muhasebe, envanter, satış noktası, proje yönetimi gibi şirketinizin tüm ihtiyaçlarını karşılayan bir açık kaynak işletme uygulamaları paketidir.

Odoo’nun eşsiz değer önermesi, aynı anda hem kullanımının çok kolay olup hem de tamamen entegre olmasıdır.

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