【问题标题】:field error in odoo (openerp)?odoo(openerp)中的字段错误?
【发布时间】:2015-05-26 08:45:07
【问题描述】:

我是开发模块odoo的初学者,所以在运行我的模块odoo时,我有这个结果:

模块架构是: init.py(我在这里导入 module.py) openerp.py(依赖:基础) _module.py(我有主要代码,一切正常) templates.xml(主视图与主代码一致,没问题)

    2015-05-26 08:13:05,515 6260 ERROR odoodb1    openerp.addons.base.ir.ir_ui_view: Field `titre` does not exist

Error context:
View `document.form`
[view_id: 873, xml_id: document_binov.document_form, model: document_binov.document_binov, parent_id: n/a]
2015-05-26 08:13:05,535 6260 INFO odoodb1 werkzeug: 127.0.0.1 - - [26/May/2015 08:13:05] "GET / HTTP/1.1" 500 -
2015-05-26 08:13:05,588 6260 ERROR odoodb1 werkzeug: Error on request:
raise ValidationError('\n'.join(errors))
ParseError: "ValidateError
Field(s) `arch` failed against a constraint: Invalid view definition

Error details:
Field `titre` does not exist

Error context:
View `document.form`
[view_id: 873, xml_id: document_binov.document_form, model: document_binov.document_binov, parent_id: n/a]" while parsing /home/binov1/git/odoo/addons/document_binov/templates.xml:29, near
<record model="ir.ui.view" id="document_form">
  <field name="name">document.form</field>
  <field name="model">document_binov.document_binov</field>
  <field name="type">form</field>
  <field name="arch" type="xml">
   <form string="Documents">
     <field name="titre"/> 
    <field name="description"/> 
     <field name="type"/> 
    </form>
  </field>
</record>

这是models.py文件:

 class document_binov(models.Model):
     _name = 'document_binov.document_binov'
     _description = 'visualise les documents'

titre = fields.Char(string='binov')
description = fields.Char(string='binov1')
type = fields.Char(string='binov2')

这是 template.xml 文件:

    <?xml version="1.0" encoding="utf-8"?>
        <openerp>
        <data>

<menuitem name="Documents" id="menu_list_doc" parent="Doc_Bin" sequence="10" />            

    <!-- Form example --> 
     <record model="ir.ui.view" id="document_form">
      <field name="name">document.form</field>
      <field name="model">document_binov.document_binov</field>
      <field name="type">form</field>
      <field name="arch" type="xml">
       <form string="Documents">
         <field name="titre"/> 
        <field name="description"/> 
         <field name="type"/> 
        </form>
      </field>
    </record> 

    <!--Tree view example -->
    <record model="ir.ui.view" id="document_tree_view">
     <field name="name">document.tree.view</field>
     <field name="model">document_binov.document_binov</field>
     <field name="type">tree</field>
     <field name="arch" type="xml">
      <tree string="Documents">
          <field name="titre"/>   
          <field name="description"/>
          <field name="type" />
      </tree>
    </field>
    </record>   

     <!-- déclaration d'action -->

     <record model="ir.actions.act_window" id="action_document_work"> 
      <field name="name">Liste des documents</field>
      <field name="res_model">document_binov.document_binov</field>
      <field name="view_type">form</field>
      <field name="view_mode">tree,form</field>
      <!-- <field name="help" type="html"/> --> 
      <field name="document_tree_view" ref="document_form"></field>

    </record>


     <!--déclaration menu -->

    <!-- déclaration de menu niveai 1.1(sans action=non cliquable) -->
    <menuitem id="document_menu" name="Liste des documents" parent="menu_list_doc" action="action_document_work" sequence="10"/> 

        </data>
    </openerp>

【问题讨论】:

  • 您需要调整您的 python 填充,以便字段成为您课程的一部分。如果你认为一切正常。尝试重新启动您的服务器,以便考虑 .py 修改,然后重新更新您的模块。

标签: python xml odoo openerp-7


【解决方案1】:

Python 通过每行中的选项卡数来识别块。在您的情况下,标题、描述和类型在类之外,因此它们没有被声明为属性。这就是系统返回该标题不是有效字段的原因。

把你的python代码改成

class document_binov(models.Model):
     _name = 'document_binov.document_binov'
     _description = 'visualise les documents'

     titre = fields.Char(string='binov')
     description = fields.Char(string='binov1')
     type = fields.Char(string='binov2')

【讨论】:

    【解决方案2】:
    ParseError: "ValidateError
    Field(s) `arch` failed against a constraint: Invalid view definition
    
    Error details:
    Field `titre` does not exist
    

    这意味着您的 view.xml 中有错误。您的 python 模型字段中不存在 titre 字段,

    这是在模型中声明字段的方法:

    _columns={
    
                'titre': fields.char('titre' , help="titre"),
         }
    

    有关模块创建的更多信息,请参阅 odoo 文档:odoo documantation

    希望对你有所帮助。

    【讨论】:

    • 这种定义字段的方式是正确的(使用_columns)。此外,它们在问题中的定义方式是正确的。不同之处在于旧 API(openERP 7 及更低版本)中使用的第一种方式,以及新 API(odoo 8)中使用的第二种方式。
    • @iouhammi 你错了,_columns 是旧 api(
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-29
    • 2015-08-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多