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 )

  1. <!--
  2. Resource: sale.order
  3. -->
  4. <record id="order" model="sale.order">
  5. <field name="shop_id" ref="shop"/>
  6. <field model="product.pricelist" name="pricelist_id" search="[]"/>
  7. <field name="user_id" ref="base.user_root"/>
  8. <field model="res.partner" name="partner_id" search="[]"/>
  9. <field model="res.partner.address" name="partner_invoice_id search="[]"/>
  10. <field model="res.partner.address" name="partner_shipping_id" search="[]"/>
  11. <field model="res.partner.address" name="partner_order_id" search="[]"/>
  12. </record>
  13. <!--
  14. Resource: sale.order.line
  15. -->
  16. <record id="line" model="sale.order.line">
  17. <field name="order_id" ref="order"/>
  18. <field name="name">New server config + material</field>
  19. <field name="price_unit">123</field>
  20. </record>
  21. <record id="line1" model="sale.order.line">
  22. <field name="order_id" ref="order"/>
  23. <field name="name">[PC1] Basic PC</field>
  24. <field name="price_unit">450</field>
  25. </record>

YAML 记录

  1. #<!--
  2. # Resource: sale.order
  3. # -->
  4. -
  5. !record {model: sale.order, id: sale_order_so4}:
  6. amount_total: 3263.0
  7. amount_untaxed: 3263.0
  8. create_date: '2010-04-06 10:45:14'
  9. date_order: '2010-04-06'
  10. invoice_quantity: order
  11. name: SO001
  12. order_line:
  13. - company_id: base.main_company
  14. name: New server config + material
  15. order_id: sale_order_so4
  16. price_unit: 123.0
  17. - company_id: base.main_company
  18. name: '[PC1] Basic PC'
  19. order_id: sale_order_so4
  20. price_unit: 450.0
  21. order_policy: manual
  22. partner_id: base.res_partner_agrolait
  23. partner_invoice_id: base.main_address
  24. partner_order_id: base.main_address
  25. partner_shipping_id: base.main_address
  26. picking_policy: direct
  27. pricelist_id: product.list0
  28. shop_id: sale.shop

YAML Tags

data

  • Tag: data

  • 必选属性: None

  • 可选属性: noupdate : 0 | 1

  • 子节点标签:

    • menuitem

    • record

    • workflow

    • delete

    • act_window

    • assert

    • 报告

    • function

    • ir_set

  • 样例:

    1. -
    2. !context
    3. noupdate: 0

record

  • 标签: record

  • 必选属性:

    • model
  • 可选属性: noupdate : 0 | 1

  • 子节点标签:

    • field
  • 可选属性:

    • id

    • forcreate

    • context

  • 样例:

    1. -
    2. !record {model: sale.order, id: order}:
    3. name: "[PC1] Basic PC"
    4. amount_total: 3263.0
    5. type_ids:
    6. - project_tt_specification
    7. - project_tt_development
    8. - project_tt_testing
    9. order_line:
    10. - name: New server config
    11. order_id: sale_order_so4
    12. - name: '[PC1] Basic PC'
    13. order_id: sale_order_so4

field

  • 标签: field

  • 必选属性:

    • name
  • 可选属性:

    • type

    • ref

    • eval

    • domain

    • search

    • model

    • use

  • 子节点标签:

    • text node
  • 样例:

    1. -price_unit: 450
    2. -product_id: product.product_product_pc1

workflow

  • 标签: workflow

  • 必选属性:

    • model

    • action

  • 可选属性:

    • uid

    • ref

  • 子节点标签:

    • value
  • 样例:

    1. -
    2. !workflow {action: invoice_open, model: account.invoice}:
    3. - eval: "obj(ref('test_order_1')).invoice_ids[0].id"
    4. model: sale.order
    5. - model: account.account
    6. search: [('type', '=', 'cash')]

function

  • 标签: function

  • 必选属性:

    • model

    • name

  • 可选属性:

    • id

    • eval

  • 子节点标签:

    • value

    • function

  • 样例:

    1. -
    2. !function {model: account.invoice, name: pay_and_reconcile}:
    3. -eval: "[obj(ref('test_order_1')).id]"
    4. model: sale.order

value

  • 标签: value

  • 必选属性: None

  • 可选属性:

    • model

    • search

    • eval

  • 子节点标签: None

  • 样例:

    1. -eval: "[obj(ref('test_order_1')).id]"
    2. model: sale.order

menuitem

  • 标签: menuitem

  • 必选属性: None

  • 可选属性:

    • id

    • name

    • parent

    • icon

    • action

    • string

    • sequence

    • groups

    • type

    • menu

  • 子节点标签: None

  • 样例:

    1. -
    2. !menuitem {sequence: 20, id: menu_administration,
    3. name: Administration,
    4. 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

  • 样例:

    1. -
    2. !act_window {target: new,
    3. res_model: wizard.ir.model.menu.create,
    4. 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

  • 样例:

    1. -
    2. !report {string: Technical guide,
    3. auto: False, model: ir.module.module,
    4. id: ir_module_reference_print,
    5. rml: base/module/report/ir_module_reference.rml,
    6. name: ir.module.reference}

ir_set

  • 标签: ir_set

  • 必选属性: None

  • 可选属性: None

  • 子节点标签:

    • field
  • 样例:

    1. -
    2. !ir_set:
    3. args: "[]"
    4. name: account.seller.costs
    5. value: tax_seller

python

  • 标签: Python

  • 必选属性:

    • model
  • 可选属性: None

  • 子节点标签: None

  • 样例:

    1. Python code

delete

  • 标签: delete

  • 必选属性:

    • model
  • 可选属性:

    • id

    • search

  • 子节点标签: None

  • 样例:

    1. -
    2. !delete {model: ir.actions, search: "[(model,like,auction.)]"}

assert

  • 标签: assert

  • 必选属性:

    • model
  • 可选属性:

    • id

    • search

    • string

  • 子节点标签:

    • test
  • 样例:

    1. -
    2. !assert {model: sale.order,
    3. id: test_order, string: order in progress}:
    4. - state == "progress"

test

  • 标签: test

  • 必选属性:

    • expr
  • 可选属性: None

  • 子节点标签:

    • text node
  • 样例:

    1. - picking_ids[0].state == "done"

url

  • 标签: url

  • 必选属性: -

  • 可选属性: -

  • 子节点标签: -

  • 样例: -