Home > Blockchain >  How to set a domain for a view [Odoo 15]
How to set a domain for a view [Odoo 15]

Time:10-28

I want to have a view that only shows reservations with state= 'paid_reserve'. I have this code actually but it doesn't work.

 <record id="view_hotel_reservation_tree_paid" model="ir.ui.view">
        <field name="name">hotel.reservation.tree.paid</field>
        <field name="model">hotel.reservation</field>
        <field name="domain">[('state','=','paid_reserve')]</field>
        <field name="arch" type="xml" >
            <tree>
                <field name="room_name" readonly="1"/>
                <field name="checkin" readonly="1"/>
                <field name="checkout" readonly="1"/>
                <field name="state" readonly="1"  />
            </tree>
        </field>
 </record>

CodePudding user response:

The domain field is not available for views, you should see the following error in the log:

ValueError: Invalid field 'domain' on model 'ir.ui.view'

The domain can be used on the  window action to be implicitly added to all view search queries.

You can find the following example in the account module:

<record id="action_account_moves_journal_sales" model="ir.actions.act_window">
    <field name="context">{'journal_type':'sales', 'search_default_group_by_move': 1, 'search_default_posted':1, 'search_default_sales':1, 'name_groupby':1, 'expand': 1}</field>
    <field name="name">Sales</field>
    <field name="res_model">account.move.line</field>
    <field name="domain">[('display_type', 'not in', ('line_section', 'line_note'))]</field>
    <field name="view_id" ref="view_move_line_tree_grouped_sales_purchases"/>
    <field name="view_mode">tree,pivot,graph,kanban</field>
</record>
  • Related