Skip to Content
Menu
This question has been flagged
1 Reply
4888 Views
<field name="arch" type="xml">
<search string="Demo">
<filter string="Test" name="name" domain="[['some_field', '=', 'some value']]" />
</search>
</field>
here, is it possible to generate the <filter> multiple times dynamically
Avatar
Discard
Best Answer

Hi,

If you are looking to extend the search view from the python code, yes its possible to do it. You can refer this module, which adds a new inherited view in odoo, to add fields to an existing form. By referring this code, you can adjust and make it workable for search view.


Module: https://apps.odoo.com/apps/modules/13.0/dynamic_partner_fields/


Relevant part of code from above module:

inherit_id = self.env.ref('base.view_partner_form')
arch_base = _('<?xml version="1.0"?>'
'<data>'
'<field name="%s" position="%s">'
'<field name="%s"/>'
'</field>'
'</data>') % (self.position_field.name, self.position, self.name)
if self.widget:
arch_base = _('<?xml version="1.0"?>'
'<data>'
'<field name="%s" position="%s">'
'<field name="%s" widget="%s"/>'
'</field>'
'</data>') % (self.position_field.name, self.position, self.name, self.widget.name)

self.env['ir.ui.view'].sudo().create({'name': 'partner.dynamic.fields.%s' % self.name,
'type': 'form',
'model': 'res.partner',
'mode': 'extension',
'inherit_id': inherit_id.id,
'arch_base': arch_base,
'active': True})
return {
'type': 'ir.actions.client',
'tag': 'reload',
}


For inheriting and changing existing search views in Odoo: How To Inherit And Make Changes Inside Existing Search Views In Odoo


Thanks

Avatar
Discard