Skip to Content
Menu
This question has been flagged
2 Replies
1155 Views

Hey there,

I'm currently writing a submodule for holidays and encountered an issue with view inheritance.

Let me give you a quick example overview.

In our company we've a customized form view for the hr_holidays form view with some xpath adjustments. (in an own module with some adjustments for the holidays)
This customization works fine and is displayed etc. correctly.

simplified example of normal adjustment for holiday view in let's say a "adjustments_module" module:

<record id="edit_holiday_new" model="ir.ui.view">
    <field name="name">Leave Request</field>
    <field name="model">hr.holidays</field>
    <field name="inherit_id" ref="hr_holidays.edit_holiday_new"/>
    <field name="arch" type="xml">
        <!-- Remove one field -->
        <xpath expr="//form//field[@name='date_to']" position="replace"/>
    </field>
</record>

Now we've a child class of hr.holidays with some additional fields in a new module (let's name it "more_adjustments_module") where we still want to maintain our customizations. So we inherit our inherited view, but also for a different model (which is a child from hr.holidays)
And this is the one which is causing issues for me.

simplified example:

<record id="child_model_form_view" model="ir.ui.view">
    <field name="name">Fancy name</field>
    <field name="model">child.model</field>
    <field name="inherit_id" ref="adjustments_module.edit_holiday_new"/>
    <field name="arch" type="xml">
        <!-- Add one field -->
        <xpath expr="//form//field[@name='name']" position="after">
            <field name="my_new_field"/>
        </xpath>
    </field>
</record>

This is an example for the action record to use the child_model_form_view:

<record id="action_child_model_overview" model="ir.actions.act_window">
    <field name="name">Child Model Overview</field>
    <field name="type">ir.actions.act_window</field>
    <field name="res_model">child.model</field>
    <field name="view_type">form</field>
    <field name="view_mode">tree,form</field>
    <field name="view_ids" eval="[(5, 0, 0),
        (0, 0, {'view_mode': 'tree', 'view_id': ref('child_model_tree_view')}),
        (0, 0, {'view_mode': 'form', 'view_id': ref('child_model_form_view')})
    ]"/>
</record>

The issue I'm facing is that (corresponding to the simplified example) the form view will display the original form view from hr_holidays (external id:  "hr_holidays.edit_holiday_new") without the adjustments from the 1st and 2nd inheritance. So it doesn't open the new form view which has (in accordance to technical -> views, as it's listed there) the external id "more_adjustments_module.child_model_form_view".


The "more_adjustments_module" is depending on the "adjustments_module" via manifest.

Small structure/dependency overview:

hr_holidays

|- adjustments_module

    |- more_adjustments_module


So any hint/help why the xpath adjustments aren't inherited would be very appreciated. Many thanks in advance.

Avatar
Discard
Author Best Answer

Seems I've just fixed it and it now applies the xpath changes from both inheritances.

Adding mode primary to the 2nd inheritance view (which is used for the new model) does the trick.

<record id="child_model_form_view" model="ir.ui.view">
    <field name="name">Fancy name</field>
    <field name="model">child.model</field>
    <field name="inherit_id" ref="adjustments_module.edit_holiday_new"/>
    <field name="mode">primary</field>
    <field name="arch" type="xml">
        <!-- Add one field -->
        <xpath expr="//form//field[@name='name']" position="after">
            <field name="my_new_field"/>
        </xpath>
    </field>
</record>

If someone can verify, that this is indeed the thing which was just missing, I would really appreciate it.

Avatar
Discard