Workflow functional concept on openerp7

26
Workflow Functional Concept OPENERP7

Transcript of Workflow functional concept on openerp7

Page 1: Workflow functional concept on openerp7

Workflow Functional ConceptOPENERP7

Page 2: Workflow functional concept on openerp7

Contents

What is workflow

Workflow Goals

Benefits of applying Workflow

Defining Workflow

Example holiday Request approval

How to modify the workflow

How to add approval workflow OpenERP 7

How to hide a workflow button based on user in OpenERP7

Page 3: Workflow functional concept on openerp7

The workflow system in OpenERP

is a very powerful mechanism that can describe the evolution of documents (model) in time.

Page 4: Workflow functional concept on openerp7

Goals of Workflow Mechanism

description of document evolution in time

automatic trigger of actions if some conditions are met

management of company roles and validation steps

management of interactions between the different objects/modules

graphical tool for visualization of document flows

Page 5: Workflow functional concept on openerp7

Advantage of Workflow in OpenERP7

Workflows are entirely customizable, they can be adapted to the flows and trade logic of almost any company. The workflow system makes OpenERP very flexible and allows it to easily support changing needs without having to program new functionality.

Page 6: Workflow functional concept on openerp7

Defining Workflow

Define the States of your object

The first step is to define the States your object can be in. We do this by adding a 'state' field to our object, in the _columns collection

Example Hr.Holidays Model:

'state': fields.selection([('draft', 'To Submit'), ('cancel', 'Cancelled'),('confirm', 'To Approve'), ('refuse', 'Refused'), ('validate1', 'dept_mang_apprv'), ('validate2', 'head_mang_apprv'), ('validate', 'Approvedff')], 'Status', readonly=True, track_visibility='onchange',

Define the State-change Handling Methods

Add additional methods to your object. These will be called by our workflow buttons.

Page 7: Workflow functional concept on openerp7

Defining Workflow

Creating your Workflow XML file

File Path : server\addons\module folder\[module_name]_workflow.xml

Workflow Header Record

 

Activity Record

Do action

Activity Record

Do action

 

Transition Record: condition must executed to transfer

These define the actions that must be executed when the workflow reaches a particular state.

These define the possible transitions between workflow states

Page 8: Workflow functional concept on openerp7

Activity: These define the actions that must be executed when the workflow reaches a particular state.

“ Draft Activity “

<record model="workflow.activity" id="act_draft"> <!-- draft -->

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

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

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

</record>

Page 9: Workflow functional concept on openerp7

Activity Fields

flow_start

Indicates if the node is a start node. When a new instance of a workflow is created, a workitem is activated for each activity marked as a flow_start.

flow_stop

Indicates if the node is an ending node. When all the active workitems for a given instance come in the node marked by flow_stop, the workflow is finished.

Page 10: Workflow functional concept on openerp7

kind

Possible values:

dummy: Do nothing (default).

function: Execute the function selected by an action field.

subflow: Execute a sub-workflow SUBFLOW_ID. The action method must return the ID of the concerned resource by the subflow. If the action returns False, the workitem disappears.

action

The action indicates the method to execute when a workitem comes into this activity.

The method must be defined in an object which belongs to this workflow

Page 11: Workflow functional concept on openerp7

Transition: are the conditions which need to be satisfied to move from one activity to the

next.

The conditions are signals:

button pressed in the interface[view.xml file for module ] # create button of type workflow

signals are evaluated before the expression. If a signal is false, the expression will not be evaluated.

Page 12: Workflow functional concept on openerp7

Transition Fields

act_from Source activity. When this activity is over, the condition is tested to determine if we can start the ACT_TO activity.

act_to The destination activity.

condition Expression to be satisfied if we want the transition done.

signal When the operation of transition comes from a button pressed in the client form, signal tests the name of the pressed button.If signal is NULL, no button is necessary to validate this transition.

Group id user to do this action must have privildge rules on this group , if not will displayed permission denied

Page 13: Workflow functional concept on openerp7

Holidays Request Approval mechanism

Manage employee leaves from the top menu "Human Resources". Employees can create leave requests that are validated by their manager and/or HR officers.

note and/or based on chosen holiday type on holiday request

Once validated, they are visible in the employee's calendar.

HR officers can define leave types and allocate leaves to employees and employee categories

Page 15: Workflow functional concept on openerp7

Fit your Needsdraft

state='to submit'(draft)

confirmholidays_confirm()

state=‘confirm'(to approve)

validateholidays_validate()state='approvedff'

(validate))

Validate_secondholidays_second_validate()state='head_man_apprv'

(validate2)

First_validateholidays_first_validate()state='dept_man_apprv'

(validate1)

Approve

ValidateValidate2

RefuseHolidays_refuse(

)State=‘refuse’

EmpJobid=developer

Split mode = or

Join mode = Xor [default]

Page 16: Workflow functional concept on openerp7

“ Draft Activity “

<record model="workflow.activity" id="act_draft"> <!-- draft -->

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

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

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

</record>

Page 17: Workflow functional concept on openerp7

“ Frist Validate activity ”

<record model="workflow.activity" id="act_validate1"> <!-- first_accepted --> <field name="wkf_id" ref="wkf_holidays" />

<field name="name">first_validate</field>

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

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

<field name="split_mode">OR</field>

</record>

Page 18: Workflow functional concept on openerp7

“Validate Activity ”

<record model="workflow.activity" id="act_validate"> <!-- accepted -->

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

<field name="name">validate</field>

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

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

</record>

Page 19: Workflow functional concept on openerp7

Steps to modify hr.wkf.holidays

Follow needs flow diagrams :

To add another approval state :

Modify state field in _column partion in class hr.holidays in hr_holidays.py to be:

'state': fields.selection([('draft', 'To Submit'), ('cancel', 'Cancelled'),('confirm', 'To Approve'), ('refuse', 'Refused'), ('validate1', 'to dept_mang_apprv'), ('validate2', 'to head_mang_apprv'), ('validate', 'Approvedff')],'Status', readonly=True, track_visibility='onchange',

Page 20: Workflow functional concept on openerp7

Add activity node In xml file for this state

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

<!-- second_accepted -->

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

<field name="name">validate_second</field>

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

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

<field name="split_mode">OR</field>

</record>

Page 21: Workflow functional concept on openerp7

Previuosly, define function holidays_second_validate() in hr_holidays.py file

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

self.check_holidays(cr, uid, ids, context=context)

obj_emp = self.pool.get('hr.employee')

ids2 = obj_emp.search(cr, uid, [('user_id', '=', uid)])

manager = ids2 and ids2[0] or False

self.holidays_first_validate_notificate(cr, uid, ids, context=context)

return self.write(cr, uid, ids, {'state':'validate2', 'manager_id': manager})

Page 22: Workflow functional concept on openerp7

this node will be active based on transition defined:

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

<!-- 4. first_accepted -> second accepted (second_validate signal) --> <field name="act_from" ref="act_validate1" />

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

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

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

<field name="group_id" ref="base.group_hr_user"/> </record>

Page 23: Workflow functional concept on openerp7

OR this node will be active based on transition defined:

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

<!-- 2. submitted->dept_man_approval directlyif jobid==1[project manager]) -->

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

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

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

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

<!--field name="condition">check_job_promag()</field-->

<field name="group_id" ref="base.group_hr_user"/>

</record>

Page 24: Workflow functional concept on openerp7

check_job_promag() is defined in object class in hr_holidays.py file and check must return false or true to satisfy expression

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

#hol_ids=self.search(cr, uid,[('hol_job_id','=',1)])

for record in self.browse(cr, uid, hol_ids, context):

if record.hol_job_id==1:

return True

else:

return False

Page 25: Workflow functional concept on openerp7

Buttons of type workflow is defined in hr_holidays_view.xml

<button string="Validate" name="second_validate" states="validate1" type="workflow" class="oe_highlight"/>

To apply this workflow file on state change of module , must be called in descriptor of module __openerp__.py file

Page 26: Workflow functional concept on openerp7

Useful URLS regarding workflow

https://doc.openerp.com/v6.1/developer/07_workflows.html/

exception handling during workflow transitions:

https://answers.launchpad.net/openobject-server/+question/103295

How to hide a workflow button based on user in openerp 7?

http://stackoverflow.com/questions/23568345/how-to-hide-a-workflow-button-based-on-user-in-openerp-7

 

How to add approval workflow OpenERP 7

http://stackoverflow.com/questions/16393415/how-to-add-approval-workflow-openerp-7?rq=1