我想在产品模块的表单视图中显示一个字段,这是 python 文件(我使用 odoo 12。):
class ClassProductInherited:
_inherit = 'product.template'
file = fields.Char(string="Choose File")
这是xml代码(我使用odoo 12。):
<record id="view_product_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_only_form_view"/>
<field name="arch" type="xml">
<xpath expr="//page[@name='inventory']/group" position="before">
<group col="2" colspan="2">
<field name="file"/>
</group>
</xpath>
</field>
</record>
当我重新启动服务器时,问题是我有以下错误:
File "/home/odoo/models.py", line 1112, in _validate_fields
raise ValidationError("%s\n\n%s" % (_("Error while validating constraint"), tools.ustr(e)))
odoo.tools.convert.ParseError: "Error while validating constraint
Field `file` does not exist
Error context:
View `product.template.common.form.inherit`
[view_id: 2095, xml_id: module.view_product_form_inherit, model: product.template, parent_id: 402]
None" while parsing /home/omar/odoo/custom-addons/addons12/module/views/views.xml:403, near
<record id="view_product_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_only_form_view"/>
<field name="arch" type="xml">
<xpath expr="//page[@name='inventory']/group" position="before">
<group col="2" colspan="2">
<field name="file"/>
</group>
</xpath>
</field>
</record>