如何在odoo中更改many2one字段的默认形式

时间:2022-07-14 20:23:50

Hi I have a mode Unit which inherits product.product. I have defined the custom views for Unit and they work fine from the menu.

嗨,我有一个继承product.product的模式单元。我已经为Unit定义了自定义视图,它们在菜单中工作正常。

Property which inherits account.asset.assets has multiple units. How do I call my custom unit views from the Property view? When I click on Add an item I get the standard product form.

继承account.asset.assets的属性有多个单元。如何从Property视图调用我的自定义单元视图?当我点击添加项目时,我会得到标准产品表格。

<record id="unit_form" model="ir.ui.view">
        <field name="name">All Units</field>
        <field name="model">product.product</field>
        <field name="sequence">0</field>
        <field name="arch" type="xml">
        <form string="Unit">

                    <group>
                        <field name="property_id" widget="many2one" attrs="{'required': [('is_unit', '=', True)]}" />
                        <field name="is_unit"  invisible="1" />
                        <field name="features_amenities_ids" placeholder="Features and Amenities" widget="many2many_tags" />
                        <field name="appliences_ids" placeholder="Apliences" widget="many2many_tags" />
                        <field name="lst_price" string="Rent" />
                    </group>

            </form>
        </field>
</record>
<record id="unit_tree" model="ir.ui.view">
        <field name="name">All Units</field>
        <field name="model">product.product</field>
        <field name="arch" type="xml">
            <tree string="Units" default_order='property_id,name'>

                <field name="property_id" />
                <field name="name" string="Unit#" />

            </tree>
        </field>
</record>

<record id="action_unit" model="ir.actions.act_window">
        <field name="name">Units</field>
        <field name="res_model">product.product</field>
        <field name="view_mode">search, kanban,tree,form</field>
        <field name="domain">[('is_unit', '=', True)]</field>
        <field name="context">{'default_is_unit':1 }</field>
        <field name="search_view_id" ref="unit_search"/>
        <field name="help" type="html">
            <p class="oe_view_nocontent_create">
            Click to create a Unit.
          </p>
            <p>
            Here you will find the all units.
          </p>
        </field>
</record> 
<record id="action_unit_form" model="ir.actions.act_window.view">
        <field name="act_window_id" ref="action_unit" />
        <field name="view_id" ref="unit_form" />
        <field name="view_mode">form</field>
        <field name="sequence">10</field>
</record> 

<record id="action_unit_tree" model="ir.actions.act_window.view">
        <field name="act_window_id" ref="action_unit" />
        <field name="view_id" ref="unit_tree" />
        <field name="view_mode">tree</field>
        <field name="sequence">9</field>
</record> 

<record id="action_unit_kanban" model="ir.actions.act_window.view">
        <field name="act_window_id" ref="action_unit" />
        <field name="view_id" ref="product.product_kanban_view" />
        <field name="view_mode">kanban</field>
        <field name="sequence">8</field>
</record>



<menuitem action="action_unit" sequence="2" 
        id="menu_units_list" name="Units" parent="menu_property_sub"/>  

This is from Property

这是来自财产

<notebook colspan="4">
    <page string="Units">
    <field name="unit_ids" nolabel="1" widget="one2many" >
        <tree string="Units">
            <field name="name" string="Unit#"/>
       </tree>
    </field>
    </page>
</notebook>

1 个解决方案

#1


3  

If you want to specify a view for many2one or one2many field:

如果要为many2one或one2many字段指定视图:

<field name="m2o_id" context="{'form_view_ref': 'module_name.form_id'}"/>

hope this helps. there are other key word like tree_view_ref for tree views

希望这可以帮助。树视图还有其他关键词,如tree_view_ref

#1


3  

If you want to specify a view for many2one or one2many field:

如果要为many2one或one2many字段指定视图:

<field name="m2o_id" context="{'form_view_ref': 'module_name.form_id'}"/>

hope this helps. there are other key word like tree_view_ref for tree views

希望这可以帮助。树视图还有其他关键词,如tree_view_ref