I have create 4 form view from odoo user interface. Now I want to render view conditionally based on my model data like state.
How can I achieve this ? or Where I can override a method to render view conditionally?
Update
According to the comment overrides the get_view
method works but to refresh the form page. When I refresh the form page my custom view applies to the form page. How Can I Fix this cache issue issue?
def get_view(
self, view_id=None, view_type='form', **options
):
# Call the super method to get the original view definition
result = super().get_view(
view_id=view_id, view_type=view_type, **options
)
if view_type == 'form' and 'params' in self._context and 'id' in \
self._context['params']:
# get record ID from _context when access Form page
record = self.browse(self._context['params']['id'])
view = self.env['ir.ui.view'].search(
[('name', '=', f'My Custom View')], limit=1
)
result.update(
{
'id': view.id,
'arch': view.arch_db,
'model': 'custom_module.model_name',
'models': {
'custom_module.model_name': model_fields,
f'related_model': related_model_fields
},
}
)
return result