Odoo 10:向产品表单添加额外字段

Odoo 10:向产品表单添加额外字段,odoo,odoo-10,odoo-view,Odoo,Odoo 10,Odoo View,我想在“standard_price”后面的产品表单中添加几个额外的字段 我创建了一个从“product.product\u template\u form\u view”继承的视图,并在其中添加了我的字段: 然后,我重新启动odoo更新模块,但在调用产品表单时,我看不到新字段 这些字段显示在数据库模型上(也显示在继承的模型上),但不显示在用户界面上 我在这里遗漏了什么?检查以下内容: 继承自正确的基本表单product.template.common.form 确保查看的是product

我想在“standard_price”后面的产品表单中添加几个额外的字段

我创建了一个从“product.product\u template\u form\u view”继承的视图,并在其中添加了我的字段:


然后,我重新启动odoo更新模块,但在调用产品表单时,我看不到新字段

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

我在这里遗漏了什么?

检查以下内容:

  • 继承自正确的基本表单
    product.template.common.form
  • 确保查看的是product.template(产品)的正确表单,而不是product.product(产品变体)
  • 在编辑模式下是否看到没有标题的输入字段?如果是这种情况,您可以在html级别破坏结构。下一个子弹将解决这个问题
  • 标准价格字段具有唯一的html结构,因为它可以连接计量单位(uom)。尝试连接到简单字段或使用container div standard_price_uom进行连接,请参见下面的模板代码
标准价格计量单位div后有新字段的工作视图的模板代码:

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


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

确保使用正确的模型。使用
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()

product.template.form
产品模板
...
类ProductTemplate(models.Model):
_inherit=“product.template”
my_field=fields.Char()

确保您已将XML文件添加到模块的
\uuuu manifest\uuuu.py
文件中。Odoo只从您告诉它的文件中提取XML

您可以在任何核心模块上看到这方面的示例。有关示例,请参见

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

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

我已经在奥多12中测试过了

<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <record id="view_product_template_common_form_inherit" model="ir.ui.view">
        <field name="name">product.template.common.form.inherit</field>
        <field name="model">product.template</field>
        <field name="inherit_id" ref="product.product_template_form_view"/>
        <field name="arch" type="xml">
            <xpath expr="//div[@name='standard_price_uom']" position="after">
                <label for="my_field" string="My Field"/>
                <div>
                    <field name="my_field"/>
                </div>
            </xpath>
        </field>
    </record>
</odoo>

product.template.common.form.inherit
产品模板

这取决于您在Odoo中如何使用产品。您应该考虑字段是否属于模板或变体。这个问题应该首先由提问者回答。@CZoellner他使用了
产品\模板\表单\视图
。是的,我并不是说你的答案是错误的,但问题并不完全清楚;-)结果发现我的代码有3处错误,使用“变体”产品和“产品”数据库模型,由于@Veikko在接受答案中指出的“标准价格”的性质,从错误的形式继承而来,并且在显示字段时出现问题。@CleberGoncalves我发布了此消息,因为您的问题不清楚,不知道您真正想做什么,我很高兴您找到了问题的好答案。您添加了什么型号领域?你了解Odoos产品模板和变体的概念吗?@CZoellner不确定我是否完全理解它,你有什么参考资料吗?已经有一个关于它的例子:-)这很有效。你有关于如何找到“正确的基本形式”的参考文件吗?实际上你有一个很好的问题。我没有任何参考文件。我搜索了standard_price,找到了表单的基本结构,并从中继承。我完全同意我们应该有关于这个的Odoo文档。这会让生活更轻松一点。