odoo:创建新表单视图时出错:字段`arch`对约束失败:视图定义无效

时间:2022-03-29 15:52:07

I want to create new form view associated to new data model, I create a new menu item "menu1" that has a submenu "menus" and then, I want to customize the action view. This is my code:

我想创建一个与新数据模型相关的新表单视图,我创建一个新菜单项“menu1”,它有一个子菜单“菜单”然后,我想自定义操作视图。这是我的代码:

My xml file:

我的xml文件:

My data model:

我的数据模型:

from openerp.osv import fields, osv

class hr_cutomization(osv.osv):

_inherit = "hr.employee"

_columns = {
  'new_field_ID': fields.char('new filed ID',size=11)
}

_default={
  'new_field_ID':0
}

hr_cutomization()

class hr_newmodel(osv.osv):

_name = "hr.newmodel"

_columns = {
  'field1': fields.char('new filed1',size=11),
  'field2': fields.char('new filed2',size=11)
}

_default={
  'field1':0
}

hr_newmodel()

When I update my module, I got this error:

当我更新我的模块时,我收到此错误:

ParseError: "ValidateError Field(s) arch failed against a constraint: Invalid view definition Error details: Element '

ParseError:“ValidateError Field(s)arch对约束失败:视图定义无效错误详细信息:Element'

what's doing wrong in my code ?

我的代码中出了什么问题?

2 个解决方案

#1


Just Update your view action in your xml file some think like this

只需在xml文件中更新您的视图操作,就像这样

<record id="new_action" model="ir.actions.act_window">
        <field name="name">New</field>
        <field name="type">ir.actions.act_window</field>
        <field name="res_model">hr.newmodel</field>
        <field name="view_type">form</field>
        <field name="view_mode">form,tree</field>
        <field name="view_id" ref="view_new_form"/>
    </record>

Just update your py file

只需更新你的py文件

from openerp.osv import fields, osv

class hr_cutomization(osv.osv):

_inherit = "hr.employee"

_columns = {
  'new_field_ID': fields.char('new filed ID',size=11)
}

_default={
  'new_field_ID':'0'
}

hr_cutomization()

class hr_newmodel(osv.osv):

_name = "hr.newmodel"

_columns = {
  'field1': fields.char('new filed1',size=11),
  'field2': fields.char('new filed2',size=11)
}

_default={
  'field1':'0'
}

hr_newmodel()

In this .py your are assign as char field but you are using _defaults as 0 (as integer) you must have to pass it as character not the integer in your _default attributes.

在此.py中,您将被指定为char字段,但是您使用_defaults作为0(作为整数),您必须将其作为字符传递,而不是_default属性中的整数。

and you are creating your module in OpenERP 7.0 then the add the new form Attribute as the version="7.0" in your form tag of your view. If it is in odoo 8.0 then it is not needed to do so.

然后在OpenERP 7.0中创建模块,然后在视图的表单标记中添加新表单Attribute作为version =“7.0”。如果它在odoo 8.0中,则不需要这样做。

#2


I got the same error, and in my case it was because of a wrong indentation in my .py file. Try doing the indentation in the correct way, something like this:

我得到了同样的错误,在我的情况下,这是因为我的.py文件中有一个错误的缩进。尝试以正确的方式进行缩进,如下所示:

from openerp.osv import fields, osv

class hr_cutomization(osv.osv):

    _inherit = "hr.employee"

    _columns = {
      'new_field_ID': fields.char('new filed ID',size=11)
    }

    _default={
      'new_field_ID':'0'
    }

    hr_cutomization()

class hr_newmodel(osv.osv):

    _name = "hr.newmodel"

    _columns = {
      'field1': fields.char('new filed1',size=11),
      'field2': fields.char('new filed2',size=11)
    }

    _default={
      'field1':'0'
    }

    hr_newmodel()

I think that way could work

我认为这种方式可行

#1


Just Update your view action in your xml file some think like this

只需在xml文件中更新您的视图操作,就像这样

<record id="new_action" model="ir.actions.act_window">
        <field name="name">New</field>
        <field name="type">ir.actions.act_window</field>
        <field name="res_model">hr.newmodel</field>
        <field name="view_type">form</field>
        <field name="view_mode">form,tree</field>
        <field name="view_id" ref="view_new_form"/>
    </record>

Just update your py file

只需更新你的py文件

from openerp.osv import fields, osv

class hr_cutomization(osv.osv):

_inherit = "hr.employee"

_columns = {
  'new_field_ID': fields.char('new filed ID',size=11)
}

_default={
  'new_field_ID':'0'
}

hr_cutomization()

class hr_newmodel(osv.osv):

_name = "hr.newmodel"

_columns = {
  'field1': fields.char('new filed1',size=11),
  'field2': fields.char('new filed2',size=11)
}

_default={
  'field1':'0'
}

hr_newmodel()

In this .py your are assign as char field but you are using _defaults as 0 (as integer) you must have to pass it as character not the integer in your _default attributes.

在此.py中,您将被指定为char字段,但是您使用_defaults作为0(作为整数),您必须将其作为字符传递,而不是_default属性中的整数。

and you are creating your module in OpenERP 7.0 then the add the new form Attribute as the version="7.0" in your form tag of your view. If it is in odoo 8.0 then it is not needed to do so.

然后在OpenERP 7.0中创建模块,然后在视图的表单标记中添加新表单Attribute作为version =“7.0”。如果它在odoo 8.0中,则不需要这样做。

#2


I got the same error, and in my case it was because of a wrong indentation in my .py file. Try doing the indentation in the correct way, something like this:

我得到了同样的错误,在我的情况下,这是因为我的.py文件中有一个错误的缩进。尝试以正确的方式进行缩进,如下所示:

from openerp.osv import fields, osv

class hr_cutomization(osv.osv):

    _inherit = "hr.employee"

    _columns = {
      'new_field_ID': fields.char('new filed ID',size=11)
    }

    _default={
      'new_field_ID':'0'
    }

    hr_cutomization()

class hr_newmodel(osv.osv):

    _name = "hr.newmodel"

    _columns = {
      'field1': fields.char('new filed1',size=11),
      'field2': fields.char('new filed2',size=11)
    }

    _default={
      'field1':'0'
    }

    hr_newmodel()

I think that way could work

我认为这种方式可行