Odoo 18: Dynamically Rename Field Labels with _get_view
By Braincuber Team
Published on February 11, 2026
Static XML labels in Odoo are great for consistency, but sometimes business logic demands flexibility. What if your "Tax ID" field needs to read "EIN" for US users, "GSTIN" for Indian users, and "VAT" for everyone else?
In standard Odoo development, changing a label usually means duplicating views or relying on translations. However, Odoo 18 provides a cleaner hook: the _get_view method (formerly fields_view_get). In this guide, we'll implement a dynamic label system for the Contact (res.partner) model that adapts based on the logged-in user's country.
Why use _get_view?
- Single Source of Truth: No need to maintain 5 different inherited views for 5 different scenarios.
- Context-Aware: Modify the UI based on the current user, company, or session context.
- Performance: Changes are applied at the architecture level before the view renders.
Step 1: Inherit the Model
We start by inheriting the res.partner model to override the view fetching logic.
from odoo import api, models
class ResPartner(models.Model):
_inherit = 'res.partner'
@api.model
def _get_view(self, view_id=None, view_type='form', **options):
# 1. Fetch the standard architecture from the parent method
arch, view = super()._get_view(view_id, view_type, **options)
return arch, view
Step 2: Inject Dynamic Logic
Now we interpret the XML architecture (arch) and modify it using XPath, similar to how you would in an XML file, but with Python's full power.
In this example, we check the current user's country code to decide what to call the Tax ID field.
@api.model
def _get_view(self, view_id=None, view_type='form', **options):
arch, view = super()._get_view(view_id, view_type, **options)
# Apply logic only to Form views
if view_type == 'form':
user = self.env.user
label = 'Tax ID' # Default
# Logic based on User's Country
if user.country_id.code == 'US':
label = 'EIN / SSN'
elif user.country_id.code == 'IN':
label = 'GSTIN'
elif user.country_id.code == 'AE':
label = 'TRN'
# Modify the XML only if we have a custom label
if label != 'Tax ID':
# Locate the node using XPath
for node in arch.xpath("//field[@name='vat']"):
node.set('string', label)
return arch, view
Important Considerations
- Caching: Odoo caches the result of
_get_view. This update happens when the view is loaded (e.g., refreshing the browser), not when changing records. This makes it perfect for User or Company-based logic, but not for record-dependent logic (e.g., "Change label if the partner is a VIP"). - XPath Precision: Ensure your XPath query is specific enough.
//field[@name='vat']will find all instances of the VAT field in the form. - Performance: Avoid heavy database queries inside this method, as it runs every time a view is loaded.
Conclusion
Dynamic view manipulation is a powerful tool in Odoo 18, allowing you to create interfaces that feel personalized to specific user roles or regions without cluttering your codebase with dozens of XML files.
Complex Odoo Customizations?
Need to dynamically alter views based on complex business rules? Our Odoo experts can build the architecture you need.
