Odoo⼯作流介绍及代码⽰例
本⽂主要介绍了Odoo⼯作流的开发⽅法并提供代码⽰例
新版本的odoo开始减少workflow的使⽤,推荐使⽤workflow-ish的⽅式来处理⼯作流过程。从odoo11起已经完全移除了⼯作流引擎的相关代码。
春天的故事在odoo中,workflow是关联到某个model的对象,⽤来动态的管理记录的⽣命周期.
创建模拟的workflow-ish
状态的改变流程如下
Draft -> Confirmed
Confirmed -> Draft
Confirmed -> Done
Done -> Draft
添加代码的步骤
1 添加state字段
2 添加state状态转移⽅法,并绑定⽅法到form view上的按钮
3 添加相关按钮到form view
odoogoedu/models.py
state = fields.Selection([('draft', "Draft"),('confirmed', "Confirmed"),('done', "Done")], default='draft')
@api.multi
def action_draft(lf):
lf.state = 'draft'
@api.multi
def action_confirm(lf):
lf.state = 'confirmed'
@api.multi
def action_done(lf):
lf.state = 'done'
odoogoedu/l
<odoo>
<data>
<record model="workflow" id="wkf_ssion">
<field name="name">OpenAcademy ssions workflow</field>
<field name="osv">openacademy.ssion</field>
<field name="on_create">True</field>
</record>
<record model="workflow.activity" id="draft">
<field name="name">Draft</field>
<field name="wkf_id" ref="wkf_ssion"/>
<field name="flow_start" eval="True"/>
<field name="kind">function</field>
<field name="action">action_draft()</field>
</record>
<record model="workflow.activity" id="confirmed">
<field name="name">Confirmed</field>
<field name="wkf_id" ref="wkf_ssion"/>
<field name="kind">function</field>
<field name="action">action_confirm()</field>
</record>
<record model="workflow.activity" id="done">
<field name="name">Done</field>
<field name="wkf_id" ref="wkf_ssion"/>
<field name="kind">function</field>
<field name="action">action_done()</field>
</record>
<record model="ansition" id="ssion_draft_to_confirmed">
<field name="act_from" ref="draft"/>
<field name="act_to" ref="confirmed"/>
一年级数学下
<field name="signal">confirm</field>
</record>
<record model="ansition" id="ssion_confirmed_to_draft">
<field name="act_from" ref="confirmed"/>
<field name="act_to" ref="draft"/>
<field name="signal">draft</field>
</record>
<record model="ansition" id="ssion_done_to_draft">
<field name="act_from" ref="done"/>
<field name="act_to" ref="draft"/>
<field name="signal">draft</field>
</record>
<record model="ansition" id="ssion_confirmed_to_done">
<field name="act_from" ref="confirmed"/>
<field name="act_to" ref="done"/>
<field name="signal">done</field>
</record>
</data>
</odoo>
使⽤odoo workflow管理状态(废弃)
以上没有使⽤odoo workflow对象。odoo中的workflow使⽤xml定义,在workflows中有activities (nodes or actions) ,transitions (conditions)和workitems。
Activities定义了⼀些由odoo服务器所要完成的任务,如改变记录状态,发送邮件
Transitions定义了如何从⼀个Activity到另外Activity
注意
workflow是在关联的model对象创建时⼀起创建并运⾏的。
替换ssion workflow
替换刚才临时的(ad-hoc)ssion workflow到⼀个真正的workflow对象. 并且改变button的绑定⽅法到workflow的transition⽅法
去除state的default值,交由workflow管理。
openacademy/__openerp__.py
'l',
'l',
'l',
'views/l',
],
# only loaded in demonstration mode
'demo': [
然后我成为了猎人openacademy/models.py
('draft', "Draft"),
('confirmed', "Confirmed"),
('done', "Done"),
])
横贯江面@api.multi
def action_draft(lf):
openacademy/l
<odoo>
<data>
<record model="workflow" id="wkf_ssion">
<field name="name">OpenAcademy ssions workflow</field>
<field name="osv">openacademy.ssion</field>
<field name="on_create">True</field>
</record>
<record model="workflow.activity" id="draft">
<field name="name">Draft</field>
<field name="wkf_id" ref="wkf_ssion"/>
<field name="flow_start" eval="True"/>
<field name="kind">function</field>
<field name="action">action_draft()</field>
</record>
<record model="workflow.activity" id="confirmed">
<field name="name">Confirmed</field>
ppt模板替换
<field name="wkf_id" ref="wkf_ssion"/>
<field name="kind">function</field>
<field name="action">action_confirm()</field>
</record>
<record model="workflow.activity" id="done">
<field name="name">Done</field>
微信好看的图片头像<field name="wkf_id" ref="wkf_ssion"/>
<field name="kind">function</field>
<field name="action">action_done()</field>
</record>
<record model="ansition" id="ssion_draft_to_confirmed">
<field name="act_from" ref="draft"/>
<field name="act_to" ref="confirmed"/>
<field name="signal">confirm</field>
</record>
<record model="ansition" id="ssion_confirmed_to_draft">
<field name="act_from" ref="confirmed"/>
常香玉捐飞机
<field name="act_to" ref="draft"/>
<field name="signal">draft</field>
</record>
<record model="ansition" id="ssion_done_to_draft">
<field name="act_from" ref="done"/>
<field name="act_to" ref="draft"/>
<field name="signal">draft</field>
</record>
<record model="ansition" id="ssion_confirmed_to_done">
<field name="act_from" ref="confirmed"/>
<field name="act_to" ref="done"/>
<field name="signal">done</field>
</record>
</data>
</odoo>
杂然相许的许创建的workflow可以在Settings ‣ Technical ‣ Workflows ‣ Instances⾥查看
button name="transition signal 名称"
⾃动执⾏transition
根据条件⾃动执⾏transition,当课时的上课⼈数⼤于50%的时候⾃动从草稿到确认状态。openacademy/views/l
done
taken_ats > 50
服务器动作
服务器动作 rver action
可以在xml⾥定义的python⽅法⽤来替换model的⽅法
openacademy/views/l