我已经定义了状态操作,按钮和工作流程。它们运行得很好,问题是当我尝试添加可点击的状态栏时,每次我点击状态栏时,除了更改记录状态之外,它实际上不会做任何事情。
如何将状态栏链接到工作流程/操作?
model.py
def action_state_draft(self, cr, uid, ids):
self.write(cr, uid, ids, { 'state' : 'draft' })
return True
def action_state_confirmed(self, cr, uid, ids):
self.write(cr, uid, ids, { 'state' : 'confirmed' })
return True
def action_state_posted(self, cr, uid, ids):
self.write(cr, uid, ids, { 'state' : 'posted' })
return True
def action_state_cancelled(self, cr, uid, ids):
self.write(cr, uid, ids, { 'state' : 'cancelled' })
return True
def hello_world(self):
print "Hello World!"
def hello_world_second(self):
print "Hello World Second!"
model_view.xml
<header>
<button name="action_state_confirmed" string="Confirm" states="draft" />
<button name="action_state_posted" string="Post" states="confirmed" />
<button name="action_state_cancelled" string="Cancel" states="draft,confirmed,posted" />
<field name="state" widget="statusbar" clickable="True" statusbar_visible="draft,confirmed,posted,cancelled"/>
</header>
model_workflow.xml
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record id="ig_account_voucher_wkf" model="workflow">
<field name="name">ig.account.voucher.wkf</field>
<field name="osv">ig.account.voucher</field>
<field name="on_create">True</field>
</record>
<record id="act_draft" model="workflow.activity">
<field name="wkf_id" ref="ig_account_voucher_wkf"/>
<field name="name">draft</field>
<field name="flow_start">True</field>
</record>
<record id="act_confirmed" model="workflow.activity">
<field name="wkf_id" ref="ig_account_voucher_wkf"/>
<field name="name">confirmed</field>
<field name="action">
write({'state':'confirmed'})
hello_world()
hello_world_second()
</field>
<field name="kind">function</field>
</record>
<record id="act_posted" model="workflow.activity">
<field name="wkf_id" ref="ig_account_voucher_wkf"/>
<field name="name">posted</field>
<field name="action">write({'state':'posted'})</field>
<field name="kind">function</field>
</record>
<record id="act_posted" model="workflow.activity">
<field name="wkf_id" ref="ig_account_voucher_wkf"/>
<field name="name">cancelled</field>
<field name="action">write({'state':'cancelled'})</field>
<field name="kind">function</field>
<field name="flow_stop">True</field>
</record>
<record id="transition_draft_confirmed" model="workflow.transition">
<field name="act_from" ref="act_draft"/>
<field name="act_to" ref="act_confirmed"/>
<field name="condition">True</field>
<field name="signal">action_state_confirmed</field>
</record>
<record id="transition_confirmed_posted" model="workflow.transition">
<field name="act_from" ref="act_confirmed"/>
<field name="act_to" ref="act_posted"/>
<field name="condition">True</field>
<field name="signal">action_state_posted</field>
</record>
<record id="transition_confirmed_cancelled" model="workflow.transition">
<field name="act_from" ref="act_confirmed"/>
<field name="act_to" ref="act_posted"/>
<field name="condition">True</field>
<field name="signal">action_state_cancelled</field>
</record>
</data>
</openerp>
另一个相关的小问题:为什么我们需要工作流而不仅仅是使用按钮和操作?
答案 0 :(得分:2)
在您的代码中,当您在工作流操作中传递multiple方法时,您在工作流操作上缺少逗号。
请先做正确的
<record id="act_confirmed" model="workflow.activity">
<field name="wkf_id" ref="ig_account_voucher_wkf"/>
<field name="name">confirmed</field>
<field name="action">
write({'state':'confirmed'}),
hello_world(),
hello_world_second()
</field>
<field name="kind">function</field>
</record>
你的问题的另一个答案是:
为什么需要工作流而不是按钮?
主要目标是将工作流程定义为业务流程。
另一个目标是:
文件演变的描述
如果满足某些条件,则自动触发操作
管理公司角色和验证步骤
管理不同对象/模块之间的交互
用于文档流可视化的图形工具
我希望这对你有用..:)