将继承字段添加到树视图 product_uom_categ - Odoo v9

Add inherited field into tree view product_uom_categ - Odoo v9

我在 product_uom_categ 模型中添加了一个新字段,继承方式如下:

class product_uom_categ(models.Model):
    _inherit = 'product.uom.categ'

    code_product = fields.Char(string="Código Unidad")

那么在我看来:

<openerp>
<data>
    <record id="product_uom_categ_form_view" model="ir.ui.view">
        <field name="name">product.uom.categ.form</field>
        <field name="model">product.uom.categ</field>
        <field name="inherit_id" ref="product.product_uom_categ_form_view" />
        <field name="arch" type="xml">
        <field name='name' position="after">
          <field name="code_product"/>
        </field>
      </field>
    </record>
 </data>
</openerp>

它工作正常,虽然我也想在该定义的树视图上看到它,但我找不到办法做到这一点,例如,在原始视图模型中,实际上并没有定义了一个树视图,就像这样一个动作:

    <record id="product_uom_categ_form_view" model="ir.ui.view">
        <field name="name">product.uom.categ.form</field>
        <field name="model">product.uom.categ</field>
        <field name="arch" type="xml">
            <form string="Units of Measure categories">
                <group>
                    <field name="name"/>
                </group>
            </form>
        </field>
    </record>
    <record id="product_uom_categ_form_action" model="ir.actions.act_window">
        <field name="name">Unit of Measure Categories</field>
        <field name="type">ir.actions.act_window</field>
        <field name="res_model">product.uom.categ</field>
        <field name="view_type">form</field>
        <field name="view_mode">tree,form</field>
        <field name="help" type="html">
          <p class="oe_view_nocontent_create">
            Click to add a new unit of measure category.
          </p><p>
            Units of measure belonging to the same category can be
            converted between each others. For example, in the category
            <i>'Time'</i>, you will have the following units of measure:
            Hours, Days.
          </p>
        </field>
    </record>

所以,在 form 上它显示了两个字段,name 和我的新字段 code_product,但是在树视图上,什么都没有,而且,也没有什么可以继承在这方面,我应该继承行动吗?

我卡在这上面了,有什么想法吗?

你是对的。 product.uom.categ 模型没有树视图。 Odoo 生成带有 name 列的默认树视图。

只需将树视图定义添加到您的 [your_module]_views.xml 文件。

<record id="product_uom_categ_tree_view" model="ir.ui.view">
     <field name="name">product.uom.categ.tree</field>
     <field name="model">product.uom.categ</field>
     <field name="arch" type="xml">
         <tree string="Units of Measure categories">
             <field name="name"/>
             <field name="code_product"/>
         </tree>
     </field>
 </record>

希望它能解决您的问题。