官术网_书友最值得收藏!

Creating the form view

All views are stored in the database, in the ir.ui.view model. To add a view to a module, we declare a <record> element describing the view in an XML file, which is to be loaded into the database when the module is installed.

Add this new views/todo_view.xml file to define our form view:

<?xml version="1.0"?> 
<odoo> 
  <record id="view_form_todo_task" model="ir.ui.view"> 
    <field name="name">To-do Task Form</field> 
    <field name="model">todo.task</field> 
    <field name="arch" type="xml"> 
      <form string="To-do Task"> 
        <group>
          <field name="name"/> 
          <field name="is_done"/> 
          <field name="active" readonly="1"/> 
        </group> 
      </form> 
    </field> 
  </record> 
</odoo> 

The ir.ui.view record has values for three fields: name, model, and arch. Another important element is the record id. It defines an XML ID identifier that can be used for other records to reference it.

The view is for the todo.task model and is named To-do Task Form. The name is just for information; it does not have to be unique, but it should allow one to easily identify which record it refers to. In fact, the name can be entirely omitted; in that case, it will be automatically generated from the model name and the view type.

The most important field is arch, as it contains the view definition, highlighted in the XML code listed previously. The <form> tag defines the view type, and in this case contains three fields. We added the readonly attribute to the active field, to make it read-only in the user interface.

Remember to add this new file to the data key in the manifest file; otherwise, our module won't know about it and it won't be loaded:

'data': [
'views/todo_menu.xml',
'views/todo_view.xml',
],
Remember that for the changes to be loaded to our Odoo database, a module upgrade is needed. To see the changes in the web client, the form needs to be reloaded. Either click again on the menu option that opens it or reload the browser page ( F5 in most browsers).
主站蜘蛛池模板: 宁乡县| 宝兴县| 东丰县| 渭南市| 石嘴山市| 新宁县| 南京市| 河北省| 凤冈县| 石泉县| 秦皇岛市| 周口市| 竹北市| 东至县| 鹤峰县| 桂林市| 八宿县| 垣曲县| 鸡泽县| 彭阳县| 黄陵县| 商洛市| 洛南县| 亚东县| 家居| 交口县| 特克斯县| 曲麻莱县| 剑阁县| 富源县| 吉首市| 高雄市| 天水市| 旺苍县| 临夏县| 灌阳县| 乐都县| 社旗县| 建平县| 泾源县| 凌海市|