[FIX] hr_holidays: impossible to create hr_employee in some situations because the functional field set_remaining_days is written
lp bug: https://launchpad.net/bugs/908986 fixed bzr revid: qdp-launchpad@openerp.com-20120103135224-3838ozzghqkmkekj
This commit is contained in:
@@ -356,9 +356,17 @@ resource_calendar_leaves()
|
||||
|
||||
|
||||
class hr_employee(osv.osv):
|
||||
_inherit="hr.employee"
|
||||
_inherit="hr.employee"
|
||||
|
||||
def _set_remaining_days(self, cr, uid, empl_id, name, value, arg, context=None):
|
||||
def create(self, cr, uid, vals, context=None):
|
||||
# don't pass the value of remaining leave if it's 0 at the creation time, otherwise it will trigger the inverse
|
||||
# function _set_remaining_days and the system may not be configured for. Note that we don't have this problem on
|
||||
# the write because the clients only send the fields that have been modified.
|
||||
if 'remaining_leaves' in vals and not vals['remaining_leaves']:
|
||||
del(vals['remaining_leaves'])
|
||||
return super(hr_employee, self).create(cr, uid, vals, context=context)
|
||||
|
||||
def _set_remaining_days(self, cr, uid, empl_id, name, value, arg, context=None):
|
||||
employee = self.browse(cr, uid, empl_id, context=context)
|
||||
diff = value - employee.remaining_leaves
|
||||
type_obj = self.pool.get('hr.holidays.status')
|
||||
@@ -366,7 +374,7 @@ class hr_employee(osv.osv):
|
||||
# Find for holidays status
|
||||
status_ids = type_obj.search(cr, uid, [('limit', '=', False)], context=context)
|
||||
if len(status_ids) != 1 :
|
||||
raise osv.except_osv(_('Warning !'),_("To use this feature, you must have only one leave type without the option 'Allow to Override Limit' set. (%s Found).") % (len(status_ids)))
|
||||
raise osv.except_osv(_('Warning !'),_("The feature behind the field 'Remaining Legal Leaves' can only be used when there is only one leave type with the option 'Allow to Override Limit' unchecked. (%s Found). Otherwise, the update is ambiguous as we cannot decide on which leave type the update has to be done. \nYou may prefer to use the classic menus 'Leave Requests' and 'Allocation Requests' located in 'Human Resources \ Leaves' to manage the leave days of the employees if the configuration does not allow to use this field.") % (len(status_ids)))
|
||||
status_id = status_ids and status_ids[0] or False
|
||||
if not status_id:
|
||||
return False
|
||||
@@ -382,7 +390,7 @@ class hr_employee(osv.osv):
|
||||
wf_service.trg_validate(uid, 'hr.holidays', leave_id, 'second_validate', cr)
|
||||
return True
|
||||
|
||||
def _get_remaining_days(self, cr, uid, ids, name, args, context=None):
|
||||
def _get_remaining_days(self, cr, uid, ids, name, args, context=None):
|
||||
cr.execute("""SELECT
|
||||
sum(h.number_of_days) as days,
|
||||
h.employee_id
|
||||
@@ -403,7 +411,7 @@ class hr_employee(osv.osv):
|
||||
remaining[employee_id] = 0.0
|
||||
return remaining
|
||||
|
||||
def _get_leave_status(self, cr, uid, ids, name, args, context=None):
|
||||
def _get_leave_status(self, cr, uid, ids, name, args, context=None):
|
||||
holidays_id = self.pool.get('hr.holidays').search(cr, uid,
|
||||
[('employee_id', 'in', ids), ('date_from','<=',time.strftime('%Y-%m-%d %H:%M:%S')),
|
||||
('date_to','>=',time.strftime('%Y-%m-%d %H:%M:%S')),('type','=','remove'),('state','not in',('cancel','refuse'))],
|
||||
@@ -419,7 +427,7 @@ class hr_employee(osv.osv):
|
||||
result[holiday.employee_id.id]['current_leave_id'] = holiday.holiday_status_id.id
|
||||
return result
|
||||
|
||||
_columns = {
|
||||
_columns = {
|
||||
'remaining_leaves': fields.function(_get_remaining_days, string='Remaining Legal Leaves', fnct_inv=_set_remaining_days, type="float", help='Total number of legal leaves allocated to this employee, change this value to create allocation/leave requests.'),
|
||||
'current_leave_state': fields.function(_get_leave_status, multi="leave_status", string="Current Leave Status", type="selection",
|
||||
selection=[('draft', 'New'), ('confirm', 'Waiting Approval'), ('refuse', 'Refused'),
|
||||
|
||||
Reference in New Issue
Block a user