[IMP] hr_holidays: clean workflow of hr_holidays
bzr revid: hmo@tinyerp.com-20120814122050-8pax7b6e06urcyvv
This commit is contained in:
parent
81a44cef8e
commit
0c20817c37
|
@ -124,8 +124,6 @@ class hr_holidays(osv.osv):
|
|||
'date_to': fields.datetime('End Date', readonly=True, states={'draft':[('readonly',False)], 'confirm':[('readonly',False)]}),
|
||||
'holiday_status_id': fields.many2one("hr.holidays.status", "Leave Type", required=True,readonly=True, states={'draft':[('readonly',False)], 'confirm':[('readonly',False)]}),
|
||||
'employee_id': fields.many2one('hr.employee', "Employee", select=True, invisible=False, readonly=True, states={'draft':[('readonly',False)], 'confirm':[('readonly',False)]}, help='Leave Manager can let this field empty if this leave request/allocation is for every employee'),
|
||||
#'manager_id': fields.many2one('hr.employee', 'Leave Manager', invisible=False, readonly=True, help='This area is automatically filled by the user who validate the leave'),
|
||||
#'notes': fields.text('Notes',readonly=True, states={'draft':[('readonly',False)]}),
|
||||
'manager_id': fields.many2one('hr.employee', 'First Approval', invisible=False, readonly=True, help='This area is automatically filled by the user who validate the leave'),
|
||||
'notes': fields.text('Reasons',readonly=True, states={'draft':[('readonly',False)], 'confirm':[('readonly',False)]}),
|
||||
'number_of_days_temp': fields.float('Number of Days', readonly=True, states={'draft':[('readonly',False)], 'confirm':[('readonly',False)]}),
|
||||
|
@ -135,8 +133,8 @@ class hr_holidays(osv.osv):
|
|||
'parent_id': fields.many2one('hr.holidays', 'Parent'),
|
||||
'linked_request_ids': fields.one2many('hr.holidays', 'parent_id', 'Linked Requests',),
|
||||
'department_id':fields.related('employee_id', 'department_id', string='Department', type='many2one', relation='hr.department', readonly=True, store=True),
|
||||
'category_id': fields.many2one('hr.employee.category', "Category", help='Category of Employee'),
|
||||
'holiday_type': fields.selection([('employee','By Employee'),('category','By Employee Category')], 'Allocation Type', help='By Employee: Allocation/Request for individual Employee, By Employee Category: Allocation/Request for group of employees in category', required=True),
|
||||
'category_id': fields.many2one('hr.employee.category', "Category", help='Category of Employee', readonly=True, states={'draft':[('readonly',False)], 'confirm':[('readonly',False)]}),
|
||||
'holiday_type': fields.selection([('employee','By Employee'),('category','By Employee Category')], 'Allocation Mode', readonly=True, states={'draft':[('readonly',False)], 'confirm':[('readonly',False)]}, help='By Employee: Allocation/Request for individual Employee, By Employee Category: Allocation/Request for group of employees in category', required=True),
|
||||
'manager_id2': fields.many2one('hr.employee', 'Second Approval', readonly=True, help='This area is automaticly filled by the user who validate the leave with second level (If Leave type need second validation)'),
|
||||
'double_validation': fields.related('holiday_status_id', 'double_validation', type='boolean', relation='hr.holidays.status', string='Apply Double Validation'),
|
||||
}
|
||||
|
@ -244,25 +242,26 @@ class hr_holidays(osv.osv):
|
|||
self.unlink(cr, uid, to_unlink, context=context)
|
||||
return True
|
||||
|
||||
def holidays_validate(self, cr, uid, ids, context=None):
|
||||
def holidays_first_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_validate_notificate(cr, uid, ids, context=context)
|
||||
self.holidays_first_validate_notificate(cr, uid, ids, context=context)
|
||||
return self.write(cr, uid, ids, {'state':'validate1', 'manager_id': manager})
|
||||
|
||||
def holidays_validate2(self, cr, uid, ids, context=None):
|
||||
def holidays_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.write(cr, uid, ids, {'state':'validate'})
|
||||
data_holiday = self.browse(cr, uid, ids)
|
||||
holiday_ids = []
|
||||
for record in data_holiday:
|
||||
if record.holiday_status_id.double_validation:
|
||||
holiday_ids.append(record.id)
|
||||
if record.double_validation:
|
||||
self.write(cr, uid, [record.id], {'manager_id2': manager})
|
||||
else:
|
||||
self.write(cr, uid, [record.id], {'manager_id': manager})
|
||||
if record.holiday_type == 'employee' and record.type == 'remove':
|
||||
meeting_obj = self.pool.get('crm.meeting')
|
||||
meeting_vals = {
|
||||
|
@ -301,9 +300,7 @@ class hr_holidays(osv.osv):
|
|||
wf_service.trg_validate(uid, 'hr.holidays', leave_id, 'confirm', cr)
|
||||
wf_service.trg_validate(uid, 'hr.holidays', leave_id, 'validate', cr)
|
||||
wf_service.trg_validate(uid, 'hr.holidays', leave_id, 'second_validate', cr)
|
||||
if holiday_ids:
|
||||
self.holidays_valid2_notificate(cr, uid, holiday_ids, context=context)
|
||||
self.write(cr, uid, holiday_ids, {'manager_id2': manager})
|
||||
self.holidays_validate_notificate(cr, uid, ids, context=context)
|
||||
return True
|
||||
|
||||
def holidays_confirm(self, cr, uid, ids, context=None):
|
||||
|
@ -311,15 +308,16 @@ class hr_holidays(osv.osv):
|
|||
self.holidays_confirm_notificate(cr, uid, ids, context=context)
|
||||
return self.write(cr, uid, ids, {'state':'confirm'})
|
||||
|
||||
def holidays_refuse(self, cr, uid, ids, approval, context=None):
|
||||
def holidays_refuse(self, cr, uid, ids, context=None):
|
||||
obj_emp = self.pool.get('hr.employee')
|
||||
ids2 = obj_emp.search(cr, uid, [('user_id', '=', uid)])
|
||||
manager = ids2 and ids2[0] or False
|
||||
if approval == 'first_approval':
|
||||
self.write(cr, uid, ids, {'state': 'refuse', 'manager_id': manager})
|
||||
else:
|
||||
self.write(cr, uid, ids, {'state': 'refuse', 'manager_id2': manager})
|
||||
self.holidays_refuse_notificate(cr, uid, ids, approval, context=context)
|
||||
for holiday in self.browse(cr, uid, ids, context=context):
|
||||
if holiday.state == 'validate1':
|
||||
self.write(cr, uid, [holiday.id], {'state': 'refuse', 'manager_id': manager})
|
||||
else:
|
||||
self.write(cr, uid, [holiday.id], {'state': 'refuse', 'manager_id2': manager})
|
||||
self.holidays_refuse_notificate(cr, uid, ids, context=context)
|
||||
self.holidays_cancel(cr, uid, ids, context=context)
|
||||
return True
|
||||
|
||||
|
@ -333,7 +331,7 @@ class hr_holidays(osv.osv):
|
|||
# If a category that created several holidays, cancel all related
|
||||
wf_service = netsvc.LocalService("workflow")
|
||||
for request in record.linked_request_ids or []:
|
||||
wf_service.trg_validate(uid, 'hr.holidays', request.id, 'cancel', cr)
|
||||
wf_service.trg_validate(uid, 'hr.holidays', request.id, 'refuse', cr)
|
||||
|
||||
self._remove_resource_leave(cr, uid, ids, context=context)
|
||||
return True
|
||||
|
@ -355,7 +353,7 @@ class hr_holidays(osv.osv):
|
|||
def get_needaction_user_ids(self, cr, uid, ids, context=None):
|
||||
result = super(hr_holidays, self).get_needaction_user_ids(cr, uid, ids, context=context)
|
||||
for obj in self.browse(cr, uid, ids, context=context):
|
||||
if obj.state == 'confirm' and obj.employee_id.parent_id:
|
||||
if obj.state == 'confirm' and obj.holiday_type == 'employee' and obj.employee_id.parent_id:
|
||||
result[obj.id] = [obj.employee_id.parent_id.user_id.id]
|
||||
elif obj.state == 'validate1':
|
||||
# get group_hr_manager: everyone will be warned of second validation
|
||||
|
@ -389,24 +387,25 @@ class hr_holidays(osv.osv):
|
|||
_("The %s request has been <b>submitted</b> and is waiting for validation by the manager.")
|
||||
% ('leave' if obj.type == 'remove' else 'allocation',), type='notification')
|
||||
|
||||
def holidays_first_validate_notificate(self, cr, uid, ids, context=None):
|
||||
for obj in self.browse(cr, uid, ids):
|
||||
self.message_append_note(cr, uid, [obj.id], _('System notification'),
|
||||
_("The %s request has been <b>approved</b>. A second validation is necessary and is now pending.")
|
||||
% ('leave' if obj.type == 'remove' else 'allocation',), type='notification', context=context)
|
||||
|
||||
def holidays_validate_notificate(self, cr, uid, ids, context=None):
|
||||
for obj in self.browse(cr, uid, ids):
|
||||
if obj.holiday_status_id.double_validation:
|
||||
if obj.double_validation:
|
||||
self.message_append_note(cr, uid, [obj.id], _('System notification'),
|
||||
_("The %s request has been <b>approved</b>. A second validation is necessary and is now pending.")
|
||||
_("The %s request has been <b>double validated</b>. The validation process is now over.")
|
||||
% ('leave' if obj.type == 'remove' else 'allocation',), type='notification', context=context)
|
||||
else:
|
||||
self.message_append_note(cr, uid, [obj.id], _('System notification'),
|
||||
_("The %s request has been <b>approved</b>. The validation process is now over.")
|
||||
% ('leave' if obj.type == 'remove' else 'allocation',), type='notification', context=context)
|
||||
|
||||
def holidays_valid2_notificate(self, cr, uid, ids, context=None):
|
||||
for obj in self.browse(cr, uid, ids):
|
||||
self.message_append_note(cr, uid, [obj.id], _('System notification'),
|
||||
_("The %s request has been <b>double validated</b>. The validation process is now over.")
|
||||
% ('leave' if obj.type == 'remove' else 'allocation',), type='notification', context=context)
|
||||
|
||||
def holidays_refuse_notificate(self, cr, uid, ids, approval, context=None):
|
||||
def holidays_refuse_notificate(self, cr, uid, ids, context=None):
|
||||
for obj in self.browse(cr, uid, ids):
|
||||
self.message_append_note(cr, uid, [obj.id], _('System notification'),
|
||||
_("The %s request has been <b>refused</b>. The validation process is now over.")
|
||||
|
|
|
@ -96,7 +96,7 @@
|
|||
<header>
|
||||
<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" type="workflow" groups="base.group_hr_user,base.group_hr_manager" class="oe_highlight"/>
|
||||
<button string="Refuse" name="refuse" states="confirm,validate1,validate" type="workflow" groups="base.group_hr_user" class="oe_highlight"/>
|
||||
<button string="Reset to New" name="set_to_draft" states="refuse,validate" type="object" groups="base.group_hr_user" />
|
||||
<field name="state" widget="statusbar" statusbar_visible="draft,confirm,validate" statusbar_colors='{"confirm":"blue","validate1":"blue","refuse":"red"}'/>
|
||||
</header>
|
||||
|
@ -123,16 +123,6 @@
|
|||
<field name="department_id" attrs="{'readonly':[('holiday_type','=','category')]}" groups="base.group_hr_user"/>
|
||||
</group>
|
||||
</group>
|
||||
<group colspan="4">
|
||||
<group>
|
||||
<group>
|
||||
<field name="double_validation" invisible="1"/>
|
||||
</group>
|
||||
<group>
|
||||
<field name="manager_id2" attrs="{'invisible':[('double_validation', '!=', True)]}" groups="base.group_no_one"/>
|
||||
</group>
|
||||
</group>
|
||||
</group>
|
||||
</sheet>
|
||||
<div class="oe_chatter">
|
||||
<field name="message_ids" colspan="4" widget="mail_thread" nolabel="1"/>
|
||||
|
@ -163,17 +153,12 @@
|
|||
<field name="number_of_days_temp"/>
|
||||
</group>
|
||||
<group>
|
||||
<field name="holiday_type" on_change="onchange_type(holiday_type)" attrs="{'readonly':[('state','!=','draft')]}" string="Allocation Mode" groups="base.group_hr_manager"/>
|
||||
<field name="holiday_type" on_change="onchange_type(holiday_type)"/>
|
||||
<field name="employee_id" attrs="{'required':[('holiday_type','=','employee')], 'invisible':[('holiday_type','=','category')]}"/>
|
||||
<field name="category_id" attrs="{'required':[('holiday_type','=','category')], 'readonly':[('state','!=','draft')], 'invisible':[('holiday_type','=','employee')]}"/>
|
||||
<field name="department_id" attrs="{'readonly':['|', ('holiday_type','=','category'), ('state','not in' ,('draft', 'confirm'))]}"/>
|
||||
<field name="category_id" attrs="{'required':[('holiday_type','=','category')], 'invisible':[('holiday_type','=','employee')]}"/>
|
||||
<field name="department_id" attrs="{'invisible':[('holiday_type','=','category')]}"/>
|
||||
</group>
|
||||
</group>
|
||||
<group>
|
||||
<field name="double_validation" invisible="1"/>
|
||||
<field name="manager_id2" attrs="{'invisible':[('double_validation', '!=', True)]}"/>
|
||||
</group>
|
||||
<newline/>
|
||||
<field name="notes" nolabel="1" colspan="4" placeholder="Add a reason..."/>
|
||||
</sheet>
|
||||
<div class="oe_chatter">
|
||||
|
|
|
@ -2,7 +2,16 @@
|
|||
<openerp>
|
||||
<data>
|
||||
|
||||
<!-- Workflow definition -->
|
||||
<!-- Workflow definition
|
||||
1. draft->submitted (no signal)
|
||||
2. submitted->accepted (validate signal) if not 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">
|
||||
<field name="name">hr.wkf.holidays</field>
|
||||
|
@ -10,13 +19,13 @@
|
|||
<field name="on_create">True</field>
|
||||
</record>
|
||||
|
||||
<record model="workflow.activity" id="act_draft">
|
||||
<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>
|
||||
|
||||
<record model="workflow.activity" id="act_confirm">
|
||||
<record model="workflow.activity" id="act_confirm"> <!-- submitted -->
|
||||
<field name="wkf_id" ref="wkf_holidays" />
|
||||
<field name="name">confirm</field>
|
||||
<field name="kind">function</field>
|
||||
|
@ -24,73 +33,94 @@
|
|||
<field name="split_mode">OR</field>
|
||||
</record>
|
||||
|
||||
<record model="workflow.activity" id="act_validate">
|
||||
<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>
|
||||
|
||||
<record model="workflow.activity" id="act_validate1">
|
||||
<record model="workflow.activity" id="act_validate1"> <!-- first_accepted -->
|
||||
<field name="wkf_id" ref="wkf_holidays" />
|
||||
<field name="name">second_validate</field>
|
||||
<field name="name">first_validate</field>
|
||||
<field name="kind">function</field>
|
||||
<field name="action">holidays_validate2()</field>
|
||||
<field name="action">holidays_first_validate()</field>
|
||||
<field name="split_mode">OR</field>
|
||||
</record>
|
||||
|
||||
|
||||
<record model="workflow.activity" id="act_refuse">
|
||||
<record model="workflow.activity" id="act_refuse"> <!-- refused -->
|
||||
<field name="wkf_id" ref="wkf_holidays" />
|
||||
<field name="name">refuse</field>
|
||||
<field name="flow_stop">True</field>
|
||||
<field name="kind">stopall</field>
|
||||
<field name="kind">function</field>
|
||||
<field name="action">holidays_refuse()</field>
|
||||
</record>
|
||||
|
||||
<!--
|
||||
workflow transition
|
||||
-->
|
||||
|
||||
<record model="workflow.transition" id="t1">
|
||||
<record model="workflow.transition" id="holiday_draft2confirm"> <!-- 1. draft->submitted (no signal) -->
|
||||
<field name="act_from" ref="act_draft" />
|
||||
<field name="act_to" ref="act_confirm" />
|
||||
</record>
|
||||
|
||||
<record model="workflow.transition" id="t2">
|
||||
<record model="workflow.transition" id="holiday_confirm2validate"> <!-- 2. submitted->accepted (validate signal) if not double_validation-->
|
||||
<field name="act_from" ref="act_confirm" />
|
||||
<field name="act_to" ref="act_validate" />
|
||||
<field name="signal">validate</field>
|
||||
<field name="condition">not double_validation</field>
|
||||
<field name="group_id" ref="base.group_hr_user"/>
|
||||
</record>
|
||||
|
||||
<record model="workflow.transition" id="holiday_confirm2validate1"> <!-- 2. submitted -> first_accepted (validate signal) if double_validation-->
|
||||
<field name="act_from" ref="act_confirm" />
|
||||
<field name="act_to" ref="act_validate1" />
|
||||
<field name="condition">double_validation</field>
|
||||
<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" />
|
||||
<field name="signal">refuse</field>
|
||||
<field name="condition">True</field>
|
||||
<field name="group_id" ref="base.group_hr_user"/>
|
||||
</record>
|
||||
|
||||
<record model="workflow.transition" id="t3">
|
||||
<field name="act_from" ref="act_confirm" />
|
||||
<field name="act_to" ref="act_refuse" />
|
||||
<field name="signal">refuse</field>
|
||||
<field name="condition">holidays_refuse('first_approval')</field>
|
||||
<field name="group_id" ref="base.group_hr_user"/>
|
||||
</record>
|
||||
|
||||
<record model="workflow.transition" id="t4">
|
||||
<record model="workflow.transition" id="holiday_validate2refuse"> <!-- 3. accepted->refused (refuse signal) -->
|
||||
<field name="act_from" ref="act_validate" />
|
||||
<field name="act_to" ref="act_refuse" />
|
||||
<field name="signal">refuse</field>
|
||||
<field name="condition">holidays_refuse('second_approval')</field>
|
||||
<field name="condition">True</field>
|
||||
<field name="group_id" ref="base.group_hr_user"/>
|
||||
</record>
|
||||
|
||||
<record model="workflow.transition" id="t8">
|
||||
<record model="workflow.transition" id="holiday_validate2refuse"> <!-- 3. accepted->refused (refuse signal) -->
|
||||
<field name="act_from" ref="act_validate" />
|
||||
<field name="act_to" ref="act_validate1" />
|
||||
<field name="act_to" ref="act_refuse" />
|
||||
<field name="signal">refuse</field>
|
||||
<field name="condition">True</field>
|
||||
<field name="group_id" ref="base.group_hr_user"/>
|
||||
</record>
|
||||
|
||||
|
||||
<record model="workflow.transition" id="holiday_validate1_validate"> <!-- 4. first_accepted -> accepted (second_validate signal) -->
|
||||
<field name="act_from" ref="act_validate1" />
|
||||
<field name="act_to" ref="act_validate" />
|
||||
<field name="condition">True</field>
|
||||
<field name="signal">second_validate</field>
|
||||
<field name="group_id" ref="base.group_hr_manager" />
|
||||
<field name="group_id" ref="base.group_hr_user"/>
|
||||
</record>
|
||||
|
||||
<record model="workflow.transition" id="t11">
|
||||
<field name="act_from" ref="act_validate" />
|
||||
<field name="act_to" ref="act_validate1" />
|
||||
<field name="condition">not holiday_status_id.double_validation</field>
|
||||
<field name="signal" eval="False"/>
|
||||
<record model="workflow.transition" id="holiday_validate1_refuse"> <!-- 4. first_accepted->refused (refuse signal) -->
|
||||
<field name="act_from" ref="act_validate1" />
|
||||
<field name="act_to" ref="act_refuse" />
|
||||
<field name="signal">refuse</field>
|
||||
<field name="condition">True</field>
|
||||
<field name="group_id" ref="base.group_hr_user"/>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
|
|
Loading…
Reference in New Issue