Skip to Content
Menu
This question has been flagged
1 Reply
1279 Views

Hi,

our aim is to extend a XML search filter view and add an additional filter.


This is the very first step we want to achieve. Then we will enhance our search filter domain by using a computed, searchable and not stored field. Finally, we will make the filter to be a default filter for users of a specific group. This bigger picture context is the reason why we want to achieve our aim this particular way.


Our Odoo module technical name is called al_hr_holidays, and inherits from the Time Off Odoo app, which technical name is hr_holidays.


From the code below, our module implements a view that inherits from the hr_holidays.view_hr_holidays_filter view [1] and add a very simple filter domain [2] after the existing department filter.


    <?xml version="1.0" encoding="utf-8"?>
    <odoo>
       <record id="al_hr_holidays.al_view_hr_holidays_filter" model="ir.ui.view">
          <field name="name">al.hr.holidays.filter</field>
          <field name="model">hr.leave</field>
          <field name="mode">primary</field>
          <field name="priority">1</field>
          <field name="inherit_id" ref="hr_holidays.view_hr_holidays_filter"/>
          <field name="arch" type="xml">
               <xpath expr="//filter[@name='department']" position="after">
                <filter name="additional_filter"
                        string="Additional Filter"
                        domain="[('state', '=', 'confirm')]"/>
             </xpath>
          </field>
       </record>
    </odoo>


However, the additional_filter filter is not rendered in the search filter, even after making sure that:


  • The al_hr_holidays module has been updated
  • The External ID of the view we are inheriting is valid
  • The XPath expression is valid
  • There is no error in the Odoo log
  • The browser cache has been cleared


Any hints on how to fix this issue? also present in Odoo 18 enterprise


[1] hr_holidays.view_hr_holidays_filter view, line 38 

addons/hr_holidays/views/hr_leave_views.xml


[2] The filter selects the leaves that are in the confirm state

Avatar
Discard

You can modify/extend the Parent View with mode=primary. This creates a brand new View. In order to use this View you need to reference it somewhere in Odoo. Without referencing it, it will never be used.

Author

(edited comment)
Thanks Ray for your 2 amazing clarifications

Two way to fix the issue:

1. (recommended) Completely remove the 'mode' field, as it is not needed in our context.
2. Change the value of the 'mode' field from 'primary' to 'extension'

The documentation on the mode field is available here https://www.odoo.com/documentation/18.0/developer/reference/user_interface/view_records.html

Care should be taken when we copy an example from outside. Before reusing it, we should carefully understand the meaning of each field.

So we would use 'primary' mode for a new view that would however be based on another view. In this case, reference of the new view should be used to render the new content. That was not the case here, this is why the 'additional_filter' was not rendered in the parent view.

Best Answer

MODE. 

PRIMARY means you are making a NEW View and need to define where this new View is used or it will never be used. 

It should be INHERIT if you want your change to be applied to an EXISTING View. 

Avatar
Discard
Related Posts Replies Views Activity
3
Jul 25
682
1
Oct 22
4104
7
Mar 17
13647
2
May 25
610
0
Nov 24
557