Hello,
I'm overriding the _get_view method to dynamically modify form views based on a custom context key mi_gestion. Here's a simplified version of my method:
@api.model
def _get_view(self, view_id=None, view_type='form', **options):
arch, view = super()._get_view(view_id=view_id, view_type=view_type, **options)
if view_type == 'form' and self._context.get('mi_gestion'):
m2o_fields = [name for name, field in self._fields.items() if field.type == 'many2one']
if m2o_fields:
xpath_query = " | ".join(f".//field[@name='{name}']" for name in m2o_fields)
nodes = arch.xpath(xpath_query)
self._modify_m2o_field_option(nodes)
return arch, view
The issue is that self._context.get('mi_gestion') always returns False, even though I'm passing mi_gestion=True via the frontend context.
- Why is self._context not reflecting the custom context in _get_view?
-
Is there a better or more reliable approach to pass and access custom context values inside _get_view?
Any help or insights would be appreciated!
Thanks in advance.