[IMP] hr_holidays: put a boolean on the holiday type like 'double-validation holiday type', means this leave type will have to be validated by 2 people => the workflow have to be adapted (one more activity, automatic transition if boolean = false), there should be a new state for the object, there should also be a second 'validator' (m2o: user_id) that is saved when the leave/allocation is validated the second time
bzr revid: mra@tinyerp.com-20100510105832-pixohghomphs57c4
This commit is contained in:
parent
b440209425
commit
f0c3f1ba59
|
@ -96,6 +96,7 @@ class hr_holidays_status(osv.osv):
|
|||
'max_leaves': fields.function(_user_left_days, method=True, string='Maximum Leaves Allowed', help='This value is given by the sum of all holidays requests with a positive value.', multi='user_left_days'),
|
||||
'leaves_taken': fields.function(_user_left_days, method=True, string='Leaves Already Taken', help='This value is given by the sum of all holidays requests with a negative value.', multi='user_left_days'),
|
||||
'remaining_leaves': fields.function(_user_left_days, method=True, string='Remaining Leaves', help='Maximum Leaves Allowed - Leaves Already Taken', multi='user_left_days'),
|
||||
'double_validation': fields.boolean('Apply Double Validation', help="If its True then its Allocation/Request have to be validated by second validator")
|
||||
}
|
||||
_defaults = {
|
||||
'color_name': 'red',
|
||||
|
@ -117,7 +118,7 @@ class hr_holidays(osv.osv):
|
|||
|
||||
_columns = {
|
||||
'name' : fields.char('Description', required=True, readonly=True, size=64, states={'draft':[('readonly',False)]}),
|
||||
'state': fields.selection([('draft', 'Draft'), ('confirm', 'Waiting Validation'), ('refuse', 'Refused'), ('validate', 'Validated'), ('cancel', 'Cancelled')], 'State', readonly=True, help='When the holiday request is created the state is \'Draft\'.\n It is confirmed by the user and request is sent to admin, the state is \'Waiting Validation\'.\
|
||||
'state': fields.selection([('draft', 'Draft'), ('confirm', 'Waiting Validation'), ('refuse', 'Refused'), ('validate1', 'Waiting Second Validation'), ('validate', 'Validated'), ('cancel', 'Cancelled')], 'State', readonly=True, help='When the holiday request is created the state is \'Draft\'.\n It is confirmed by the user and request is sent to admin, the state is \'Waiting Validation\'.\
|
||||
If the admin accepts it, the state is \'Validated\'. If it is refused, the state is \'Refused\'.'),
|
||||
'date_from' : fields.datetime('Start Date', readonly=True, states={'draft':[('readonly',False)]}),
|
||||
'user_id':fields.many2one('res.users', 'User', states={'draft':[('readonly',False)]}, select=True, readonly=True),
|
||||
|
@ -136,6 +137,7 @@ class hr_holidays(osv.osv):
|
|||
'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', "Employee Category", help='Category Of employee'),
|
||||
'holiday_type': fields.selection([('employee','By Employee'),('category','By Employee Category')], 'Holiday Type', help='By Employee: Allocation/Request for individual Employee, By Employee Category: Allocation/Request for group of employees in category'),
|
||||
'manager_id2': fields.many2one('hr.employee', 'Second Validator', readonly=True, help='This area is automaticly filled by the user who validate the leave with second level (If Leave type need second validation)')
|
||||
}
|
||||
|
||||
_defaults = {
|
||||
|
@ -259,18 +261,16 @@ class hr_holidays(osv.osv):
|
|||
wf_service.trg_create(uid, 'hr.holidays', holiday_id, cr)
|
||||
return True
|
||||
|
||||
def holidays_validate(self, cr, uid, ids, *args):
|
||||
self.check_holidays(cr, uid, ids)
|
||||
vals = {
|
||||
'state':'validate',
|
||||
}
|
||||
def holidays_validate2(self, cr, uid, ids, *args):
|
||||
vals = {'state':'validate'}
|
||||
data_holiday = self.browse(cr, uid, ids)
|
||||
ids2 = self.pool.get('hr.employee').search(cr, uid, [('user_id','=', uid)])
|
||||
if ids2:
|
||||
vals['manager_id'] = ids2[0]
|
||||
vals['manager_id2'] = ids2[0]
|
||||
else:
|
||||
raise osv.except_osv(_('Warning !'),_('No user related to the selected employee.'))
|
||||
self.write(cr, uid, ids, vals)
|
||||
for record in self.browse(cr, uid, ids):
|
||||
for record in data_holiday:
|
||||
if record.holiday_type=='employee' and record.type=='remove':
|
||||
vals= {
|
||||
'name':record.name,
|
||||
|
@ -283,6 +283,33 @@ class hr_holidays(osv.osv):
|
|||
self.pool.get('resource.calendar.leaves').create(cr, uid, vals)
|
||||
return True
|
||||
|
||||
def holidays_validate(self, cr, uid, ids, *args):
|
||||
data_holiday = self.browse(cr, uid, ids)
|
||||
self.check_holidays(cr, uid, ids)
|
||||
if data_holiday[0].holiday_status_id.double_validation:
|
||||
vals = {'state':'validate1'}
|
||||
else:
|
||||
vals = {'state':'validate'}
|
||||
ids2 = self.pool.get('hr.employee').search(cr, uid, [('user_id','=', uid)])
|
||||
if ids2:
|
||||
vals['manager_id'] = ids2[0]
|
||||
else:
|
||||
raise osv.except_osv(_('Warning !'),_('No user related to the selected employee.'))
|
||||
self.write(cr, uid, ids, vals)
|
||||
if data_holiday[0].holiday_status_id.double_validation:
|
||||
for record in data_holiday:
|
||||
if record.holiday_type=='employee' and record.type=='remove':
|
||||
vals= {
|
||||
'name':record.name,
|
||||
'date_from':record.date_from,
|
||||
'date_to':record.date_to,
|
||||
'calendar_id':record.employee_id.calendar_id.id,
|
||||
'company_id':record.employee_id.company_id.id,
|
||||
'resource_id':record.employee_id.resource_id.id
|
||||
}
|
||||
self.pool.get('resource.calendar.leaves').create(cr, uid, vals)
|
||||
return True
|
||||
|
||||
def holidays_confirm(self, cr, uid, ids, *args):
|
||||
for record in self.browse(cr, uid, ids):
|
||||
user_id = False
|
||||
|
@ -310,6 +337,7 @@ class hr_holidays(osv.osv):
|
|||
'number_of_days': nb,
|
||||
'user_id': user_id
|
||||
})
|
||||
cr.commit()
|
||||
return True
|
||||
|
||||
def holidays_refuse(self, cr, uid, ids, *args):
|
||||
|
|
|
@ -68,11 +68,15 @@
|
|||
<group colspan="2">
|
||||
<button string="Confirm" name="confirm" states="draft" type="workflow" icon="gtk-yes"/>
|
||||
<button string="Validate" name="validate" states="confirm" type="workflow" icon="gtk-apply"/>
|
||||
<button string="Refuse" name="refuse" states="confirm" type="workflow" icon="gtk-no"/>
|
||||
<button string="Approve" name="second_validate" states="validate1" type="workflow" icon="gtk-apply"/>
|
||||
<button string="Refuse" name="refuse" states="confirm,validate1" type="workflow" icon="gtk-no"/>
|
||||
<button string="Cancel" name="cancel" states="validate,refuse" type="workflow" icon="gtk-cancel"/>
|
||||
<button string="Set to Draft" name="set_to_draft" states="cancel" type="object" icon="gtk-convert"/>
|
||||
</group>
|
||||
</page>
|
||||
<page string="Extra Information">
|
||||
<field name="manager_id2"/>
|
||||
</page>
|
||||
</notebook>
|
||||
</form>
|
||||
</field>
|
||||
|
@ -105,11 +109,15 @@
|
|||
<group colspan="2">
|
||||
<button string="Confirm" name="confirm" states="draft" type="workflow" icon="gtk-yes"/>
|
||||
<button string="Validate" name="validate" states="confirm" type="workflow" icon="gtk-apply"/>
|
||||
<button string="Refuse" name="refuse" states="confirm" type="workflow" icon="gtk-no"/>
|
||||
<button string="Approve" name="second_validate" states="validate1" type="workflow" icon="gtk-apply"/>
|
||||
<button string="Refuse" name="refuse" states="confirm,validate1" type="workflow" icon="gtk-no"/>
|
||||
<button string="Cancel" name="cancel" states="validate,refuse" type="workflow" icon="gtk-cancel"/>
|
||||
<button string="Set to Draft" name="set_to_draft" states="cancel" type="object" icon="gtk-convert"/>
|
||||
<button string="Set to Draft" name="set_to_draft" states="cancel" type="object" icon="gtk-convert"/>
|
||||
</group>
|
||||
</page>
|
||||
<page string="Extra Information">
|
||||
<field name="manager_id2"/>
|
||||
</page>
|
||||
</notebook>
|
||||
</form>
|
||||
</field>
|
||||
|
@ -142,7 +150,7 @@
|
|||
<button string="Confirm" name="confirm" states="draft" type="workflow" icon="gtk-yes"/>
|
||||
<button string="Validate" name="validate" states="confirm" type="workflow" icon="gtk-apply"/>
|
||||
<button string="Refuse" name="refuse" states="confirm" type="workflow" icon="gtk-no"/>
|
||||
<button string="Cancel" name="cancel" states="validate,refuse" type="workflow" icon="gtk-cancel"/>
|
||||
<button string="Cancel" name="cancel" states="validate,refuse,validate1" type="workflow" icon="gtk-cancel"/>
|
||||
<button string="Set to Draft" name="set_to_draft" states="cancel" type="object" icon="gtk-convert"/>
|
||||
</group>
|
||||
</page>
|
||||
|
@ -303,6 +311,7 @@
|
|||
<field name="active"/>
|
||||
<field name="categ_id" select="1" widget="selection"/>
|
||||
<field name="color_name"/>
|
||||
<field name="double_validation" />
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
|
|
@ -37,6 +37,14 @@
|
|||
<field name="action">holidays_validate()</field>
|
||||
</record>
|
||||
|
||||
<record model="workflow.activity" id="act_validate1">
|
||||
<field name="wkf_id" ref="wkf_holidays" />
|
||||
<field name="name">second_validate</field>
|
||||
<field name="kind">function</field>
|
||||
<field name="action">holidays_validate2()</field>
|
||||
</record>
|
||||
|
||||
|
||||
<record model="workflow.activity" id="act_refuse">
|
||||
<field name="wkf_id" ref="wkf_holidays" />
|
||||
<field name="name">refuse</field>
|
||||
|
@ -53,8 +61,8 @@
|
|||
<field name="action">holidays_cancel()</field>
|
||||
<field name="join_mode">XOR</field>
|
||||
</record>
|
||||
|
||||
<!--
|
||||
|
||||
<!--
|
||||
workflow transition
|
||||
-->
|
||||
|
||||
|
@ -63,7 +71,7 @@
|
|||
<field name="act_to" ref="act_confirm" />
|
||||
<field name="signal">confirm</field>
|
||||
</record>
|
||||
|
||||
|
||||
<record model="workflow.transition" id="t2">
|
||||
<field name="act_from" ref="act_confirm" />
|
||||
<field name="act_to" ref="act_validate" />
|
||||
|
@ -97,6 +105,24 @@
|
|||
<field name="act_to" ref="act_draft" />
|
||||
<field name="signal">set_to_draft</field>
|
||||
</record>
|
||||
|
||||
|
||||
<record model="workflow.transition" id="t8">
|
||||
<field name="act_from" ref="act_validate" />
|
||||
<field name="act_to" ref="act_validate1" />
|
||||
<field name="signal">second_validate</field>
|
||||
</record>
|
||||
|
||||
<record model="workflow.transition" id="t9">
|
||||
<field name="act_from" ref="act_validate" />
|
||||
<field name="act_to" ref="act_refuse" />
|
||||
<field name="signal">refuse</field>
|
||||
</record>
|
||||
|
||||
<record model="workflow.transition" id="t10">
|
||||
<field name="act_from" ref="act_validate1" />
|
||||
<field name="act_to" ref="act_cancel" />
|
||||
<field name="signal">cancel</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
|
|
Loading…
Reference in New Issue