Search code examples
odooodoo-8odoo-9odoo-view

Inherit TransientModel and have two views ( website.config.settings )


I am trying to inherit the Website settings menu and have two views. website.config.settings is a models.TransientModel

When I am inheriting that and viewing with a new menuitem it overwrites the previous view. Like - There are two views now, the new record I defined named Website Event Settings . When I click on that it loads the new modified view but when I click on existing Settings menu, it shows nothing.

In summary, the existing website settings menu not working and new menu does. I need both of them.

The py code and record view I used are following -

class cofair_website_design_config(models.TransientModel):
    _name = 'website.config.settings'
    _inherit = 'website.config.settings'

    event_title = fields.Char(related='website_id.event_title', string='Event Title')

XML:

<record id="view_website_event_config_settings" model="ir.ui.view">
        <field name="name">Website Event Settings</field>
        <field name="model">website.config.settings</field>
        <field name="arch" type="xml">
            <form class="oe_form_configuration">
                <header>
                    <button string="Apply" type="object" name="execute" class="oe_highlight"/>
                    <button string="Cancel" type="object" name="cancel" class="oe_link"/>
                </header>
                <div>
                    <group string="Event Page Section">
                        <group>
                            <field name="event_title_color"/>
                        </group>
                    </group>
                </div>
            </form>
        </field>
</record>

<record id="action_website_event_configuration" model="ir.actions.act_window">
    <field name="name">Website Event Settings</field>
    <field name="res_model">website.config.settings</field>
    <field name="view_mode">form</field>
    <field name="target">inline</field>
    <field name="view_id" ref="view_website_event_config_settings"/>
</record>

<menuitem id="menu_website_event_settings" parent="website.menu_website_configuration" name="Website Event Settings" action="action_website_event_configuration"/>

Solution

  • Instead of renaming the modules (which causes relational error), I found a workaround. I have inherited the main settings and put a view id there and called it with menuitem -

    <!-- Bring settings menu out -->
    <record id="website.action_website_configuration" model="ir.actions.act_window">
        <field name="name">Website Settings</field>
        <field name="res_model">website.config.settings</field>
        <field name="view_mode">form</field>
        <field name="target">inline</field>
        <field name="view_id" ref="website.view_website_config_settings"/>
    </record>
    
    <menuitem id="website.menu_website_website_settings" parent="website.menu_website_configuration" name="Website Admin" action="website.action_website_configuration"/>
    

    Then I called my record action and it loaded the view and action. Another catch point is I had to show website_id to show the values of specific websites or the transient model will always be empty.