YAML 数据序列化
YAML 是 human-readable 可读的数据序列化格式 概念源于 C, Perl, Python, 主意来自 XML 和电子邮件的数据格式. YAML stands for YAML Ain’t Markup Language (yes, that’s a recursive acronym). YAML 用于 OpenERP 数据格式 as of OpenERP 6.0, 有以下优点:
作为当前的 XML 格式的一个用户友善的备选格式.
在相同的系统模块中进行数据的装载,测试集成.
内建与 OpenERP 以便开发复杂的 Python 测试.
方便非开发人员写功能测试.
下面是一个 XML 记录和 YAML 记录的比较.
首先,XML 记录使用当前的 XML 序列化格式: (参阅 previous section )
<!--
Resource: sale.order
-->
<record id="order" model="sale.order">
<field name="shop_id" ref="shop"/>
<field model="product.pricelist" name="pricelist_id" search="[]"/>
<field name="user_id" ref="base.user_root"/>
<field model="res.partner" name="partner_id" search="[]"/>
<field model="res.partner.address" name="partner_invoice_id search="[]"/>
<field model="res.partner.address" name="partner_shipping_id" search="[]"/>
<field model="res.partner.address" name="partner_order_id" search="[]"/>
</record>
<!--
Resource: sale.order.line
-->
<record id="line" model="sale.order.line">
<field name="order_id" ref="order"/>
<field name="name">New server config + material</field>
<field name="price_unit">123</field>
</record>
<record id="line1" model="sale.order.line">
<field name="order_id" ref="order"/>
<field name="name">[PC1] Basic PC</field>
<field name="price_unit">450</field>
</record>
YAML 记录
#<!--
# Resource: sale.order
# -->
-
!record {model: sale.order, id: sale_order_so4}:
amount_total: 3263.0
amount_untaxed: 3263.0
create_date: '2010-04-06 10:45:14'
date_order: '2010-04-06'
invoice_quantity: order
name: SO001
order_line:
- company_id: base.main_company
name: New server config + material
order_id: sale_order_so4
price_unit: 123.0
- company_id: base.main_company
name: '[PC1] Basic PC'
order_id: sale_order_so4
price_unit: 450.0
order_policy: manual
partner_id: base.res_partner_agrolait
partner_invoice_id: base.main_address
partner_order_id: base.main_address
partner_shipping_id: base.main_address
picking_policy: direct
pricelist_id: product.list0
shop_id: sale.shop
YAML Tags
data
Tag: data
必选属性: None
可选属性: noupdate : 0 | 1
子节点标签:
menuitem
record
workflow
delete
act_window
assert
报告
function
ir_set
样例:
-
!context
noupdate: 0
record
标签: record
必选属性:
- model
可选属性: noupdate : 0 | 1
子节点标签:
- field
可选属性:
id
forcreate
context
样例:
-
!record {model: sale.order, id: order}:
name: "[PC1] Basic PC"
amount_total: 3263.0
type_ids:
- project_tt_specification
- project_tt_development
- project_tt_testing
order_line:
- name: New server config
order_id: sale_order_so4
- name: '[PC1] Basic PC'
order_id: sale_order_so4
field
标签: field
必选属性:
- name
可选属性:
type
ref
eval
domain
search
model
use
子节点标签:
- text node
样例:
-price_unit: 450
-product_id: product.product_product_pc1
workflow
标签: workflow
必选属性:
model
action
可选属性:
uid
ref
子节点标签:
- value
样例:
-
!workflow {action: invoice_open, model: account.invoice}:
- eval: "obj(ref('test_order_1')).invoice_ids[0].id"
model: sale.order
- model: account.account
search: [('type', '=', 'cash')]
function
标签: function
必选属性:
model
name
可选属性:
id
eval
子节点标签:
value
function
样例:
-
!function {model: account.invoice, name: pay_and_reconcile}:
-eval: "[obj(ref('test_order_1')).id]"
model: sale.order
value
标签: value
必选属性: None
可选属性:
model
search
eval
子节点标签: None
样例:
-eval: "[obj(ref('test_order_1')).id]"
model: sale.order
menuitem
标签: menuitem
必选属性: None
可选属性:
id
name
parent
icon
action
string
sequence
groups
type
menu
子节点标签: None
样例:
-
!menuitem {sequence: 20, id: menu_administration,
name: Administration,
icon: terp-administration}
act_window
标签: act_window
必选属性:
id
name
res_model
可选属性:
domain
src_model
context
view
view_id
view_type
view_mode
multi
target
key2
groups
子节点标签: None
样例:
-
!act_window {target: new,
res_model: wizard.ir.model.menu.create,
id:act_menu_create, name: Create Menu}
报告
标签: report
必选属性:
string
model
name
可选属性:
id
报告
multi
menu
keyword
rml
sxw
xml
xsl
auto
header
attachment
attachment_use
groups
子节点标签: None
样例:
-
!report {string: Technical guide,
auto: False, model: ir.module.module,
id: ir_module_reference_print,
rml: base/module/report/ir_module_reference.rml,
name: ir.module.reference}
ir_set
标签: ir_set
必选属性: None
可选属性: None
子节点标签:
- field
样例:
-
!ir_set:
args: "[]"
name: account.seller.costs
value: tax_seller
python
标签: Python
必选属性:
- model
可选属性: None
子节点标签: None
样例:
Python code
delete
标签: delete
必选属性:
- model
可选属性:
id
search
子节点标签: None
样例:
-
!delete {model: ir.actions, search: "[(model,like,auction.)]"}
assert
标签: assert
必选属性:
- model
可选属性:
id
search
string
子节点标签:
- test
样例:
-
!assert {model: sale.order,
id: test_order, string: order in progress}:
- state == "progress"
test
标签: test
必选属性:
- expr
可选属性: None
子节点标签:
- text node
样例:
- picking_ids[0].state == "done"
url
标签: url
必选属性: -
可选属性: -
子节点标签: -
样例: -