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

Is it possible to activate second or third notebook page instead of the first one, based on some conditions?

Iscriviti

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

La domanda è stata contrassegnata
xmlpagesnotebookodooodoo-xml
3 Risposte
2575 Visualizzazioni
Avatar
Zahid Mehmood

Is it possible to activate the second or third notebook page instead of the first one, based on some conditions? For example, If boolean field A is checked then activate or focus on second page and if boolean field B is checked then activate of focus third page of the notebook.


 I want to activate second page by default in odoo notebooks pages.

0
Avatar
Abbandona
Avatar
Gracious Joseph
Risposta migliore

Yes, it is possible to dynamically activate a specific page in an Odoo notebook based on conditions, but it requires JavaScript customization since XML alone does not provide conditional control over active notebook pages.

Here’s how you can achieve this in Odoo 17 (and it should also work for earlier versions):

Solution: Use JavaScript to Control Notebook Page Activation

1. Add an ID to Your Notebook Pages in the XML View

Assign unique IDs to the notebook pages you want to control.

Example XML:

<notebook>
    <page string="First Page" id="page_1">
        <group>
            <field name="field_a" />
        </group>
    </page>
    <page string="Second Page" id="page_2">
        <group>
            <field name="field_b" />
        </group>
    </page>
    <page string="Third Page" id="page_3">
        <group>
            <field name="field_c" />
        </group>
    </page>
</notebook>

2. Add JavaScript to Dynamically Activate Pages

Write JavaScript to dynamically activate the notebook page based on conditions.

Create a JS file in your custom module:

odoo.define('custom_module.dynamic_notebook_page', function (require) {
    "use strict";

    const FormRenderer = require('web.FormRenderer');
    const fieldRegistry = require('web.field_registry');

    FormRenderer.include({
        _renderTabPage: function () {
            this._super.apply(this, arguments);

            // Check conditions and activate the appropriate page
            const fieldA = this.state.data.field_a; // Assuming `field_a` is your boolean field
            const fieldB = this.state.data.field_b; // Assuming `field_b` is another boolean field

            if (fieldA) {
                this._activateNotebookPage('page_2'); // Activate second page
            } else if (fieldB) {
                this._activateNotebookPage('page_3'); // Activate third page
            }
        },

        _activateNotebookPage: function (pageId) {
            const notebook = this.el.querySelector('.o_notebook'); // Target notebook
            const page = notebook.querySelector(`[id="${pageId}"]`); // Find the page
            if (page) {
                const tabs = notebook.querySelectorAll('.o_notebook_tab');
                tabs.forEach(tab => tab.classList.remove('active'));
                const tab = notebook.querySelector(`[href="#${pageId}"]`);
                tab.classList.add('active');

                // Hide all pages and show the active page
                const pages = notebook.querySelectorAll('.o_notebook_page');
                pages.forEach(page => page.classList.add('o_notebook_page_hidden'));
                page.classList.remove('o_notebook_page_hidden');
            }
        },
    });
});

3. Load the JS File in Your Module

Ensure the JavaScript file is included in your module.

Add the following to your module’s __manifest__.py:

'assets': {
    'web.assets_backend': [
        '/custom_module/static/src/js/dynamic_notebook_page.js',
    ],
},

4. Install and Test

  1. Install or upgrade your module.
  2. Open the form view with the notebook.
  3. Check if the correct page is activated based on the boolean fields.

Alternative Approach: Use autofocus Attribute

If JavaScript is not preferred, you can use the autofocus attribute to focus on a specific field on another page. However, this might not work reliably in Odoo 17 (as mentioned in your example).

Example:

<field name="field_b" autofocus="autofocus" />

Key Considerations

  • Performance: Ensure JavaScript modifications are efficient and don’t impact page load times.
  • Testing: Test thoroughly in different scenarios to ensure correct page activation.

This approach allows you to dynamically activate the desired notebook page based on conditions. Let me know if you need further clarification or help!

0
Avatar
Abbandona
Avatar
Zahid Mehmood
Autore Risposta migliore

Hi Ray, 
Thank you for your quick reply. 

I have just added autofocus on a field on 3rd page of the notebook but it still activated the first tab and no other autofocus attributes have been used throughout the view. See the attached screenshot. I am on odoov17 ent. 

0
Avatar
Abbandona
Avatar
Ray Carnes (ray)
Risposta migliore

It is not.

You can globally define a different default page by adding the autofocus attribute to a field on that page that requires user input:

<field name="field_on_other_page" autofocus="autofocus"/>
0
Avatar
Abbandona
Zahid Mehmood
Autore

Hi Ray,
Thank you for your quick reply.

I have just added autofocus on a field on 3rd page of the notebook but it still activated the first tab and no other autofocus attributes have been used throughout the view. See the attached screenshot. I am on odoov17 ent.

Ray Carnes (ray)

Interesting, it worked for me in Odoo 18.0 but not 17.0. Sorry, I don't have any more information for you!

Zahid Mehmood
Autore

Sure. Thanks for your help. I will try in v18

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à
Problemas al imprimir factura en el odoo
xml odoo
Avatar
0
gen 25
1913
How to post xml code
xml odoo
Avatar
1
mar 25
652
How can I include my generic qweb view on my Odoo 16 Form View using JS or Controller
xml odoo
Avatar
Avatar
1
set 23
3451
Favorite filter Odoo 10 Risolto
xml odoo
Avatar
Avatar
2
ago 22
8297
[Odoo 8]How to use ref on domain xml Risolto
xml odoo
Avatar
Avatar
Avatar
Avatar
Avatar
8
giu 20
22859
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