首页 文章

Odoo 10:在产品表单中添加额外的字段

提问于
浏览
1

我想在'standard_price'之后的产品表单中添加几个额外的字段 .

我创建了一个继承自“product.product_template_form_view”的视图,并在那里添加了我的字段:

<field name="standard_price" position="after">
        <field name="my_field" />
</field>

然后我重新启动odoo更新模块,但是当我调用产品表单时,我没有看到我的新字段 .

这些字段显示在数据库模型上(也创建了继承的模型),但不在用户界面上 .

我在这里缺少什么?

3 回答

  • 1

    检查以下事项:

    • 从正确的基本表单继承 product.template.common.form

    • 确保您正在查看product.template(产品)的正确表单,而不是product.product(产品变体) .

    • 在编辑模式下,您是否看到没有 Headers 的输入字段?如果是这种情况,您可以在html级别中破坏结构 . 下一个子弹将解决这个问题

    • Standard_price字段具有唯一的html结构,因为它可以将度量单位(uom)连接到它 . 尝试连接到简单字段或使用容器div standard_price_uom进行连接,请参阅下面的模板代码 .

    使用standard_price_uom div之后的新字段的工作视图的模板代码:

    <div name='standard_price_uom' position="after">
      <field name="my_field" />
    </div>
    

    如果这些没有帮助,请提供整个视图定义 .

  • 0

    确保使用正确的型号 . 使用 product.template 而不是 product.product .

    <record id="product_template_form" model ="ir.ui.view">
        <field name="name">product.template.form</field>
        <field name="model">product.template</field>
        <field name="inherit_id" ref="product.product_template_form_view" />
        <field name="arch" type="xml">
            <field name="standard_price" position="after">
                <field name="my_field"/>
            </field>
        </field>
    </record>
    
    ...
    
    class ProductTemplate(models.Model):
        _inherit = "product.template"
    
        my_field = fields.Char()
    
  • 0

    确保已将XML文件添加到模块的 __manifest__.py 文件中 . Odoo只从你告诉它的文件中提取XML .

    您可以在任何核心模块上看到此示例 . 有关示例,请参见sale/manifest.py .

    在您的模块上,它将是这样的:

    {
        ...
        ‘data’: [
            ‘views/form/form_product.xml’,
        ]
        ...
    }
    

相关问题