[IMP] hr_holidays: workflow update
authorThibault Delavallée <tde@openerp.com>
Mon, 5 Aug 2013 11:30:23 +0000 (13:30 +0200)
committerThibault Delavallée <tde@openerp.com>
Mon, 5 Aug 2013 11:30:23 +0000 (13:30 +0200)
starts in confirm
from confirm, possible to get back to draft with reset signal, calling old set_to_draft, now
renamed holidays_reset, in the same workflow
from draft, possible to go to confirm

bzr revid: tde@openerp.com-20130805113023-1cs1s18dd5m4mi20

addons/hr_holidays/hr_holidays.py
addons/hr_holidays/hr_holidays_data.xml
addons/hr_holidays/hr_holidays_view.xml
addons/hr_holidays/hr_holidays_workflow.xml
addons/hr_holidays/test/test_hr_holiday.yml

index 6dc58bb..b75d253 100644 (file)
@@ -165,7 +165,7 @@ class hr_holidays(osv.osv):
     }
     _defaults = {
         'employee_id': _employee_get,
-        'state': 'draft',
+        'state': 'confirm',
         'type': 'remove',
         'user_id': lambda obj, cr, uid, context: uid,
         'holiday_type': 'employee'
@@ -306,18 +306,16 @@ class hr_holidays(osv.osv):
                 raise osv.except_osv(_('Warning!'),_('You cannot modify a leave request that has been approved. Contact a human resource manager.'))
         return super(hr_holidays, self).write(cr, uid, ids, vals, context=context)
 
-    def set_to_draft(self, cr, uid, ids, context=None):
+    def holidays_reset(self, cr, uid, ids, context=None):
         self.write(cr, uid, ids, {
             'state': 'draft',
             'manager_id': False,
             'manager_id2': False,
         })
-        self.delete_workflow(cr, uid, ids)
-        self.create_workflow(cr, uid, ids)
         to_unlink = []
         for record in self.browse(cr, uid, ids, context=context):
             for record2 in record.linked_request_ids:
-                self.set_to_draft(cr, uid, [record2.id], context=context)
+                self.holidays_reset(cr, uid, [record2.id], context=context)
                 to_unlink.append(record2.id)
         if to_unlink:
             self.unlink(cr, uid, to_unlink, context=context)
index 2b370f0..703fa74 100644 (file)
@@ -49,7 +49,7 @@
         <record id="mt_holidays_confirmed" model="mail.message.subtype">
             <field name="name">To Approve</field>
             <field name="res_model">hr.holidays</field>
-            <field name="description">Request created and waiting confirmation</field>
+            <field name="description">Request confirmed and waiting approval</field>
         </record>
         <record id="mt_holidays_approved" model="mail.message.subtype">
             <field name="name">Approved</field>
index 85bbcb9..9a91a21 100644 (file)
             <field name="arch" type="xml">
                 <form string="Leave Request" version="7.0">
                 <header>
+                    <button string="Confirm" name="confirm" states="draft" type="workflow" groups="base.group_hr_user" class="oe_highlight"/>
                     <button string="Approve" name="validate" states="confirm" type="workflow" groups="base.group_hr_user" class="oe_highlight"/>
                     <button string="Validate" name="second_validate" states="validate1" type="workflow" groups="base.group_hr_user" class="oe_highlight"/>
                     <button string="Refuse" name="refuse" states="confirm,validate1,validate" type="workflow" groups="base.group_hr_user"/>
-                    <button string="Reset to New" name="set_to_draft" states="refuse" type="object" groups="base.group_hr_user"/>
+                    <button string="Reset to Draft" name="reset" states="confirm" type="workflow" groups="base.group_hr_manager"/>
                     <field name="state" widget="statusbar" statusbar_visible="draft,confirm,validate" statusbar_colors='{"confirm":"blue","validate1":"blue","refuse":"red"}'/>
                 </header>
                 <sheet string="Leave Request">
                     <button string="Approve" name="validate" states="confirm" type="workflow" groups="base.group_hr_user" class="oe_highlight"/>
                     <button string="Validate" name="second_validate" states="validate1" type="workflow" groups="base.group_hr_user" class="oe_highlight"/>
                     <button string="Refuse" name="refuse" states="confirm,validate,validate1" type="workflow" groups="base.group_hr_user"/>
-                    <button string="Reset to New" name="set_to_draft" states="cancel,refuse" type="object" groups="base.group_hr_user"/>
+                    <button string="Reset to Draft" name="reset" states="confirm" type="workflow" groups="base.group_hr_manager"/>
                     <field name="state" widget="statusbar" statusbar_visible="draft,confirm,validate" statusbar_colors='{"confirm":"blue","validate1":"blue","refuse":"red"}'/>
                 </header>
                 <sheet>
                         <button string="Submit to Manager" name="confirm" states="draft" type="workflow" icon="gtk-yes"/>
                         <button string="Approve" name="validate" states="confirm" type="workflow" icon="gtk-apply"/>
                         <button string="Refuse" name="refuse" states="confirm,validate,draft" type="workflow" icon="gtk-no"/>
-                        <button string="Reset to New" name="set_to_draft" states="cancel" type="object" icon="gtk-convert"/>
+                        <button string="Reset to Draft" name="reset" states="confirm" type="workflow" groups="base.group_hr_manager"/>
                         <field name="state"/>
                     </header>
                     <group col="4">
index b729ea5..7d626c1 100644 (file)
@@ -2,15 +2,14 @@
 <openerp>
 <data>
 
-    <!-- Workflow definition 
-        1. draft->submitted (no signal)
+    <!-- Workflow definition
+        1. draft->submitted (confirm signal)
         2. submitted->accepted (validate signal) if not double_validation
-        2. submitted -> first_accepted (validate signal) if double_validation
+        2. submitted->first_accepted (validate signal) if double_validation
         2. submitted->refused (refuse signal)
         3. accepted->refused (refuse signal)
         4. first_accepted -> accepted (second_validate  signal)
         4. first_accepted -> refused (refuse signal)
-
     -->
 
     <record model="workflow" id="wkf_holidays">
 
     <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>
+        <field name="kind">function</field>
+        <field name="action">holidays_reset()</field>
     </record>
 
     <record model="workflow.activity" id="act_confirm"> <!-- submitted -->
         <field name="wkf_id" ref="wkf_holidays" />
         <field name="name">confirm</field>
+        <field name="flow_start">True</field>
         <field name="kind">function</field>
         <field name="action">holidays_confirm()</field>
         <field name="split_mode">OR</field>
         workflow transition
     -->
 
-    <record model="workflow.transition" id="holiday_draft2confirm"> <!-- 1. draft->submitted (no signal) -->
+    <record model="workflow.transition" id="holiday_draft2confirm"> <!-- 1. draft->submitted (confirm signal) -->
         <field name="act_from" ref="act_draft" />
         <field name="act_to" ref="act_confirm" />
+        <field name="signal">confirm</field>
+        <field name="condition">True</field>
+        <field name="group_id" ref="base.group_hr_user"/>
+    </record>
+
+    <record model="workflow.transition" id="holiday_confirm2draft"> <!-- 1. submitted->draft (reset signal) -->
+        <field name="act_from" ref="act_confirm" />
+        <field name="act_to" ref="act_draft" />
+        <field name="signal">reset</field>
+        <field name="condition">True</field>
+        <field name="group_id" ref="base.group_hr_user"/>
     </record>
 
     <record model="workflow.transition" id="holiday_confirm2validate"> <!-- 2. submitted->accepted (validate signal) if not double_validation-->
@@ -82,7 +94,6 @@
         <field name="group_id" ref="base.group_hr_user"/>
     </record>
 
-
     <record model="workflow.transition" id="holiday_confirm2refuse"> <!-- 2. submitted->refused (refuse signal) -->
         <field name="act_from" ref="act_confirm" />
         <field name="act_to" ref="act_refuse" />
index 2bb6030..7bedd33 100644 (file)
@@ -18,7 +18,7 @@
   I again set to draft and then confirm.
 -
   !python {model: hr.holidays}: |
-     self.set_to_draft(cr, uid, [ref('hr_holidays_employee1_cl')])
+     self.holidays_reset(cr, uid, [ref('hr_holidays_employee1_cl')])
      self.signal_confirm(cr, uid, [ref('hr_holidays_employee1_cl')])
 -
   I validate the holiday request by clicking on "To Approve" button.