简体   繁体   中英

Odoo - Change domain on inherited view

I am currently working on building a custom module, and I extended the unit of measure class (product.uom). I want some uom entries to be removed from the list/tree views, based on a specific value for one of my new variables.

I am not entirely sure how to modify this view. I seem to be reading that I need to specify a domain, like domain = [("myvariable","=",True)], but I'm not entirely sure how to apply this. I tried inheriting the tree view, and adding a domain, but this doesn't work.

Any help would be greatly appreciated.

Solution:

<record model="ir.actions.act_window" id="uom_list_action">
    <field name="name">Units Of Measurement</field>
    <field name="res_model">product.uom</field>
    <field name="domain">[("myvariable","!=",True)]</field>
    <field name="view_mode">tree,form</field>
</record>

<record model="ir.ui.menu" id="product.menu_product_uom_form_action">
    <field name="action" ref="uom_list_action"/>
</record>

<record model="ir.ui.menu" id="stock.menu_stock_uom_form_action">
    <field name="action" ref="uom_list_action"/>
</record>

In order to do what Nross2781 is looking for you have to override the ir.actions.act_window for the record.

<record model="ir.actions.act_window" id="uom_list_action">
    <field name="name">Units Of Measurement</field>
    <field name="res_model">product.uom</field>
    <field name="domain">[("myvariable","!=",True)]</field>
    <field name="view_mode">tree,form</field>
</record>

However you may want to consider adding filters to a search view which would be more flexible. You would also be able to see the records which do not show up by default.

<record model="ir.ui.view" id="uom_search_view">
    <field name="name">uom.search</field>
    <field name="model">product.uom</field>
    <field name="arch" type="xml">
        <search string="Units Of Measurement">
            <filter name="my_var_is_true" string="My Variable" domain="[('myvariable','=',True)]"/>
            <filter name="my_var_is_false" string="Not My Variable" domain="[('myvariable','!=',True)]"/>
        </search>
    </field>
</record>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM