一:模型module:

1. 字段类型

(1)可控字段:

  fileds.char()

  fileds.Boolean()

  fileds.Date()

(2)保留字段:(系统自动生成)

id (Id)
the unique identifier for a record in its model
create_date (Datetime)
creation date of the record
create_uid (Many2one)
user who created the record
write_date (Datetime)
last modification date of the record
write_uid (Many2one)
user who last modified the record

2. 字段属性

string (unicode, default: field’s name)
在用户界面显示的标签名
required (bool, default: False)
如果是True, 则不可以为空值
help (unicode, default: '')
当用户悬停在UI字段上时,显示的提示。
index (bool, default: False)
要求odoo为此字段添加一个数据库索引。

二:视图views

1. 基本视图:

(1)树状视图Tree views

<tree string="Idea list">
<field name="name"/>
<field name="inventor_id"/>
</tree> (2)表单视图Form views
<form string="Idea form">
<group colspan="4">
<group colspan="2" col="2">
<separator string="General stuff" colspan="2"/>
<field name="name"/>
<field name="inventor_id"/>
</group> <group colspan="2" col="2">
<separator string="Dates" colspan="2"/>
<field name="active"/>
<field name="invent_date" readonly="1"/>
</group> <notebook colspan="4">
<page string="Description">
<field name="description" nolabel="1"/>
</page>
</notebook> <field name="state"/>
</group>
</form> (3)搜索视图
<search>
<field name="name"/>
<field name="inventor_id"/>
</search>
三:模型关系
1. 多对一:
(1)定义方式:
Many2one(other_model, ondelete='set null')

(2)取出方式

print foo.other_id.name

2. 一对多
(1)定义方式:
One2many(other_model, related_field)

(2)取出方式

for other in foo.other_ids:
print other.name
2. 多对多
(1)定义方式:
Many2many(other_model)

(2)取出方式

for other in foo.other_ids:
print other.name 待续
翻译自:
http://odoo-master.readthedocs.io/en/8.0/howtos/backend.html#build-an-odoo-module
 
05-07 15:17