Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
2 Risposte
344 Visualizzazioni

I have this code from a custom module that I want to add as an inherited view. However, the view I want to assign it to is website.homepage. When I do it this way, a different tree is created with the inherited view instead of assigning it to the already existing one. Any idea what might be happening?

<odoo>

  <data>

    <record id="alx_al_website" model="ir.ui.view">

      <field name="name">(CUSTOM) - landing page</field>

      <field name="type">qweb</field>

      <field name="inherit_id" ref="website.homepage"/>

      <field name="priority" eval="1000"/>

      <field name="website_id" ref="website.default_website"/>

      <field name="arch" type="xml">

        <xpath expr="//div[@id='wrap']" position="replace">

          <div><p>hello world</p></div>

        </xpath>

      </field>

    </record>

  </data>

</odoo>

Avatar
Abbandona
Risposta migliore

Hi,


Try the following,

<odoo>

  <data>

    <record id="alx_al_website" model="ir.ui.view">

      <field name="name">(CUSTOM) - landing page</field>

      <field name="type">qweb</field>

      <field name="inherit_id" ref="website.homepage"/>

      <field name="priority" eval="1000"/>

      <field name="arch" type="xml">

        <xpath expr="//div[@id='wrap']" position="replace">

          <div><p>hello world</p></div>

        </xpath>

      </field>

    </record>

  </data>

</odoo>


When you create an inherited view in Odoo:

  • If you don’t set website_id, the view applies globally to all websites. Updating the module will always refresh it everywhere, including new websites.
  • If you set website_id, the view is tied only to that website. Updates to the module will refresh it only for that site, and new websites won’t automatically get the changes.

Best practice:

Use global inheritance if you want one universal homepage design, and add website_id only if you want different designs per website.


Hope it helps

Avatar
Abbandona
Risposta migliore

Hi Diego,

What’s happening is due to how website-specific views work in Odoo. When you include a <field name="website_id" .../> in your inherited view, Odoo doesn’t just extend the existing website.homepage — instead, it creates a website-restricted variant of the homepage. That’s why you see a new view “tree” instead of your code extending the original one.

If you want your changes to apply globally (for all websites), simply remove the website_id field:

<record id="alx_al_website" model="ir.ui.view"> <field name="name">(CUSTOM) - landing page</field> <field name="type">qweb</field> <field name="inherit_id" ref="website.homepage"/> <field name="arch" type="xml"> <xpath expr="//div[@id='wrap']" position="replace"> <div><p>hello world</p></div> </xpath> </field> </record>

If you really need it to apply only to a specific website, then keeping website_id is correct, but in that case Odoo will always generate a new branch of the view for that website — that’s the expected behavior.

Hope this helps!

Avatar
Abbandona
Autore

Thanks for the answer, however I have a question if a website already exists, this template only applies to new sites, but if I update the module with a new view The inherited view logically will not be updated and will only apply to sites closed later to the installation of the module, not to those previously created, any strategy that you can propose to me?

Post correlati Risposte Visualizzazioni Attività
3
ott 25
1190
1
giu 25
2296
0
feb 25
1623
3
ott 24
2119
0
giu 24
1653