在树视图odoo 10.0中添加新字段时出错



我想在产品树视图中添加新属性,但在启动服务器并更新插件时发生了错误,如下所示:

ParseError:"反转录验证错误

Modxe8le non trouvxe9 : product.template
Contexte de l'erreur :
Vue `productTree`
[view_id: 752, xml_id: n/a, model: product.template, parent_id: 308]
None" while parsing /opt/odoo/odoo-10.0/addons/test_tuto/views/views.xml:3, near
<record id="view_product_tree_inherit" model="ir.ui.view">
<field name="inherit_id" ref="product.product_template_tree_view"/>
<field name="name">productTree</field>
<field name="model">product.template</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<xpath expr="/tree/field[@name='categ_id']" position="after">
<field name="calories"/>
<field name="servingsize"/>
<field name="lastupdated"/>
</xpath>
</field>
</record>

这是我的视图源代码,

<record id="view_product_tree_inherit" model="ir.ui.view">
<field name="inherit_id" ref="product.product_template_tree_view"/>
<field name="name">productTree</field>
<field name="model">product.template</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<xpath expr="/tree/field[@name='categ_id']" position="after">
<field name="calories"/>
<field name="servingsize"/>
<field name="lastupdated"/>
</xpath>
</field>
</record>

这是我在类中添加的python代码,其中3个字段继承自产品模板类。

from odoo import models, fields, api
class test_tuto(models.Model):
_inhirit = 'product.template'
calories = fields.Integer("Calories")
servingsize = fields.Float("Serving size")
lastupdated = fields.Datetime('Last Updated')

按照你的要求,你是我的manifest.py文件我在views.xml文件中编写xml代码

# -*- coding: utf-8 -*-
{
'name': "Test_tuto",
'summary': """
Short (1 phrase/line) summary of the module's purpose, used as
subtitle on modules listing or apps.openerp.com""",
'description': """
Long description of module's purpose
""",
'author': "My Company",
'website': "http://www.yourcompany.com",
# Categories can be used to filter modules in modules listing
# Check https://github.com/odoo/odoo/blob/10.0/odoo/addons/base/module/module_data.xml
# for the full list
'category': 'Uncategorized',
'version': '0.1',
# any module necessary for this one to work correctly
'depends': ['base'],
# always loaded
'data': [
# 'security/ir.model.access.csv',
'views/views.xml',
'views/templates.xml',
],
# only loaded in demonstration mode
'demo': [
'demo/demo.xml',
],
}

请尝试像这样更改"xpath">

在依赖中添加">产品">

'depends': ['base','product'],

<xpath expr="//tree/field[@name='categ_id']" position="after">
<field name="calories"/>
<field name="servingsize"/>
<field name="lastupdated"/>
</xpath>

最新更新