Skip to Content
Menu
This question has been flagged
1 Reply
2228 Views

Hi, I'm new to workflows.

I'm trying to understand how to program workflows but can't find a reliable source for practical examples online. (I've read the documentation and theory about workflows)

Can someone show me how to create a simple workflow so I could understand how it works?

Avatar
Discard
Best Answer

Hello Arjun 

1)first create seperate .xml file 

then put this code put your model name in the place of academic.session 

<?xml version="1.0"?>

<openerp>

<data>

<record model="workflow" id="wkf_academy">

<field name="name">academy.wkf</field>

<field name="osv">academic.session</field>

<field name="on_create">True</field>

</record>

<record model="workflow.activity" id="act_draft">

<field name="wkf_id" ref="wkf_academy" />

<field name="flow_start">True</field>

<field name="name">draft</field>

<field name="kind">function</field>

<field name="action">write({'state': 'draft'})</field>

</record>

<record model="workflow.activity" id="act_confirmed">

<field name="wkf_id" ref="wkf_academy" />

<field name="name">confirmed</field>

<field name="kind">function</field>

<field name="action">session_confirmed()</field>

</record>

<record model="workflow.activity" id="act_done">

<field name="wkf_id" ref="wkf_academy"/>

<field name="name">done</field>

<field name="kind">function</field>

<field name="action">session_done()</field>

</record>

<record model="workflow.transition" id="t1">

<field name="act_from" ref="act_draft"/>

<field name="act_to" ref="act_confirmed"/>

<field name="signal">session_confirmed</field>

</record>

<record model="workflow.transition" id="t2">

<field name="act_from" ref="act_confirmed"/>

<field name="act_to" ref="act_draft" />

<field name="signal">session_draft</field>

</record>

<record model="workflow.transition" id="t3">

<field name="act_from" ref="act_confirmed"/>

<field name="act_to" ref="act_done" />

<field name="signal">session_done</field>

</record>

<record model="workflow.transition" id="t4">

<field name="act_from" ref="act_done"/>

<field name="act_to" ref="act_draft" />

<field name="signal">session_draft</field>

<field name="flow_stop">True</field>

</record>

</data>

</openerp>


2) then put the following method inside  .py file in particular model that name you mention like i put my method inside academic.session model in .py file


def session_draft(self, cr, uid, ids,context=None):

self.write(cr, uid, ids, { 'state' : 'draft'},context=context)

return True

def session_confirmed(self, cr, uid, ids,context=None):

self.write(cr, uid, ids, { 'state' : 'confirmed'},context=context)

return True

def session_done(self, cr, uid, ids,context=None):

self.write(cr, uid, ids, { 'state' : 'done' },context=context)

return True


3)try to print workflow


Thank You

Avatar
Discard
Related Posts Replies Views Activity
1
Dec 24
49
1
Aug 23
1373
1
May 19
2229
0
May 19
2158
0
Dec 18
4283