Skip to Content
Odoo Menu
  • Prijavi
  • Try it free
  • Aplikacije
    Finance
    • Knjigovodstvo
    • Obračun
    • Stroški
    • Spreadsheet (BI)
    • Dokumenti
    • Podpisovanje
    Prodaja
    • CRM
    • Prodaja
    • POS Shop
    • POS Restaurant
    • Naročnine
    • Najem
    Spletne strani
    • Website Builder
    • Spletna trgovina
    • Blog
    • Forum
    • Pogovor v živo
    • eUčenje
    Dobavna veriga
    • Zaloga
    • Proizvodnja
    • PLM
    • Nabava
    • Vzdrževanje
    • Kakovost
    Kadri
    • Kadri
    • Kadrovanje
    • Odsotnost
    • Ocenjevanja
    • Priporočila
    • Vozni park
    Marketing
    • Družbeno Trženje
    • Email Marketing
    • SMS Marketing
    • Dogodki
    • Avtomatizacija trženja
    • Ankete
    Storitve
    • Projekt
    • Časovnice
    • Storitve na terenu
    • Služba za pomoč
    • Načrtovanje
    • Termini
    Produktivnost
    • Razprave
    • Odobritve
    • IoT
    • Voip
    • Znanje
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industrije
    Trgovina na drobno
    • Book Store
    • Trgovina z oblačili
    • Trgovina s pohištvom
    • Grocery Store
    • Trgovina s strojno opremo računalnikov
    • Trgovina z igračami
    Food & Hospitality
    • Bar and Pub
    • Restavracija
    • Hitra hrana
    • Guest House
    • Beverage Distributor
    • Hotel
    Nepremičnine
    • Real Estate Agency
    • Arhitekturno podjetje
    • Gradbeništvo
    • Estate Management
    • Vrtnarjenje
    • Združenje lastnikov nepremičnin
    Svetovanje
    • Računovodsko podjetje
    • Odoo Partner
    • Marketinška agencija
    • Law firm
    • Pridobivanje talentov
    • Audit & Certification
    Proizvodnja
    • Tekstil
    • Metal
    • Pohištvo
    • Hrana
    • Brewery
    • Poslovna darila
    Health & Fitness
    • Športni klub
    • Trgovina z očali
    • Fitnes center
    • Wellness Practitioners
    • Lekarna
    • Frizerski salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Sistemi sončne energije
    • Izdelovalec čevljev
    • Čistilne storitve
    • HVAC Services
    Ostali
    • Neprofitna organizacija
    • Agencija za okolje
    • Najem oglasnih panojev
    • Fotografija
    • Najem koles
    • Prodajalec programske opreme
    Browse all Industries
  • Skupnost
    Learn
    • Tutorials
    • Dokumentacija
    • Certifikati
    • Šolanje
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Prenesi
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Dogodki
    • Prevodi
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Sklici kupca
    • Podpora
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Določanje cen
  • Pomoč

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

  • CRM
  • e-Commerce
  • Knjigovodstvo
  • Zaloga
  • PoS
  • Projekt
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
Pomoč

How to create systray icon that shows data from model?

Naroči se

Get notified when there's activity on this post

This question has been flagged
javascriptOdoo13.0systray
3 Odgovori
7508 Prikazi
Avatar
Samo Arko

I'm very bad at JS. I've looked at the mail modules systray icons javascript and template files. I've read the javascript cheetsheet and referance documentation but I cannot get it to work.

I want to gave a systray icon that shows a number same as the mail systray icons and when you click on it, a div with the message apears. The number and message need to be gotten from a models method. This means that I've got a problem with asynchronous promise function. The custom module returns json dump of a dict

JS Code:

odoo.define('odoo13_demo_timer.DemoDays', function (require) {
    'use strict';

    var core = require('web.core');
    var session = require('web.session');
    var SystrayMenu = require('web.SystrayMenu');
    var Widget = require('web.Widget');
    var Qweb = core.qweb;

    var DemoDays = Widget.extend({
        name: 'demo_days_menu',
        template: 'odoo13_demo_timer.DemoDays',
        events: {
            'show.bs.dropdown': '_onDemoDaysShow',
            'hide.bs.dropdown': '_onDemoDaysHide',
        },
        start: function() {
            this._getDemoDaysData();
            return this._super();
        },
        _getDemoDaysData: function() {
            var self = this;

            return self._rpc({
                model: 'demo.installation',
                method: 'get_systray_dict',
                args: [],
                kwargs: {context: session.user_context},
            }).then(function (data) {
                self.demo_days_data = data;
                self.$('.o_demo_days_counter').addClass(data.message_class);
                self.$('.o_demo_days_counter').text(data.expires);
                self.$('.demo_days_message').append(data.message);
            });
        },
        _onDemoDaysShow: function () {
            document.body.classList.add('modal-open');
        },
        _onDemoDaysHide: function () {
            document.body.classList.remove('modal-open');
        },
    });
    DemoDays.prototype.sequence = 100;
    SystrayMenu.Items.push(DemoDays);

    return DemoDays;
});

Template:

<?xml version="1.0" encoding="UTF-8"?>
<templates>
    <t t-name="odoo13_demo_timer.DemoDays">
        <li class="o_timer_systray_item">
            <a class="dropdown-toggle o-no-caret" data-toggle="dropdown" data-display="static" aria-expanded="false" title="Demo Days" href="#" role="button">
                <i class="fa fa-history" role="img" aria-label="Demo Days"/> <span class="o_demo_days_counter badge badge-pill"/>
            </a>
            <div class="o_demo_days_systray_dropdown dropdown-menu dropdown-menu-right">
                <span class="demo_days_message"/>
            </div>
        </li>
    </t>
</templates>

If I hard code the number and message in the start function it works. Getting the data from the model doesn't work. I wasted hours with trying different things but I just cannot get it  to work.

start: function() {
    this.$('.o_demo_days_counter').addClass('green');
    this.$('.o_demo_days_counter').text('15');
    this.$('.demo_days_message').append('some text for message');
},


Can someone help?  


EDIT:

The data is now accessible, when I updated the code with the answer for promise. But it still does not show the data!? Really need help with this.


2
Avatar
Opusti
Samo Arko
Avtor

Finally I've got it to work.

Used @Ravi Gadhia answer for help with the promise. Moved the promise to willStart and only set the DOM elements in the start.

Avatar
Ravi Gadhia
Best Answer
start: function() {
var self = this;
return Promise.all([this._super.apply(this, arguments), this._getDemoDaysData()]).then(function () {
self.$('.o_demo_days_counter').addClass(self.demo_days_data.message_class);
self.$('.o_demo_days_counter').text(self.demo_days_data.expires);
self.$('.demo_days_message').append(self.demo_days_data.message);
});
});

},
_getDemoDaysData: function() { var self = this;
return this._rpc({
model: 'demo.installation',
method: 'get_systray_dict',
args: [],
kwargs: {context: session.user_context},
}).then(function (data) {
self.demo_days_data = data;
})
},

try this it will resolve if there is promise issue note: please corrent sytext error if any
2
Avatar
Opusti
Samo Arko
Avtor

Thanks, I have the data but it still does not show the counter or message. You have one to many }); in the return Promise.

Akshay Birajdar

Can you please post the get_systray_dict function?

Samo Arko
Avtor

@api.model

def get_systray_dict(self):

demos_obj = dict()

demo_install = self.with_user(SUPERUSER_ID).search([])

if not demo_install:

return json.dumps(demos_obj)

demo_install = demo_install[0]

now = datetime.now().date()

delta = now - demo_install.database_creation

demos_obj['name'] = demo_install.name

demos_obj['days_ago'] = delta.days

demos_obj['expires'] = EXPIRATION_DAYS - demos_obj['days_ago']

demos_obj['deletes'] = DELETION_DAYS - demos_obj['days_ago']

demos_obj['message'] = u'MESSAGE'

if demos_obj['expires'] <= 3:

demos_obj['message_class'] = 'red'

elif demos_obj['expires'] <= 9:

demos_obj['message_class'] = 'yellow'

elif demos_obj['expires'] > 9:

demos_obj['message_class'] = 'green'

else:

demos_obj['message_class'] = 'green'

return json.dumps(demos_obj)

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

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

Prijavi
Related Posts Odgovori Prikazi Aktivnost
ODOO13 JS Framework how to load vis.js graph Solved
javascript Odoo13.0
Avatar
1
maj 20
5185
How to refresh a kanban view automatically - Odoo13 ?
javascript Odoo13.0
Avatar
Avatar
Avatar
2
feb. 20
6574
How to insert new event in Odoo calendar using another application in javascript
javascript Odoo13.0
Avatar
0
dec. 19
4965
Javascript get model ID from where this JS Function is being called.
javascript Odoo13.0 v14
Avatar
Avatar
1
jun. 24
4285
How to create systray icon?
javascript systray v15
Avatar
Avatar
1
jun. 22
3632
Community
  • Tutorials
  • Dokumentacija
  • Forum
Open Source
  • Prenesi
  • Github
  • Runbot
  • Prevodi
Services
  • Odoo.sh Hosting
  • Podpora
  • Nadgradnja
  • Custom Developments
  • Izobraževanje
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Sredstva blagovne znamke
  • Kontakt
  • Zaposlitve
  • Dogodki
  • Podcast
  • Blog
  • Stranke
  • Pravno • Zasebnost
  • Varnost
الْعَرَبيّة 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