




版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
Odoo90模塊開(kāi)發(fā)全流程
模塊組成
O業(yè)務(wù)對(duì)象
業(yè)務(wù)對(duì)象聲明為Python類(lèi),由Od。。自動(dòng)載入.
o數(shù)據(jù)文件
XML或CSV文件格式,在其中聲明了元數(shù)據(jù)(視圖或工作流)、配置數(shù)據(jù)(模塊參數(shù))'演示數(shù)據(jù)
等.
oWeb操縱器
處理Web掃瞄器發(fā)來(lái)的requests.
o靜態(tài)web數(shù)據(jù)
Web用到的圖像,CSS或JavaScript文件.
模塊結(jié)構(gòu)
一個(gè)Od。。模塊也是一個(gè)Python模塊,存放在一個(gè)名目中,包含一個(gè)_init_.py文件,用于導(dǎo)入其
他Python模塊.
from,importmymodule
odoo.py提供了一個(gè)子命令scaffold能夠方便地創(chuàng)建一個(gè)空的模塊.
$odoo.pyscaffold<modulename><wheretoputit>
命令執(zhí)行后,將會(huì)創(chuàng)建一個(gè)子名目同時(shí)其中包括了Od。。模塊所需的一些差不多文件.
練習(xí)#1
執(zhí)行./odoo.pyscaffoldopenacademyaddons,在addons名目下倉(cāng)U建一個(gè)名為openacademy
的模塊,生成的名目文件結(jié)構(gòu)如下.
openacademy
\~_init_.py
I-_openerp_.py
|—controllers.py
|—demo.xml
|—models.py
|—security
1—ir.model.access.csv
1—templates.xml
各文件內(nèi)容請(qǐng)查看文件或查看原又,然后對(duì)_openerp_.py中的幾種標(biāo)識(shí)文本進(jìn)行修改,
至少需要添加'installable':Tnje「application':True。
對(duì)象關(guān)系映射
ORM層是Odoo的一個(gè)關(guān)鍵組件,它能夠幸免大部分的SQL語(yǔ)句編寫(xiě)從而提高擴(kuò)展性和安全性.
業(yè)務(wù)對(duì)象用派生自Model的Python類(lèi)(模型)來(lái)編寫(xiě),該類(lèi)的_name屬性定義了模型在Odoo系統(tǒng)
中的名稱(chēng).
fromopenerpimportmodels
classMinimalModel(models.Model):
_name='test.model'
字段
字段定義模型能夠儲(chǔ)備什么以及在哪里儲(chǔ)備,字段在模型類(lèi)中用屬性來(lái)定義.
fromopenerpimportmodels,fields
classLessMinimalModel(models.Model):
_name='test.model2*
name=fields.Char()
通用屬性
與模型類(lèi)似,字段也能夠通過(guò)參數(shù)傳遞對(duì)其進(jìn)行設(shè)定:
name=field.Char(required=True)
字段的常用屬性有:
ostring(unicode,default:field,sname)
字段標(biāo)簽名稱(chēng)-會(huì)顯示在界面上〔對(duì)用戶(hù)可見(jiàn)〕。
orequired(bool,default:False)
假如值為T(mén)rue-此字段值不能為空,設(shè)置默認(rèn)值或者在創(chuàng)建記錄時(shí)提供。
□help(unicode,default:'')
界面上顯示提示語(yǔ)。
oindex(bool,default:False)
假如值為T(mén)rue?創(chuàng)建表時(shí)將為此列添加索引。
簡(jiǎn)單字段
字段能夠分為兩類(lèi):簡(jiǎn)單字段和關(guān)系字段.前者為原子值,直截了當(dāng)儲(chǔ)存在模型對(duì)應(yīng)的數(shù)艇表中;
后者連接到其他的記錄上(能夠是相同的模型也能夠是不同的模型).
Boolean,Date,Char這些差不多上簡(jiǎn)單字段.
保留字段
Odoo在模型中自動(dòng)創(chuàng)建并愛(ài)護(hù)一些字段,這些字段確實(shí)是保留字段,這些字段數(shù)據(jù)不需要也不應(yīng)該
手動(dòng)去修改.
oid(Id)
一條記錄的唯獨(dú)id。
ocreate_date(Datetime)
記錄創(chuàng)建時(shí)刻。
ocreate_uid(Many2one)
誰(shuí)創(chuàng)建的記錄。
owrite_date(Datetime)
最后修改時(shí)刻。
owrite_uid(Many2one)
誰(shuí)最后修改的記錄。
專(zhuān)門(mén)字段
默認(rèn)情形下,Odoo要求模型中有一個(gè)〃以776字段,用于顯示和搜索,通過(guò)設(shè)置」ejname也能夠達(dá)
到如此的目的.
練習(xí)#2
在openacademy模塊中定義一個(gè)新的模型Course,openacademy/models.py內(nèi)容如下:
#coding:utf-8
fromopenerpimportmodels,fields,api
classCourse(models.Model):
_name='openacademy.course'
name=fields.Char(string="Title",required=True)
description=fields.Text()
數(shù)據(jù)文件
Odoo是一個(gè)高度數(shù)據(jù)驅(qū)動(dòng)的系統(tǒng),盡管使用Python代碼來(lái)定制模塊行為,但專(zhuān)門(mén)多模塊數(shù)據(jù)是在
其載入時(shí)setup的,同時(shí)有些模塊僅僅為Odoo添加數(shù)據(jù).
通過(guò)數(shù)據(jù)文件來(lái)定義模塊數(shù)據(jù),例如能夠使用XML文件中的〈record〉元素定義數(shù)據(jù),每一個(gè)
〈record〉元素創(chuàng)建或者更新數(shù)據(jù)庫(kù)中的一條記錄,形式如下:
<openerp>
<data>
<recordmodel="{modelname}"id="{recordidentifier}“)
<fieldname="{afieldname)">{avalue)</field>
</record>
</data>
<openerp>
omodel
Odoo模型名.
oid
外部ID(ExternalIdentifier),通過(guò)它能夠引用到記錄(同時(shí)不需要明白記錄所在的數(shù)據(jù)庫(kù)ID).
o7L
name屬性用于確定字段名稱(chēng)(例如description),該元素的body給出字段的值.
數(shù)據(jù)文件必須在模塊載入清單文件列表中,也確實(shí)是_openerp一py的‘data'列表(全部載入)或‘
dem?!斜恚ㄖ挥性O(shè)定為載人演示數(shù)據(jù)才會(huì)載入)中.
練習(xí)#3
創(chuàng)建一個(gè)數(shù)據(jù)文件來(lái)向Course中添加數(shù)據(jù),編輯openacademy/demo.xml,并確認(rèn)
_openerp_.py的‘demo'列表中有該文件.
<openerp>
<data>
<recordmodel=Hopenacademy.course"id="course0">
<fieldname="name,,>Course0</field>
<fieldname=ndescription">Course0'sdescription
Canhavemultiplelines
</field>
</record>
<recordmodel="openacademy.course"id="coursel">
<fieldname="name">Coursel</field>
<!--nodescriptionforthisone-->
</record>
<recordmodel="openacademy.course"id="course2">
<fieldname="name">Course2</field>
<fieldname="description">Course2'sdescription</field>
</record>
</data>
</openerp>
動(dòng)作和菜單
在Od。。中,動(dòng)作和菜單差不多上定義在數(shù)據(jù)庫(kù)中的數(shù)據(jù)記錄,一樣通過(guò)數(shù)據(jù)文件來(lái)定義.
動(dòng)作能夠由三種方式觸發(fā):
O點(diǎn)擊菜單項(xiàng)(菜單項(xiàng)鏈接到特定動(dòng)作)
O點(diǎn)擊視圖上的按鈕(假如按鈕連接到動(dòng)作)
O作為對(duì)象的上下文動(dòng)作
使用<menuitem>聲明一個(gè)ir.ui.menu并將其連接到一個(gè)action,能夠用下面的形式的代碼.
<recordmodel="ir.actions.act_window"id="action__list__ideas">
<fieldname="name">Ideas</field>
<fieldname=,,res_modelH>idea.idea</field>
<fieldname="view_mode">tree?form</field>
</record>
<menuitemid="menu__ideas"parent="menu_root"name="Ideas"sequence="10"
action="action_list_ideas"/>
注意:action必須先于menu的連接使用定義,數(shù)據(jù)文件在載入時(shí)順序地執(zhí)行,因此動(dòng)作的ID必須第
一存在于數(shù)據(jù)庫(kù)中才能使用.
練習(xí)#4
定義一個(gè)新的菜單項(xiàng)訪問(wèn)OpenAcademy課程.
倉(cāng)U建openacademy/views/openacademy.xml文件,并在其中添加動(dòng)作和菜單.
<?xmlversion=H1.0"encoding="UTF-8"?>
<openerp>
<data>
<!--windowaction-->
<!--
Thefollowingtagisanactiondefinitionfora"windowaction",
thatisanactionopeningavieworasetofviews
-->
<recordmodel="ir.actions.act_window"id="course_list_action">
<fieldname="name">Courses</field>
<fieldname="res_model">openacademy.course</field>
<fieldname="view_type">form</field>
<fieldname="view_mode">tree>form</field>
<fieldname="help"type="html">
<pclass="oe_view_nocontent_create">Createthefirstcourse
</p>
</field>
</record>
<!--toplevelmenu:noparent-->
<menuitemid="main_openacademy_menu"name="OpenAcademy"/>
<!--Afirstlevelintheleftsidemenuisneeded
beforeusingaction=attribute-->
<menuitemid="openacademy_menu"name="OpenAcademy"
parent=',main_openacademy_menu,7>
<!--thefollowingmenuitemshouldappear*after*
itsparentopenacademy_menuand*after*its
actioncourse_list_action-->
<menuitemid="courses_menu"name=uCourses"parent="openacademy_menu"
action=ncourse_list__action'7>
<!--Fullidlocation:
action="openacademy.course_list_action"
Itisnotrequiredwhenitisthesamemodule-->
</data>
</openerp>
在_openerp_.py中添加那個(gè)數(shù)據(jù)文件名到’data7.
'data':[
#'security/ir'.model.access.csv,,
'templates.xml,,
'views/openacademy.xml'
],
更新模塊后能夠看到菜單,操作看看成效.
差不多視圖
視圖定義了模型數(shù)據(jù)如何顯示,每種類(lèi)型的視圖代表一種數(shù)據(jù)可視化模式.
差不多的視圖定義
一個(gè)視圖是以一條ir.ui.view模型數(shù)據(jù)的形式定義的.
<recordmodel="ir.ui.view"id="view_id">
<fieldname="name"></field>
<fieldname="model">object_name</field>
<fieldname="priority"eval="16"/>
<fieldname="arch"type="xml">
<!--viewcontent:<form>J<tree>,〈graph),...-->
</field>
</record>
Treeviews
Treeview也被稱(chēng)為listviews,在一個(gè)表格中顯示記錄.根元素是<tree>,最簡(jiǎn)形式的treeview只
是簡(jiǎn)單地列出每條記錄的多個(gè)字段,每個(gè)字段為一列.
<treestring="Idealist">
<fieldname="name"/>
<fieldname=,,inventor_id"/>
</tree>
Formviews
Form用于創(chuàng)建或編輯單條記錄,根元素是<form>,能夠在form中組合各種高層結(jié)構(gòu)元素(如
groups,notebooks)以及交互元素(如buttons,fields).
<formstring="Ideaform">
<groupcolspan="4">
<groupcolspan="2"col="2">
<separatorstring="Generalstuff"colspan="2"/>
<fieldname="name"/>
<fieldname="inventor_id"/>
</group>
<groupcolspan="2"col="2">
<separatorstring="Dates"colspan="2"/>
<fieldname="active"/>
<fieldname="invent_datenreadonly="l"/>
</group>
<notebookcolspan=H4">
<pagestring="Description">
<fieldname="description"nolabel="l"/>
</page>
</notebook>
<fieldname=,,state'7>
</group>
</form>
練習(xí)#5
為openacademy倉(cāng)”建formview,views/openacademy.xml數(shù)據(jù)文件中增加〈recordmodel=
ir.ui.view"…>內(nèi)容.
<?xmlversion="1.0"encoding="UTF-8"?>
<openerp>
<data>
<recordmodel=nir.ui.view"id="course_form_view">
<fieldname="name">course.form</field>
<fieldname="model">openacademy.course</field>
<fieldname="arch”type="xml">
<formstring="CourseForm">
<sheet>
<group>
<fieldname="name"/>
<fieldname="description"/>
</group>
</sheet>
</form>
</field>
</record>
<!--windowaction-->
<!--
Thefollowingtagisanactiondefinitionfora"windowaction",,
更新模塊,創(chuàng)建一個(gè)Course,能夠看到formview變了.
練習(xí)#6
使用〃。加6。。上在formview中,將description字段放在一個(gè)tab中,方便隨后添加其他tabs,對(duì)
練習(xí)#5的formview數(shù)據(jù)做如下修改.
<sheet>
<group>
<fieldname="name"/>
</group>
<notebook>
<pagestring="Description">
<fieldname="description"/>
</page>
<pagestring="About">
Thisisanexampleofnotebooks
</page>
</notebook>
</sheet>
</form>
</field>
更新模塊,看成效.
More
還能夠使用HTML為formview提供更加靈活的布局,例如下面的例子.
<formstring="IdeaForm">
<header>
<buttonstring="Confirm"type="object"name="action_confirm"
states="draft"class="oe_highlight"/>
<buttonstring="Markasdone"type="object"name=naction_done"
states="confirmed"class="oe_highlight"/>
<buttonstring='*Resettodraft"type="object"name="action_draftM
states="confirmeddone"/>
<fieldname=Hstate"widget="statusbar"/>
</header>
<sheet>
<divclass="oe_title">
<labelfor="name"c1ass="oe_edit_only"string="IdeaName"/>
<hlxfieldname="name"/></hl>
</div>
<separatorstring="General"colspan="2"/>
<groupcolspan="2"col="2">
<fieldname="description"placeholder="Ideadescription..."/>
</group>
</sheet>
</form>
Searchviews
Searchviews用來(lái)自定義listviews及其它統(tǒng)計(jì)/多條記錄視圖中的搜索字段.根元素為〈search〉,
其子元素定義了在哪些字段上進(jìn)行搜索.
<search>
<fieldname="name"/>
<fieldname="inventor_id"/>
</search>
假如一個(gè)模型沒(méi)有定義對(duì)應(yīng)的Searchview,odoo自動(dòng)創(chuàng)建一個(gè)僅搜索name字段的searchview.
練習(xí)#7
添加title以及description搜索,在views/openacademy.xml中定義searchview.
</field>
</record>
<recordmodel="in.ui.view"id="course_search__view">
<fieldname="name">course.search</field>
<fieldname="model">openacademy.course</field>
<fieldname="arch"type="xml">
<search>
<fieldname="name"/>
<fieldname="description"/>
</search>
</field>
</record>
<!--windowaction-->
<!--
Thefollowingtagisanactiondefinitionfora"windowaction*'
更新模塊,搜索框輸入字符后能夠看到下方能夠選擇搜索description字段.
模型中的關(guān)聯(lián)
概述
一個(gè)模型中的記錄可能關(guān)聯(lián)到其他模型的記錄,例如銷(xiāo)售訂單記錄會(huì)關(guān)聯(lián)到一個(gè)包含客戶(hù)信息的客
戶(hù)記錄.
練習(xí)#8
為了說(shuō)明數(shù)據(jù)關(guān)聯(lián),第一增加新的模型.
OpenAcademy模塊中,一個(gè)session是一個(gè)在特定時(shí)刻針對(duì)特定聽(tīng)眾講授課程的過(guò)程.需要為
session創(chuàng)建相應(yīng)的模型.
session具有name,開(kāi)始日期,連續(xù)時(shí)刻以及座位數(shù)量等.此外還需要添加相應(yīng)的action和
menuitem顯示模型數(shù)據(jù).
第一在openacademy/models.py中倉(cāng)U建Session類(lèi).
classSession(models.Model):
_name='openacademy.session'
name=fields.Char(required=True)
start_date=fields.Date()
duration=fields.Float(digits=(6^2),help="Durationindays")
seats=fields.Integer(string="Numberofseats")
然后在openacademy/view/openacademy.xml中添加用于訪問(wèn)session模型的action和
menuitem定義.
<!--Fullidlocation:
action=nopenacademy.course_list_action"
Itisnotrequiredwhenitisthesamemodule-->
<!--sessionformview-->
<recordmodel="ir.ui.view'1id="session_form_view">
<fieldname=,,name">session.form</field>
<fieldname="model">openacademy.session</field>
<fieldname="arch"type="xml">
<formstring="SessionForm">
<sheet>
<group>
<fieldname="name"/>
<fieldname="start_date"/>
<fieldname="duration"/>
<fieldname="seats'7>
</group>
</sheet>
</form>
</field>
</record>
<recordmodel="ir.actions.act_window"id=Hsession_list__action">
<fieldname="name">Sessions</field>
<fieldname=nres_model">openacademy.session</field>
<fieldname=,,view_type">form</field>
<fieldname="view__mode">treeJform</field>
</record>
<menuitemid="session_menu"name="SessionsH
parent="openacademy__menu"
action="session_list_action"/>
</data>
</openerp>
digits=(6,2)確定浮點(diǎn)數(shù)的精度,6表示總的數(shù)字位數(shù)(不包括小數(shù)點(diǎn)),2表示小數(shù)點(diǎn)后的位數(shù).因此,
digits=(6,2)小數(shù)點(diǎn)前最多4位.
關(guān)聯(lián)字段
關(guān)聯(lián)字段指向某些記錄,或者是相同的model(模型),或者是不同的model(模型)。
關(guān)聯(lián)字段類(lèi)型:
Manv2one(othermodel,ondelete='setnull')
One2manv(othermodel,relatedfield)
Marw2manv(othermodel)
練習(xí)#9
概述
?使用many2one修改Course和Session模型(model)?反映出與其他模型(model)的關(guān)聯(lián):
?每個(gè)Course有一個(gè)負(fù)責(zé)人,othejmodel值為res.users
?每個(gè)Session有一個(gè)老師■other_model值為res.partner
?一個(gè)Session關(guān)聯(lián)一個(gè)Course?other_model值為openacademy.course,必填
?調(diào)整view°
1.添加相關(guān)字段Many20ne至Umodel
2.添加到view
openacademy/models.py
name=fields.Char(string="Title”,required二True)
description=fields.Text()
responsible_id-fields.Many2oneC,
ondelete-setnul:,stringszResponsible,index=True)
ssSession(models.Model):
_name='openacademy,session'
start_date=fields.Date()
duration=fields.Float(digits=(6,2),help=*Durationindays")
seats=fields.Integer(string=*Numberofseats")
instructor_id-fields.Many2one(,strings)
course_id二fields.Many2one(,
=,
ondeletecascade',stringsCourse”,required二True)
openacademy/views/openacademy.xml
<sheet>
<group>
<fieldname="name"/)
<fieldname=*responsible_id*/>
</group>
<notebook>
<pagestring=*Description'*>
</field>
</record>
<!-overridetheautomaticallygeneratedlistviewforcourses->
<recordmodel=<rir.ui.view*id=*course_tree_view*>
:匚一"na?course,tree
:openacademy,course
<fieldname=*arch*type=*xml*>
<treestring=*CourseTree"〉
<fieldname="name"/)
<fieldname=*responsible_id*/>
</tree>
</field>
</record>
<!-windowaction—>
<!—
Thefollowingtagisanactiondefinitionfora"windowaction*,
<formstring="SessionForm”)
<sheet>
<group>
<groupstring=*GeneralJ*>
<fieldname=*course_id*/>
<fieldname="name"淞
<fieldname=<*instructor_id*/>
</group>
<groupstring=*Schedule*>
<fieldname=*start_date*/>
<fieldname=*duration*/>
<fieldname="seats'/)
</group>
</group>
</sheet>
</form>
</field>
</record>
<!-sessiontree/listview—>
<recordmodel=*ir.ui.view*id=*session_tree_view*>
;「小,::;;:“「一"name-session.tree</t'ield)
openacademy,session
<fieldname=*arch*type=*xml*>
<treestring=*SessionTree')
<fieldname="name"/)
<fieldname=*course_id*/>
</tree>
</record>
<recordmodel=/zir.actions.act_window*id=*session_list_action*>
<fieldname=*name*>Sessions</field>
<fieldname=/rres_model*>openacademy.session</field>
Exercise
Inverseone2manyrelations
Usingtheinverserelationalfieldone2many,modifythemodelstoreflecttherelationbetween
coursesandsessions.
1.Modifythecourseclass,and
2.addthefieldinthecourseformview.
openacademy/models.py
responsible_id=fields.Many2oneres.users',
ondelete=,setnulT,string="Responsible”,index=True)
session_ids=fields.0ne2many(
'openacademy.session*,'course_id,,string=/rSessions*)
classSession(models.Model):
openacademy/views/openacademy.xml
<pagestring=*Description*>
<fieldname="description”/)
</page>
<pagestring=*Sessions*>
<fieldname=*session_ids*>
<treestring="Registeredsessions"〉
<fieldname=*name*/>
<fieldname=*instructor_id*/>
</field>
</page>
</notebook>
</sheet>
Exercise
Multiplemany2manyrelations
Usingtherelationalfieldmany2many,modifytheSessionmodeltorelateeverysessiontoa
setofattendees.Attendeeswillberepresentedbypartnerrecords,sowewillrelatetothe
built-inmodelres.partner.Adapttheviewsaccordingly.
1.ModifytheSessionclass,and
2.addthefieldintheformview.
openacademy/models.py
instructor_id=fields.Many2one(i-es.partner),string="Instructor")
course_id=fields.Many2one(,openacademy.course,,
ondelete=,cascade',string=/rCourse*,required=True)
attendee_ids=fields.Many2many(es.pa:tncr',string=口)
openacademy/views/openacademy.xml
<fieldname="seats'/)
</group>
</group>
<labelfor=*attendee_ids*/>
<fieldname=/*attendee_ids*/>
</sheet>
</fonn>
</field>
Inheritance
Modelinheritance
Odooprovidestwoinheritancemechanismstoextendanexistingmodelinamodularway.
Thefirstinheritancemechanismallowsamoduletomodifythebehaviorofamodeldefinedin
anothermodule:
?addfieldstoamodel,
?overridethedefinitionoffieldsonamodel,
?addconstraintstoamodel,
?addmethodstoamodel,
?overrideexistingmethodsonamodel.
Thesecondinheritancemechanism(delegation)allowstolinkeveryrecordofamodeltoa
recordinaparentmodel,andprovidestransparentaccesstothefieldsoftheparentrecord.
TraditionalInheritanceDelegationInheritance
name=objlname=newname=new
inherit=objlJnherit=objlinherits=objl,...
PrototypeinheritanceDelegationinheritance
-Usedtoaddfeatures-Usedtocopyfeatures-Multipleinheritanceispossible
-Newclasscompatible-Newclassignoredbyexisting-Newclassignoredbyexistingviews
withexistingviewsviews-Storedindifferenttables
-Storedinsametable-Storedindifferenttables-'new'instancescontainanembedded
?objl'instancewithsynchronizedvalues
Seealso
?_inherit
?一inherits
Viewinheritance
Insteadofmodifyingexistingviewsinplace(byoverwritingthem),Odooprovidesview
inheritancewherechildren"extension"viewsareappliedontopofrootviews,andcanaddor
removecontentfromtheirparent.
Anextensionviewreferencesitsparentusingtheinheritedfield,andinsteadofasingleview
itsarchfieldiscomposedofanynumberofxpathelementsselectingandalteringthecontentof
theirparentview:
<!-improvedideacategorieslist—>
<recordid=*idea_category_list2/zmodel="ir.ui.view”〉
<fieldname=,/namez/>id.category.Iist2</field>
<fieldname=〃mode1〃>idea.category。field)
<fieldname="inherit_id“ref="rid_category__list/x/>
<fieldname="arch"type=
<!-findfielddescriptionandaddthefield
idea_idsafterit—>
<xpathexpr="〃field[@name='description']"position=*after?z>
<fieldname="idea_ids"string="zNumberofideas'/〉
</xpath>
</field>
</record>
expr
AnXPathexpressionselectingasingleelementintheparentview.Raisesanerrorifit
matchesnoelementormorethanone
position
Operationtoapplytothematchedelement:
inside
appendsxpath'sbodyattheendofthematchedelement
replace
replacesthematchedelementbythexpath'sbody
before
insertsthexpath'sbodyasasiblingbeforethematchedelement
after
insertsthexpaths'sbodyasasiblingafterthematchedelement
attributes
alterstheattributesofthematchedelementusingspecialattributeelementsin
thexpath'sbody
Tip
Whenmatchingasingleelement,thepositionattributecanbesetdirectlyonthe
elementtobefound.Bothinheritancesbelowwillgivethesameresult.
<xpathexpr=*//field[@name=,description1]*position="after”>
<fieldname="idea_ids"/>
</xpath>
<fieldname="description"position="after')
<fieldname="idea_ids"/>
</field>
Exercise
Alterexistingcontent
?Usingmodelinheritance,modifytheexistingPartnermodeltoadd
aninstructorbooleanfield,andamany2manyfieldthatcorrespondstothesession-
partnerrelation
?Usingviewinheritance,displaythisfieldsinthepartnerformview
Note
Thisistheopportunitytointroducethedevelopermodetoinspecttheview,findits
externalIDandtheplacetoputthenewfield.
1.Createafileopenacademy/partner.pyandimportitin_init_.py
2.Createafileopenacademy/views/partner.xmlandaddittO_openerp_.py
openacademy/_init_.py
#-*-coding:utf-8-*-
from.importcontrollers
from.importmodels
from,importpartner
openacademy/_openerp_.py
#'security/ir.model,access,csv',
'templates,xml',
'views/openacademy,xml',
'views/partner,xml',
],
#onlyloadedindemonstrationmode
'demo':[
openacademy/partner.py
#coding:utf-8
fromopenerpimportfields,models
Partner(models.Model):
_inherit='res-partner,
ftAddanewcolumntotheres.partnermodel,bydefaultpartnersarenot
#instructors
instructor=fields.Boolean(nstyu",default=False)
session_ids=fields.Many2many(openacademy.session',
string-s”,readonly二True)
openacademy/views/partner.xml
<?xmlversion="1.0"encoding="UTF-8”?>
<openerp>
<data>
<!-Addinstructorfieldtoexistingview—>
<recordmodel=*ir.ui.view*id=*partner_instructor_form_view*r>
<fieldiiHi!?:"name"partner,instructor
<iieldname="model'res.partnerfieia>
<fieldname=*inherit_id*ref=*base.view_partner_form*/>
<fieldname="arch"type="xml”>
<notebookposition="inside”)
<pagestring=*Sessions*>
<group>
<fieldname="instructor"/)
<fieldname=zrsession_idsV>
</group>
</page>
</notebook>
</record>
<recordmodel=*ir.actions.act_window"id=*contact_list_action*>
<fieldname=*name*>Contacts</field>
fio1dname:,,res_moder-res.partner</field>
<fieldname=*view__mode*>tree,form</fieldg
</record>
<menuitemid=*configuration_menu*name="rConfiguration*
parent=/rmain_openacademy_menu*/>
<menuitemid=*contact_menu*name="Contacts”
parent="configurationjnenu”
action=/rcontact_list_actionzr/>
</data>
</openerp>
Domains
InOdoo,Domainsarevaluesthatencodeconditionsonrecords.Adomainisalist
ofcriteriausedtoselectasubsetofamodel'srecords.Eachcriteriaisatriplewitha
fieldname,anoperatorandavalue.
Forinstance,whenusedontheProductmodelthefollowingdomainselects
allserviceswithaunitpriceover1000:
[('product_type1,''service*),('unit_price,,',1000)]
BydefaultcriteriaarecombinedwithanimplicitAND.Thelogical
operators&(AND),|(OR)and!(NOT)canbeusedtoexplicitlycombinecriteria.
Theyareusedinprefixposition(theoperator
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 3.5人眼看不見(jiàn)的光說(shuō)課稿 2024-2025學(xué)年蘇科版八年級(jí)上冊(cè)物理
- 2025合同范本快遞合伙承包協(xié)議
- 2025-2030古典家具修復(fù)人才缺口與職業(yè)教育體系構(gòu)建分析
- 2025-2030口腔數(shù)字化診療設(shè)備采購(gòu)周期與民營(yíng)診所升級(jí)需求預(yù)測(cè)
- 2025-2030口腔數(shù)字化診療設(shè)備滲透率增長(zhǎng)與民營(yíng)醫(yī)院采購(gòu)偏好研究
- 2025-2030口腔醫(yī)療行業(yè)市場(chǎng)現(xiàn)狀診療需求及連鎖模式分析研究報(bào)告
- 2025-2030即食辣椒零食消費(fèi)行為分析及產(chǎn)品創(chuàng)新方向預(yù)測(cè)報(bào)告
- 2025-2030醫(yī)藥臨床前研究外包服務(wù)市場(chǎng)規(guī)模與質(zhì)量控制分析報(bào)告
- 2025-2030醫(yī)療影像AI輔助診斷商業(yè)化落地與醫(yī)保支付政策影響分析報(bào)告
- 2025-2030醫(yī)療器械注冊(cè)人制度改革對(duì)行業(yè)影響評(píng)估報(bào)告
- 聯(lián)通運(yùn)營(yíng)合作協(xié)議合同
- 8.1 走進(jìn)人工智能 課件 2024-2025學(xué)年浙教版(2023)初中信息技術(shù)八年級(jí)下冊(cè)
- 鄂爾多斯盆地地質(zhì)特征與沉積模式分析
- 數(shù)字化賦能設(shè)計(jì)企業(yè)轉(zhuǎn)型升級(jí)
- 鼻部解剖結(jié)構(gòu)及其臨床表現(xiàn)
- 2025年糧油集團(tuán)筆試試題及答案
- 生鮮農(nóng)產(chǎn)品配送商業(yè)計(jì)劃書(shū)模板
- 2025年股東退股權(quán)益申請(qǐng)協(xié)議書(shū)范例
- 小學(xué)生乘坐飛機(jī)安全
- 《主動(dòng)脈夾層動(dòng)脈瘤》課件
- 配電房崗位職責(zé)
評(píng)論
0/150
提交評(píng)論