如何继承看板视图并修改default_group_by属性?
Replacing
default_group_by in an Inherited Kanban View (Odoo) Absolutely, you can replace the default_group_by attribute when inheriting a kanban view in Odoo—this is fully supported! Here's a straightforward, step-by-step guide to make it work:
Step 1: Build the Inherited View XML
Use Odoo's standard view inheritance structure to target the kanban root node and modify its attributes. Here's a complete, ready-to-use example:
<record id="inherit_target_kanban_view" model="ir.ui.view"> <field name="name">target.model.kanban.inherit</field> <field name="model">your.target.model</field> <!-- Replace with your actual model name --> <field name="inherit_id" ref="original_module.original_kanban_view_id"/> <!-- Replace with the original view's external ID --> <field name="arch" type="xml"> <!-- Target the root kanban node where default_group_by is defined --> <xpath expr="//kanban" position="attributes"> <!-- Overwrite the existing default_group_by value --> <attribute name="default_group_by">state</attribute> </xpath> </field> </record>
Key Details to Get Right:
inherit_id: Double-check that this references the correct external ID of the kanban view you want to extend. You can find this ID in the original module's XML files, or by navigating to Settings > Technical > Views in Odoo and searching for the view.- XPath Target: The
//kanbanexpression directly hits the root node of the kanban view, which is where thedefault_group_byattribute lives. - Attribute Replacement: Using
position="attributes"signals to Odoo that you want to modify the node's attributes, and the<attribute>tag will directly overwrite the existingdefault_group_byvalue with your new one (state).
Quick Extra Tips:
- If the original view's
default_group_bywas set dynamically via Python code (instead of XML), you might need to override the relevant method (likeget_viewor a model-specific group-by handler) to ensure your change takes priority. But for XML-defined attributes, the method above works flawlessly. - Don't forget to upgrade your module after adding this code—Odoo won't apply the changes until you do so.
内容的提问来源于stack exchange,提问作者Tessnim
相关产品推荐
相关产品推荐

