Workflow functional concept on openerp7


Published on

Published in: Software, Technology, Business
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • Note:
    The first two arguments wkf_id and name are mandatory per each activity.
  • transition rules
    Workflow transition rules are rules that restrict some operations to certain groups. Those rules handle rights to go from one step to another one in the workflow. For example, you can limit the right to validate an invoice, i.e. going from a draft action to a validated action.
  • // how to defines groups and security next session ISA
  • Previously I add hol_job_id filled to hr. holidays refer to job id for employee
  • Workflow functional concept on openerp7

    1. 1. Workflow Functional Concept OPENERP7
    2. 2. 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
    3. 3. The workflow system in OpenERP  is a very powerful mechanism that can describe the evolution of documents (model) in time.
    4. 4. 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
    5. 5. 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.
    6. 6. 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.
    7. 7. Defining Workflow  Creating your Workflow XML file File Path : serveraddonsmodule 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
    8. 8. 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>
    9. 9. 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.
    10. 10.  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
    11. 11. 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.
    12. 12. 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
    13. 13. 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
    14. 14. Customized Holidays Request Approval mechanism  Based on job employement hierarchy :  How to add approval workflow OpenERP 7  How to control number of approvals based on employee job id department manager project manager project manager project manager developer1 developer2 Head Manager
    15. 15. Fit your Needs draft state='to submit' (draft) confirm holidays_confirm() state=‘confirm' (to approve) validate holidays_validate() state='approvedff' (validate)) Validate_second holidays_second_validate() state='head_man_apprv' (validate2) First_validate holidays_first_validate() state='dept_man_apprv' (validate1) Approve ValidateValidate2 Refuse Holidays_refuse() State=‘refuse’ EmpJobid=developer Split mode = or Join mode = Xor [default]
    16. 16.  “ 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>
    17. 17.  “ 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>
    18. 18.  “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>
    19. 19. 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 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',
    20. 20.  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>
    21. 21.  Previuosly, define function holidays_second_validate() in 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 =, 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})
    22. 22.  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>
    23. 23. 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>
    24. 24.  check_job_promag() is defined in object class in file and check must return false or true to satisfy expression def check_job_promag(self, cr, uid, ids, context=None):, 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
    25. 25.  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 file
    26. 26. Useful URLS regarding workflow   exception handling during workflow transitions:  How to hide a workflow button based on user in openerp 7? openerp-7  How to add approval workflow OpenERP 7