How to fix search view working where given field able to searchable?

762 Views Asked by At

The below code should apply search by name, contact, and email. but it's not working as expected. I would like to know. in the image attached, the only search is applicable for the name. but not email and contact.

<record id="merchant_search" model="ir.ui.view">
    <field name="name">ecommece_advance.merchant.search</field>
    <field name="model">ecommece_advance.merchant</field>
    <field name="type">search</field>
    <field name="arch" type="xml">
        <search string="Merchants">
            <field name="name" string="Merchant Name"/>
            <field name="contact"/>
            <field name="email" string="Email" filter_domain="[('email', 'ilike', self)]"/>
            <separator/>
            <group expand="0" string="Group By">
                <filter string="Name" name="Name" domain="[]" context="{'group_by': 'name'}"/>
            </group>
        </search>
    </field>
</record>

//model fields

name        = fields.Char( required=True)
email       = fields.Char(required=True)
address     = fields.Char()
website     = fields.Char()
latitude    = fields.Float(digits=(3,6))
longitude   = fields.Float(digits=(3,6))
contact     = fields.Char(required=True)
alternative_contact = fields.Char()

search view

search failed with ss but search result exists

1

There are 1 best solutions below

1
On

Let's add these filters to check that your xml file is loaded :

<filter string="Name" name="Name" domain="[]" context="{'group_by': 'name'}"/>
<filter string="Email" name="Email" domain="[]" context="{'group_by': 'email'}"/>
<filter string="Contact" name="Contact" domain="[]" context="{'group_by': 'contact'}"/>

If these filters are not added, you should check that your xml file is called in the data section in your manifest.py file of your module : 'data': [ 'view/merchants.xml',

Otherwise, if this record was already existing, consider inherit it from its original module and use xpath to insert your new fields in :

  <record id="merchant_search" model="ir.ui.view">
    <field name="inherit_id" ref="original_module.merchant_search" />
    <field name="arch" type="xml">
        <xpath expr="//search" position="inside">           
          <field name="email">email</field>
          <field name="contact">contact</field>
        </xpath>
   </record>