Hello Eduardo,
To configure a view to open by default based on an attribute in Odoo 18.0 Community, you can follow these steps:
- Prioritize your custom views: Ensure that your custom views have a lower priority than the default res.partner view. Odoo selects the view with the lowest priority as the default. You can set the priority in the view definition XML file.
- Override the default view: You can override the default view by defining a window action that specifically calls your custom view based on the contact_type parameter. This involves creating a menu item or action that triggers your desired view when accessed from other places in Odoo.
- Conditional view rendering: Use the invisible attribute in your view definitions to conditionally display fields or sections based on the contact_type parameter. This allows you to tailor the view based on the attribute value.
- Set default order: If you want to change the way records are sorted by default in the list view, you can select a field under "Sort By" in the view settings. To set a default grouping for records, select a field under "Default Group By".
Here's an example of how you might define your view in XML, adjusting the priority:
<record id="your_custom_view_id" model="ir.ui.view">
<field name="name">your.custom.view.name</field>
<field name="model">res.partner</field>
<field name="priority">16</field> <!-- Lower priority number -->
<field name="arch" type="xml">
<!-- Your view definition here -->
</field>
</record>
By setting a lower priority, you encourage Odoo to select this view as the default when it matches the criteria (e.g., when accessed via your internal links).
🚀 Did This Solve Your
Problem?
If this answer helped you save time, money, or
frustration, consider:
✅ Upvoting (👍)
to help others find it faster
✅ Marking
as "Best Answer" if it resolved your issue
Your feedback keeps the Odoo community strong! 💪
(Need further customization? Drop a comment—I’m happy to
refine the solution!)
Your solution makes a lot of sense. I had three views with primary mode. From now on, I'll implement this logic when inheriting views.
Thank you very much. I'd upvote as many as I could, but I don't have enough karma.