Passa al contenuto
Odoo Menu
  • Accedi
  • Provalo gratis
  • App
    Finanze
    • Contabilità
    • Fatturazione
    • Note spese
    • Fogli di calcolo (BI)
    • Documenti
    • Firma
    Vendite
    • CRM
    • Vendite
    • Punto vendita Negozio
    • Punto vendita Ristorante
    • Abbonamenti
    • Noleggi
    Siti web
    • Configuratore sito web
    • E-commerce
    • Blog
    • Forum
    • Live chat
    • E-learning
    Supply chain
    • Magazzino
    • Produzione
    • PLM
    • Acquisti
    • Manutenzione
    • Qualità
    Risorse umane
    • Dipendenti
    • Assunzioni
    • Ferie
    • Valutazioni
    • Referral dipendenti
    • Parco veicoli
    Marketing
    • Social marketing
    • E-mail marketing
    • SMS marketing
    • Eventi
    • Marketing automation
    • Sondaggi
    Servizi
    • Progetti
    • Fogli ore
    • Assistenza sul campo
    • Helpdesk
    • Pianificazione
    • Appuntamenti
    Produttività
    • Comunicazioni
    • Approvazioni
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    App di terze parti Odoo Studio Piattaforma cloud Odoo
  • Settori
    Retail
    • Libreria
    • Negozio di abbigliamento
    • Negozio di arredamento
    • Alimentari
    • Ferramenta
    • Negozio di giocattoli
    Cibo e ospitalità
    • Bar e pub
    • Ristorante
    • Fast food
    • Pensione
    • Grossista di bevande
    • Hotel
    Agenzia immobiliare
    • Agenzia immobiliare
    • Studio di architettura
    • Edilizia
    • Gestione immobiliare
    • Impresa di giardinaggio
    • Associazione di proprietari immobiliari
    Consulenza
    • Società di contabilità
    • Partner Odoo
    • Agenzia di marketing
    • Studio legale
    • Selezione del personale
    • Audit e certificazione
    Produzione
    • Tessile
    • Metallo
    • Arredamenti
    • Alimentare
    • Birrificio
    • Ditta di regalistica aziendale
    Benessere e sport
    • Club sportivo
    • Negozio di ottica
    • Centro fitness
    • Centro benessere
    • Farmacia
    • Parrucchiere
    Commercio
    • Tuttofare
    • Hardware e assistenza IT
    • Ditta di installazione di pannelli solari
    • Calzolaio
    • Servizi di pulizia
    • Servizi di climatizzazione
    Altro
    • Organizzazione non profit
    • Ente per la tutela ambientale
    • Agenzia di cartellonistica pubblicitaria
    • Studio fotografico
    • Punto noleggio di biciclette
    • Rivenditore di software
    Carica tutti i settori
  • Community
    Apprendimento
    • Tutorial
    • Documentazione
    • Certificazioni 
    • Formazione
    • Blog
    • Podcast
    Potenzia la tua formazione
    • Programma educativo
    • Scale Up! Business Game
    • Visita Odoo
    Ottieni il software
    • Scarica
    • Versioni a confronto
    • Note di versione
    Collabora
    • Github
    • Forum
    • Eventi
    • Traduzioni
    • Diventa nostro partner
    • Servizi per partner
    • Registra la tua società di contabilità
    Ottieni servizi
    • Trova un partner
    • Trova un contabile
    • Incontra un esperto
    • Servizi di implementazione
    • Testimonianze dei clienti
    • Supporto
    • Aggiornamenti
    GitHub Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Richiedi una demo
  • Prezzi
  • Aiuto

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

  • CRM
  • e-Commerce
  • Contabilità
  • Magazzino
  • PoS
  • Progetti
  • MRP
All apps
È necessario essere registrati per interagire con la community.
Tutti gli articoli Persone Badge
Etichette (Mostra tutto)
odoo accounting v14 pos v15
Sul forum
È necessario essere registrati per interagire con la community.
Tutti gli articoli Persone Badge
Etichette (Mostra tutto)
odoo accounting v14 pos v15
Sul forum
Assistenza

How to create systray icon that shows data from model?

Iscriviti

Ricevi una notifica quando c'è un'attività per questo post

La domanda è stata contrassegnata
javascriptOdoo13.0systray
3 Risposte
7516 Visualizzazioni
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
Abbandona
Samo Arko
Autore

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
Risposta migliore
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
Abbandona
Samo Arko
Autore

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
Autore

@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)

Ti stai godendo la conversazione? Non leggere soltanto, partecipa anche tu!

Crea un account oggi per scoprire funzionalità esclusive ed entrare a far parte della nostra fantastica community!

Registrati
Post correlati Risposte Visualizzazioni Attività
ODOO13 JS Framework how to load vis.js graph Risolto
javascript Odoo13.0
Avatar
1
mag 20
5190
How to refresh a kanban view automatically - Odoo13 ?
javascript Odoo13.0
Avatar
Avatar
Avatar
2
feb 20
6577
How to insert new event in Odoo calendar using another application in javascript
javascript Odoo13.0
Avatar
0
dic 19
4966
Javascript get model ID from where this JS Function is being called.
javascript Odoo13.0 v14
Avatar
Avatar
1
giu 24
4288
How to create systray icon?
javascript systray v15
Avatar
Avatar
1
giu 22
3636
Community
  • Tutorial
  • Documentazione
  • Forum
Open source
  • Scarica
  • Github
  • Runbot
  • Traduzioni
Servizi
  • Hosting Odoo.sh
  • Supporto
  • Aggiornamenti
  • Sviluppi personalizzati
  • Formazione
  • Trova un contabile
  • Trova un partner
  • Diventa nostro partner
Chi siamo
  • La nostra azienda
  • Branding
  • Contattaci
  • Lavora con noi
  • Eventi
  • Podcast
  • Blog
  • Clienti
  • Note legali • Privacy
  • Sicurezza
الْعَرَبيّة 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 è un gestionale di applicazioni aziendali open source pensato per coprire tutte le esigenze della tua azienda: CRM, Vendite, E-commerce, Magazzino, Produzione, Fatturazione elettronica, Project Management e molto altro.

Il punto di forza di Odoo è quello di offrire un ecosistema unico di app facili da usare, intuitive e completamente integrate tra loro.

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