python - 将继承字段添加到 TreeView product_uom_categ - Odoo v9

标签 python odoo 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>

它工作正常,虽然我也想在该定义的 TreeView 上看到它,但我找不到方法,例如,在原始 View 模型中,实际上并没有 TreeView 已定义,只是这样的操作:

    <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,但是在 TreeView 上,什么都没有,但是还有,在这方面没有什么可以继承的,我应该继承这个 Action 吗?

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

最佳答案

你是对的。 product.uom.categ 模型没有 TreeView 。 Odoo 使用 name 列生成默认 TreeView 。

只需将 TreeView 定义添加到您的 [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>

希望它能解决您的问题。

关于python - 将继承字段添加到 TreeView product_uom_categ - Odoo v9,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40791971/

相关文章:

javascript - 如何从 odoo 9 javascript 调用 python 方法

python - 我想返回 "duo"列表中顶级元素的数量

python - 更新: Odoo project task tags domain

python - 如何在当前窗口中打开 one2many 记录,而不是 odoo V13 中的弹出窗口

python - Mac 上安装 Odoo 无法执行命令 LESSC

python - Odoo 模块的升级如何进行?

python - 为什么列为键字典,仍然会显示为元组作为键字典

python - 如何将变量文件路径传递给位于 PYTHONPATH 上的 Robot Framework?

python - Pandas:更改数据帧日期索引格式

odoo-9 - 基于访问的表单 View