我想在产品树视图中添加新属性,但是启动服务器并更新插件时出现错误:
ParseError:“违禁品验证员
Mod\xe8le non trouv\xe9 : 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>
这是我在类中添加了3个字段的python代码,它们从产品模板类继承。
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文件 我将XML代码写在views.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',
],
}
答案 0 :(得分:1)
请尝试这样更改您的“ xpath”
在“ ”中添加“ 产品”
'depends': ['base','product'],
<xpath expr="//tree/field[@name='categ_id']" position="after">
<field name="calories"/>
<field name="servingsize"/>
<field name="lastupdated"/>
</xpath>