Odoo - ParseError:" ValidateError字段`arch`对约束失败:视图定义无效

时间:2015-07-25 13:13:43

标签: python xml odoo odoo-8

我正在关注Odoo的教程,我必须创建一个新视图来轻松创建/编辑付款方式。在Sales Order中添加many2one字段可以正常工作,但是一旦我添加教程中给出的xml行并进行升级就会出错。重新启动服务会导致内部服务器错误。

init是正确的,所以不应该是问题,没有xml更改的py工作正常。

这是我得到的错误

    Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 537, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 574, in dispatch
    result = self._call_function(**self.params)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 310, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 113, in wrapper
    return f(dbname, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 307, in checked_call
    return self.endpoint(*a, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 803, in __call__
    return self.method(*args, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 403, in response_wrap
    response = f(*args, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/addons/web/controllers/main.py", line 948, in call_button
    action = self._call_kw(model, method, args, {})
  File "/usr/lib/python2.7/dist-packages/openerp/addons/web/controllers/main.py", line 936, in _call_kw
    return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 241, in wrapper
    return old_api(self, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/addons/base/module/module.py", line 533, in button_immediate_upgrade
    return self._button_immediate_function(cr, uid, ids, self.button_upgrade, context=context)
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 241, in wrapper
    return old_api(self, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/addons/base/module/module.py", line 494, in _button_immediate_function
    registry = openerp.modules.registry.RegistryManager.new(cr.dbname, update_module=True)
  File "/usr/lib/python2.7/dist-packages/openerp/modules/registry.py", line 370, in new
    openerp.modules.load_modules(registry._db, force_demo, status, update_module)
  File "/usr/lib/python2.7/dist-packages/openerp/modules/loading.py", line 351, in load_modules
    force, status, report, loaded_modules, update_module)
  File "/usr/lib/python2.7/dist-packages/openerp/modules/loading.py", line 255, 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/python2.7/dist-packages/openerp/modules/loading.py", line 176, in load_module_graph
    _load_data(cr, module_name, idref, mode, kind='data')
  File "/usr/lib/python2.7/dist-packages/openerp/modules/loading.py", line 118, in _load_data
    tools.convert_file(cr, module_name, filename, idref, mode, noupdate, kind, report)
  File "/usr/lib/python2.7/dist-packages/openerp/tools/convert.py", line 901, in convert_file
    convert_xml_import(cr, module, fp, idref, mode, noupdate, report)
  File "/usr/lib/python2.7/dist-packages/openerp/tools/convert.py", line 987, in convert_xml_import
    obj.parse(doc.getroot(), mode=mode)
  File "/usr/lib/python2.7/dist-packages/openerp/tools/convert.py", line 853, in parse
    self._tags[rec.tag](self.cr, rec, n, mode=mode)
  File "/usr/lib/python2.7/dist-packages/openerp/tools/convert.py", line 763, in _tag_record
    id = self.pool['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/python2.7/dist-packages/openerp/api.py", line 241, in wrapper
    return old_api(self, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/addons/base/ir/ir_model.py", line 1077, in _update
    res_id = model_obj.create(cr, uid, values, context=context)
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 241, in wrapper
    return old_api(self, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/addons/base/ir/ir_ui_view.py", line 264, in create
    context=context)
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 241, in wrapper
    return old_api(self, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 336, in old_api
    result = method(recs, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/models.py", line 4076, in create
    record = self.browse(self._create(old_vals))
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 239, in wrapper
    return new_api(self, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 463, in new_api
    result = method(self._model, cr, uid, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/models.py", line 4267, in _create
    recs._validate_fields(vals)
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 239, in wrapper
    return new_api(self, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/models.py", line 1271, in _validate_fields
    raise ValidationError('\n'.join(errors))
ParseError: "ValidateError
Field(s) `arch` failed against a constraint: Invalid view definition

Error details:
Field `writeoff` does not exist

Error context:
View `xx.payment.method tree`
[view_id: 868, xml_id: n/a, model: xx.payment.method, parent_id: n/a]" while parsing /home/pantera/Custom/xx_khleuven2/view/sale.xml:18, near
<record id="view_payment_method_tree" model="ir.ui.view">
            <field name="model">xx.payment.method</field>
            <field name="arch" type="xml">
                <tree string="Payment methods">
                    <field name="name"/>
                    <field name="writeoff"/>
                </tree>
            </field>
        </record>

我的py文件

   from datetime import datetime, timedelta
   import time
   from openerp.osv import fields, osv
   from openerp.tools.translate import _
   from openerp.tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT
   import openerp.addons.decimal_precision as dp
   from openerp import workflow

class SaleOrder(osv.Model):
    _inherit = 'sale.order'

    _columns = {
        'xx_delivery_date': fields.date(string='Delivery date'),
        #'xx_payment_method': fields.selection([('visa', 'Visa'),
        #                                       ('cash', 'Cash')],
        #                                      string='Payment method'),
        'xx_payment_method': fields.many2one('xx.payment.method',
                                             string='Payment method')
    }

class PaymentMethod(osv.Model):
    _name = 'xx.payment.method'

    _columns = {
        'name': fields.char(size=128, string='Name'),
        'writeoff': fields.boolean(string='Writeoff'),
        'sale_ids': fields.one2many('sale.order', 'xx_payment_method',
                                    string='Sale orders')
    }

xml文件。在------行之间是应该创建新菜单的部分。

  <?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
        <record id="view_order_form" model="ir.ui.view">
            <field name="model">sale.order</field>
            <field name="inherit_id" ref="sale.view_order_form"/>
            <field name="arch" type="xml">
                <field name="client_order_ref" position="after">
                    <field name="xx_delivery_date"/>
                </field>

                <xpath expr="//form//field[@name='client_order_ref']" position="after">
                    <field name="xx_payment_method"/>
                </xpath>
            </field>
        </record>
        -------------------------------------------------------------
        <record id="view_payment_method_tree" model="ir.ui.view">
            <field name="model">xx.payment.method</field>
            <field name="arch" type="xml">
                <tree string="Payment methods">
                    <field name="name"/>
                    <field name="writeoff"/>
                </tree>
            </field>
        </record>

        <record id="action_payment_method" model="ir.actions.act_window">
            <field name="name">Payment methods</field>
            <field name="res_model">xx.payment.method</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,form</field>
        </record>

        <menuitem id="menu_payment_method" action="action_payment_method"
             parent="base.menu_base_config"/>
       -------------------------------------------------------------
    </data>
</openerp>

我不知道该字段未被识别的原因,我将其与教程中的代码进行了比较,但我找不到任何差异。

提前致谢。

编辑: 我尝试重命名字段,然后注销&#39;没有给出错误,但名称是&#39;场确实。重新命名&#39;字段不会更改任何内容,错误会保留在该字段上。

EDIT2: 好吧问题似乎已经解决了,我不知道为什么......在经历了挫折之后再次回来并再次尝试,一切正常,所以是的... 无论如何,谢谢你的帮助!

1 个答案:

答案 0 :(得分:1)

同意@HardikPatadia:重新启动重新加载py文件的服务器后,通常会解决您获得的错误(“找不到字段”)。你说重新启动会给你一个内部服务器错误,所以你应该检查Odoo日志文件以查看错误是什么 - 可能是一些python错误。

另一件可能错误的事情是您没有在 init .py中导入py文件,因此无法识别字段。