模块开发实例(Story 2)继承视图

__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大小的图片。

效果

发布了26 篇原创文章 · 获赞 13 · 访问量 9万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章