__init__.py
import product_img
這裏是初始化的時候需要模塊裏面的那些py文件,我這裏是product_img.py。所以寫import product_img
__terp__.py
{ "name" :
"simple_product_image" , "version" :
"1.0" , "depends" :
[ "product" ], "init_xml" :
[], "update_xml" :
[ "product_img_view.xml" ], "installable" :
True ,
"active" :
False ,
"author" :
"Joshua" , } |
這裏的最重要的有
“depends”:就是需要依賴哪些module,我這裏既然是繼承product當然就是product了。
“update_xml”:就是這個模塊需要的Xml。我寫了個是product_img_view.xml
product_img.py
#!/usr/bin/python from
osv import
osv, fields class
product_product(osv.osv): _name
=
'product.product' _inherit
=
'product.product' _description
=
'Product' _columns
=
{ 'pic' :fields.binary( 'Pic' ), } product_product() |
這裏是object的繼承
_name=’product.product’._inherit = ‘product.product’
此名字可以在Administrators->Customization->Database Structure->Object查找,不過我建議還是直接進addon裏面看product模塊
_columns就是字段了
‘pic’:fields.binary(‘Pic’), ‘pic’是字段名,就是數據庫裏面存的字段,fields.binary就是圖片在OE裏面的字段類型,後面的’Pic’是在OE裏面顯示的名稱。
product_img_view.xml
< openerp > < data > < record
id = "product_img_view"
model = "ir.ui.view" > < field
name = "name" >product.normal.form</ field > < field
name = "model" >product.product</ field > < field
name = "type" >form</ field > < field
name = "inherit_id"
ref = "product.product_normal_form_view" /> < field
name = "arch"
type = "xml" > < field
name = "name"
position = "before" > < field
name = "pic"
widget = "image"
nolabel = "1"
img_width = "300"
img_height = "300" /> </ field > </ field > </ record > </ data > </ openerp > |
這裏的格式其實都已經很固定的了。這裏是view的繼承
“id”代表的是這個view,唯一。
“name”就是你要繼承的view的名字
“model”就是你要繼承的view的object…
“ref”就是你要繼承的view的id
<field name=”name” position=”before”>
這句是是你的元件插入的時用於定位的我這裏的意思是插在name之前
<field name=”pic” widget=”image” nolabel=”1″ img_width=”300″ img_height=”300″/>
這句就是你所要插入的東西了,我這裏是插入一個圖片300*300大小的圖片。