Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
947 มุมมอง

Good morning.

I have created a module with three views that inherit from res.partner. These views are designed to be accessed through internal links within my module. However, when I try to access them from other places, like going back in the browser, they revert to the default res.partner view instead of my custom view.

What can I do to make sure the view opens based on my contact_type parameter in this scenario?

อวตาร
ละทิ้ง
ผู้เขียน

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.

คำตอบที่ดีที่สุด

Hello Eduardo,

To configure a view to open by default based on an attribute in Odoo 18.0 Community, you can follow these steps:

  1. 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.
  2. 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.
  3. 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.
  4. 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!)

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
1
พ.ค. 25
702
0
พ.ค. 25
435
0
ก.พ. 25
904
0
มี.ค. 15
4003
0
ส.ค. 25
25