odoo(openerp)中的字段错误?

2024-09-24 02:28:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我是开发模块odoo的初学者,所以在运行模块odoo时,我得到了以下结果:

模块架构是: 在初始py(我导入的地方模块.py) 在打开程序.py(依赖项:基) _模块.py(我有主代码,一切正常) 模板.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>

这是模型.py文件:

^{pr2}$

这是模板.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>

Tags: 模块namepyformviewidtreefield
2条回答
ParseError: "ValidateError
Field(s) `arch` failed against a constraint: Invalid view definition

Error details:
Field `titre` does not exist

这意味着你的视图.xml. 在python模型字段中不存在titre字段

以下是如何在模型中声明字段:

^{pr2}$

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

我希望这能有所帮助。在

Python通过每行中的制表符数目来识别块。在您的例子中,title、description和type在类之外,因此它们不声明为属性。那就是为什么系统返回该标题不是有效字段。在

将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')

相关问题 更多 >