[FIX] hr_holidays: force draft.@flow_start to False to correctly update existing databases + fix validation logic
The check_holidays() validation was not working correctly because it was called both before and after inserting new leave requests, with inconsistent results. Using it as a fixed constraint is simpler. bzr revid: odo@openerp.com-20131015165416-in0rfd7rrjmekv0g
This commit is contained in:
parent
17c661328b
commit
58928c5c4c
|
@ -26,6 +26,7 @@ import math
|
||||||
import time
|
import time
|
||||||
from operator import attrgetter
|
from operator import attrgetter
|
||||||
|
|
||||||
|
from openerp.exceptions import Warning
|
||||||
from openerp import tools
|
from openerp import tools
|
||||||
from openerp.osv import fields, osv
|
from openerp.osv import fields, osv
|
||||||
from openerp.tools.translate import _
|
from openerp.tools.translate import _
|
||||||
|
@ -149,6 +150,8 @@ class hr_holidays(osv.osv):
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
_check_holidays = lambda self, cr, uid, ids, context=None: self.check_holidays(cr, uid, ids, context=context)
|
||||||
|
|
||||||
_columns = {
|
_columns = {
|
||||||
'name': fields.char('Description', size=64),
|
'name': fields.char('Description', size=64),
|
||||||
'state': fields.selection([('draft', 'To Submit'), ('cancel', 'Cancelled'),('confirm', 'To Approve'), ('refuse', 'Refused'), ('validate1', 'Second Approval'), ('validate', 'Approved')],
|
'state': fields.selection([('draft', 'To Submit'), ('cancel', 'Cancelled'),('confirm', 'To Approve'), ('refuse', 'Refused'), ('validate1', 'Second Approval'), ('validate', 'Approved')],
|
||||||
|
@ -188,6 +191,7 @@ class hr_holidays(osv.osv):
|
||||||
}
|
}
|
||||||
_constraints = [
|
_constraints = [
|
||||||
(_check_date, 'You can not have 2 leaves that overlaps on same day!', ['date_from','date_to']),
|
(_check_date, 'You can not have 2 leaves that overlaps on same day!', ['date_from','date_to']),
|
||||||
|
(_check_holidays, 'The number of remaining leaves is not sufficient for this leave type', ['state','number_of_days_temp'])
|
||||||
]
|
]
|
||||||
|
|
||||||
_sql_constraints = [
|
_sql_constraints = [
|
||||||
|
@ -314,7 +318,6 @@ class hr_holidays(osv.osv):
|
||||||
context = {}
|
context = {}
|
||||||
context = dict(context, mail_create_nolog=True)
|
context = dict(context, mail_create_nolog=True)
|
||||||
hol_id = super(hr_holidays, self).create(cr, uid, values, context=context)
|
hol_id = super(hr_holidays, self).create(cr, uid, values, context=context)
|
||||||
self.check_holidays(cr, uid, [hol_id], context=context)
|
|
||||||
return hol_id
|
return hol_id
|
||||||
|
|
||||||
def holidays_reset(self, cr, uid, ids, context=None):
|
def holidays_reset(self, cr, uid, ids, context=None):
|
||||||
|
@ -333,7 +336,6 @@ class hr_holidays(osv.osv):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def holidays_first_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')
|
obj_emp = self.pool.get('hr.employee')
|
||||||
ids2 = obj_emp.search(cr, uid, [('user_id', '=', uid)])
|
ids2 = obj_emp.search(cr, uid, [('user_id', '=', uid)])
|
||||||
manager = ids2 and ids2[0] or False
|
manager = ids2 and ids2[0] or False
|
||||||
|
@ -341,7 +343,6 @@ class hr_holidays(osv.osv):
|
||||||
return self.write(cr, uid, ids, {'state':'validate1', 'manager_id': manager})
|
return self.write(cr, uid, ids, {'state':'validate1', 'manager_id': manager})
|
||||||
|
|
||||||
def holidays_validate(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')
|
obj_emp = self.pool.get('hr.employee')
|
||||||
ids2 = obj_emp.search(cr, uid, [('user_id', '=', uid)])
|
ids2 = obj_emp.search(cr, uid, [('user_id', '=', uid)])
|
||||||
manager = ids2 and ids2[0] or False
|
manager = ids2 and ids2[0] or False
|
||||||
|
@ -393,7 +394,6 @@ class hr_holidays(osv.osv):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def holidays_confirm(self, cr, uid, ids, context=None):
|
def holidays_confirm(self, cr, uid, ids, context=None):
|
||||||
self.check_holidays(cr, uid, ids, context=context)
|
|
||||||
for record in self.browse(cr, uid, ids, context=context):
|
for record in self.browse(cr, uid, ids, context=context):
|
||||||
if record.employee_id and record.employee_id.parent_id and record.employee_id.parent_id.user_id:
|
if record.employee_id and record.employee_id.parent_id and record.employee_id.parent_id.user_id:
|
||||||
self.message_subscribe_users(cr, uid, [record.id], user_ids=[record.employee_id.parent_id.user_id.id], context=context)
|
self.message_subscribe_users(cr, uid, [record.id], user_ids=[record.employee_id.parent_id.user_id.id], context=context)
|
||||||
|
@ -429,12 +429,10 @@ class hr_holidays(osv.osv):
|
||||||
if record.holiday_type != 'employee' or record.type != 'remove' or not record.employee_id or record.holiday_status_id.limit:
|
if record.holiday_type != 'employee' or record.type != 'remove' or not record.employee_id or record.holiday_status_id.limit:
|
||||||
continue
|
continue
|
||||||
leave_days = self.pool.get('hr.holidays.status').get_days(cr, uid, [record.holiday_status_id.id], record.employee_id.id, context=context)[record.holiday_status_id.id]
|
leave_days = self.pool.get('hr.holidays.status').get_days(cr, uid, [record.holiday_status_id.id], record.employee_id.id, context=context)[record.holiday_status_id.id]
|
||||||
if leave_days['remaining_leaves'] < record.number_of_days_temp:
|
if leave_days['remaining_leaves'] < 0 or leave_days['virtual_remaining_leaves'] < 0:
|
||||||
raise osv.except_osv(_('Warning!'),
|
# Raising a warning gives a more user-friendly feedback than the default constraint error
|
||||||
_('There are not enough remaining days available in %s for employee %s.') % (record.holiday_status_id.name, record.employee_id.name))
|
raise Warning(_('The number of remaining leaves is not sufficient for this leave type.\n'
|
||||||
if leave_days['virtual_remaining_leaves'] < record.number_of_days_temp:
|
'Please verify also the leaves waiting for validation.'))
|
||||||
raise osv.except_osv(_('Warning!'),
|
|
||||||
_('Other pending requests already book too much days in %s for employee %s.') % (record.holiday_status_id.name, record.employee_id.name))
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# -----------------------------
|
# -----------------------------
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
<record model="workflow.activity" id="act_draft"> <!-- draft -->
|
<record model="workflow.activity" id="act_draft"> <!-- draft -->
|
||||||
<field name="wkf_id" ref="wkf_holidays" />
|
<field name="wkf_id" ref="wkf_holidays" />
|
||||||
<field name="name">draft</field>
|
<field name="name">draft</field>
|
||||||
|
<field name="flow_start">False</field>
|
||||||
<field name="kind">function</field>
|
<field name="kind">function</field>
|
||||||
<field name="action">holidays_reset()</field>
|
<field name="action">holidays_reset()</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
Loading…
Reference in New Issue