我正在学习如何在OpenERP v7上开发模块。在我尝试添加向导之前一切正常:OpenERP将不接受我的View架构,我无法弄清楚原因!
模块架构是:
这是wizard.py文件:
# -*- coding: utf-8 -*-
from openerp.osv import fields, osv
class idea_wizard(osv.TransientModel):
_name = 'idea.wizard'
_columns = {
'idea_age': fields.integer('Age'),
}
这是wizard.xml文件:
<?xml version="1.0"?>
<openerp>
<data>
<!-- Idea Category Form View -->
<record model="ir.ui.view" id="view_idea_wizard_form">
<field name="name">idea.wizard.form</field>
<field name="model">idea.wizard</field>
<field name="arch" type="xml">
<form string="Cleanup" version="7.0">
<field name="idea_age"/>
</form>
</field>
</record>
</data>
</openerp>
目前这一切都是基本的,但我希望它有效,所以我可以在它上面......
这是服务器回溯:
Server Traceback (most recent call last):
File "/usr/lib/pymodules/python2.7/openerp/addons/web/session.py", line 89, in send
return openerp.netsvc.dispatch_rpc(service_name, method, args)
File "/usr/lib/pymodules/python2.7/openerp/netsvc.py", line 292, in dispatch_rpc
result = ExportService.getService(service_name).dispatch(method, params)
File "/usr/lib/pymodules/python2.7/openerp/service/web_services.py", line 622, in dispatch
security.check(db,uid,passwd)
File "/usr/lib/pymodules/python2.7/openerp/service/security.py", line 40, in check
pool = pooler.get_pool(db)
File "/usr/lib/pymodules/python2.7/openerp/pooler.py", line 49, in get_pool
return get_db_and_pool(db_name, force_demo, status, update_module)[1]
File "/usr/lib/pymodules/python2.7/openerp/pooler.py", line 33, in get_db_and_pool
registry = RegistryManager.get(db_name, force_demo, status, update_module)
File "/usr/lib/pymodules/python2.7/openerp/modules/registry.py", line 203, in get
update_module)
File "/usr/lib/pymodules/python2.7/openerp/modules/registry.py", line 233, in new
openerp.modules.load_modules(registry.db, force_demo, status, update_module)
File "/usr/lib/pymodules/python2.7/openerp/modules/loading.py", line 350, in load_modules
force, status, report, loaded_modules, update_module)
File "/usr/lib/pymodules/python2.7/openerp/modules/loading.py", line 256, in load_marked_modules
loaded, processed = load_module_graph(cr, graph, progressdict, report=report, skip_modules=loaded_modules, perform_checks=perform_checks)
File "/usr/lib/pymodules/python2.7/openerp/modules/loading.py", line 188, in load_module_graph
load_data(module_name, idref, mode)
File "/usr/lib/pymodules/python2.7/openerp/modules/loading.py", line 76, in <lambda>
load_data = lambda *args: _load_data(cr, *args, kind='data')
File "/usr/lib/pymodules/python2.7/openerp/modules/loading.py", line 124, in _load_data
tools.convert_xml_import(cr, module_name, fp, idref, mode, noupdate, report)
File "/usr/lib/pymodules/python2.7/openerp/tools/convert.py", line 954, in convert_xml_import
obj.parse(doc.getroot())
File "/usr/lib/pymodules/python2.7/openerp/tools/convert.py", line 847, in parse
self._tags[rec.tag](self.cr, rec, n)
File "/usr/lib/pymodules/python2.7/openerp/tools/convert.py", line 814, in _tag_record
id = self.pool.get('ir.model.data')._update(cr, self.uid, rec_model, self.module, res, rec_id or False, not self.isnoupdate(data_node), noupdate=self.isnoupdate(data_node), mode=self.mode, context=rec_context )
File "/usr/lib/pymodules/python2.7/openerp/addons/base/ir/ir_model.py", line 967, in _update
res_id = model_obj.create(cr, uid, values, context=context)
File "/usr/lib/pymodules/python2.7/openerp/addons/base/ir/ir_ui_view.py", line 103, in create
return super(view, self).create(cr, uid, values, context)
File "/usr/lib/pymodules/python2.7/openerp/osv/orm.py", line 4493, in create
self._validate(cr, user, [id_new], context)
File "/usr/lib/pymodules/python2.7/openerp/osv/orm.py", line 1561, in _validate
raise except_orm('ValidateError', '\n'.join(error_msgs)) except_orm: ('ValidateError', u'Error occurred while validating the field(s) arch: Invalid XML for View Architecture!')
如果我清空wizard.xml文件中的“arch”标记,则服务器不会引发任何错误。但我无法理解我的架构有什么问题。
感谢您的帮助:)
答案 0 :(得分:1)
简短回答
确保使用utf-8编码保存XML文件。在xml定义中添加encoding
属性:
<?xml version="1.0" encoding="utf-8"?>
希望这有帮助。
<强>详情
一般来说,OpenERP中的数据验证主要通过每个模型的_constraints属性中设置的方法来处理。在您的情况下,您在尝试创建新的ir.ui.view
对象时遇到错误。查看base/ir/ir_ui>view.py
文件,您可以看到以下内容:
_constraints = [
(_check_xml, 'Invalid XML for View Architecture!', ['arch'])
]
这里我们只定义了一个约束,并通过_check_xml
方法进行评估。看看这种方法,您可以看到除了XML本身的有效性之外,还进行了编码测试。 OpenERP 6.0中不存在此测试。这意味着您的视图可能会在OpenERP 6.0下正确呈现。
如果您愿意,可以通过在__check_xml
类的view
方法中添加断点来进一步调查。
答案 1 :(得分:1)