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

时间:2016-11-24 17:26:11

标签: python openerp odoo-9

我在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,但在树视图中,没有任何内容,但也没有任何内容可以继承我应该继承这个行动吗?

我坚持这个,有什么想法吗?

1 个答案:

答案 0 :(得分:1)

你是对的。 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>

希望它能解决你的问题。

相关问题