odoo的學習步驟五:inhert與xpath
model:
# -*- coding: utf-8 -*-
from odoo import models, fields, api
class test(models.Model):
_name = 'test.test'
name = fields.Char(string='名字')
sex = fields.Char(string='性別')
age = fields.Char(string='年齡')
hobby_id = fields.Many2one('test.hobby',ondelete='set null',string='愛好')
class hobby(models.Model):
_name = 'test.hobby'
name = fields.Char(string='愛好')
person_ids = fields.One2many('test.test','hobby_id',string='愛好的人')
person_ids_num = fields.Integer(string='愛好的人的數量',compute='_compute_person_num')
@api.depends('person_ids')
@api.multi
def _compute_person_num(self):
for i in self:
i.person_ids_num = len(i.person_ids)
xml:
<odoo>
<data>
<record model="ir.ui.view" id="hobby_list">
<field name="name">hobby_list</field>
<field name="model">test.hobby</field>
<field name="arch" type="xml">
<tree>
<field name="name"/>
<field name="person_ids_num"/>
</tree>
</field>
</record>
<record model="ir.ui.view" id="hobby_form">
<field name="name">hobby_form</field>
<field name="model">test.hobby</field>
<field name="arch" type="xml">
<form>
<group colspan="4">
<group colspan="2" col="2">
<field name="name"/>
</group>
<notebook colspan="4">
<page string="person">
<field name="person_ids">
<tree>
<field name="name"/>
<field name="sex"/>
<field name="age"/>
</tree>
</field>
</page>
</notebook>
</group>
</form>
</field>
</record>
<record model="ir.ui.view" id="myself_list">
<field name="name">myself_list</field>
<field name="model">test.test</field>
<field name="arch" type="xml">
<tree>
<field name="name"/>
<field name="sex"/>
<field name="age"/>
<field name="hobby_id"></field>
</tree>
</field>
</record>
<record model="ir.ui.view" id="myself_form">
<field name="name">myself_form</field>
<field name="model">test.test</field>
<field name="arch" type="xml">
<form>
<group colspan="4">
<group colspan="2" col="2">
<separator string="Myname" colspan="2"/>
<field name="name"/>
<!--<field name="age" nolabel="1"/>-->
</group>
<group colspan="2" col="2">
<separator name="title" string="Mysex" colspan="2"/>
<!--<field name="sex"/>-->
</group>
<notebook colspan="4">
<page string="hobby">
<field name="hobby_id" nolabel="1"/>
</page>
</notebook>
</group>
</form>
</field>
</record>
<record model="ir.ui.view" id="add_field">
<field name="name">add_field</field>
<field name="model">test.test</field>
<field name="inherit_id" ref="myself_form"></field>
<field name="arch" type="xml">
<xpath expr="//field[@name='name']" position="before">
<field name="age"></field>
</xpath>
<xpath expr="//separator[@name='title']" position="after">
<field name="sex"></field>
</xpath>
</field>
</record>
<record model="ir.ui.view" id="myself_search">
<field name="name">myself_search</field>
<field name="model">test.test</field>
<field name="arch" type="xml">
<search>
<field name="name"></field>
<field name="sex"></field>
<field name="age"></field>
<separator/>
<filter string="超過" name="more" domain="[('age','>','18')]"></filter>
<separator/>
<group>
<filter string="sex" name="sex" domain="[]" context="{'group_by':'sex'}"></filter>
</group>
</search>
</field>
</record>
<record model="ir.actions.act_window" id="myself_ideas">
<field name="name">myself</field>
<field name="res_model">test.test</field>
<field name="view_model">tree,form</field>
</record>
<record model="ir.actions.act_window" id="hobby_idea">
<field name="name">hobby</field>
<field name="res_model">test.hobby</field>
<field name="view_model">tree,form</field>
</record>
<menuitem id="first_menu" name="first_menu"/>
<menuitem id="second_menu" name="second_menu" parent="first_menu"/>
<menuitem id="menu_myself" name="menu_myself" parent="second_menu" action="myself_ideas"/>
<menuitem id="menu_hobby" name="menu_hobby" parent="second_menu" action="hobby_idea"/>
</data>
</odoo>
相關文章
- 學習SAP的步驟
- 學習java的步驟Java
- mvc框架的學習步驟MVC框架
- 深度學習學習7步驟深度學習
- SSH框架學習步驟框架
- 學習編譯原理的步驟編譯原理
- odoo學習-1Odoo
- odoo學習-2Odoo
- 分享給Python愛好者的五大學習步驟Python
- STM32學習步驟
- 新媒體如何學習?五個步驟讓你快速入門!
- Java怎麼學?Java的學習步驟分享Java
- 商業與IT專案聯合的五步驟(轉)
- XPath學習筆記筆記
- 【經驗】學習android開發的步驟Android
- 詳解學習C#的方法和步驟C#
- JS開發步驟學習筆記JS筆記
- Java培訓學習步驟有哪些Java
- 一個零基礎學習Python應該知道的學習步驟與規劃Python
- C++學習步驟(C++該如何學)C++
- XPath學習:軸(3)——descendant
- 應用容器化的五個步驟
- 通向微服務成功的五個步驟微服務
- [PyTorch 學習筆記] 3.1 模型建立步驟與 nn.ModulePyTorch筆記模型
- 學習C#的一般性步驟C#
- Data Guard學習之物理standby建立步驟
- odoo ORM API學習總結兼orm學習教程OdooORMAPI
- Git學習2 --- Git安裝詳細步驟Git
- kettle學習筆記(四)——kettle輸入步驟筆記
- 優思學院|3步驟計算出Cpk|學習Minitab
- OceanBase學習之路42|建立新的資源池的步驟?
- odoo 許可權管理學習總結Odoo
- odoo Web Controllers 學習總結OdooWebController
- 變革家五步投資法學習體會
- 維護伺服器的五大步驟伺服器
- MongoDB 效能優化五個簡單步驟MongoDB優化
- 學習Python最正確的步驟(0基礎必備)Python
- 讓你輕鬆學習新程式碼庫的六個步驟