diff --git a/addons/base_setup/installer.py b/addons/base_setup/installer.py
index 0019ff9a4f4..fdd28950094 100644
--- a/addons/base_setup/installer.py
+++ b/addons/base_setup/installer.py
@@ -236,9 +236,9 @@ class user_preferences_config(osv.osv_memory):
context = {}
res = super(user_preferences_config, self).default_get(cr, uid, fields, context=context)
res_default = self.pool.get('ir.values').get(cr, uid, 'default', False, ['res.users'])
- for val in range(len(res_default)):
- res.update({res_default[val][1]:res_default[val][2]})
- return res
+ for id, field, value in res_default:
+ res.update({field: value})
+ return res
def execute(self, cr, uid, ids, context=None):
for o in self.browse(cr, uid, ids, context=context):
diff --git a/addons/hr_holidays/hr_holidays.py b/addons/hr_holidays/hr_holidays.py
index 049d93a3170..d8605f297b0 100644
--- a/addons/hr_holidays/hr_holidays.py
+++ b/addons/hr_holidays/hr_holidays.py
@@ -326,61 +326,35 @@ resource_calendar_leaves()
class hr_employee(osv.osv):
_inherit="hr.employee"
- def _emp_remaining_days(self, cr, uid, ids, name, args, context=None):
- if context is None:
- context = {}
- res = {}
- emp_list = []
- ans2 = 0.0
- type_list = []
+ 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')
holiday_obj = self.pool.get('hr.holidays')
- type_ids = type_obj.search(cr, uid, [], context=context)
- false_leave_id = []
- for type in type_obj.browse(cr, uid, type_ids, context=context):
- if type.limit == False:
- false_leave_id.append(type.id)
- holiday_ids = holiday_obj.search(cr, uid, [('type','=','add')], context=context)
- for j in holiday_obj.browse(cr, uid, holiday_ids, context=context):
- if j.employee_id.id not in emp_list:
- emp_list.append(j.employee_id.id)
- if emp_list:
- for c in emp_list:
- res[c] = 0.0
- for b in false_leave_id:
- cr.execute("select sum(number_of_days_temp) from hr_holidays where employee_id=%s and holiday_status_id=%s and state='validate' and type='add'", (c,b))
- res3 = cr.fetchone()[0] or 0.0
- ans2 = ans2 + res3
- res[c] = ans2
- return res
-
- def _data_compute(self, cr, uid, id, name, value, arg, context=None):
- if context is None:
- context = {}
- false_leave_id = []
- emp = self.browse(cr, uid, id, context=context)
- diff = value - emp.remaining_leaves
- holiday_obj = self.pool.get('hr.holidays')
- type_obj = self.pool.get('hr.holidays.status')
- type_ids = type_obj.search(cr, uid, [], context=context)
- for type in type_obj.browse(cr, uid, type_ids, context=context):
- if type.limit == False:
- false_leave_id.append(type.id)
- if false_leave_id:
- holiday_emp_id = holiday_obj.search(cr, uid, [('employee_id','=',emp.id),('type','=','add'),('state','=','validate'),('holiday_status_id','=',false_leave_id[0])], context=context)
- if holiday_emp_id:
- holiday_emp_id.sort()
- prev_lv = holiday_obj.browse(cr, uid, holiday_emp_id[0], context=context).number_of_days_temp
- new_lv = prev_lv + diff
- holiday_obj.write(cr, uid, holiday_emp_id[0],{'number_of_days_temp': new_lv}, context=context)
- if not holiday_emp_id:
- desc = 'Leaves for '+ emp.name
- holiday_obj.create(cr, uid,{'employee_id': emp.id, 'number_of_days_temp':diff, 'name':desc,'holiday_status_id':false_leave_id[0], 'type':'add','state':'validate'})
-
- return {}
+ # Find for holidays status
+ status_ids = type_obj.search(cr, uid, [('limit', '=', False)], context=context)
+ status_id = status_ids and status_ids[0] or False
+ if not status_id or diff <= 0:
+ return False
+ leave_id = holiday_obj.create(cr, uid, {'name': 'Allocation for ' + employee.name,'employee_id': employee.id, 'holiday_status_id': status_id, 'type': 'add', 'holiday_type': 'employee', 'number_of_days_temp': diff}, context=context)
+ holiday_obj.holidays_confirm(cr, uid, [leave_id])
+ holiday_obj.holidays_validate2(cr, uid, [leave_id])
+ return True
+
+ def _get_remaining_days(self, cr, uid, ids, name, args, context=None):
+ cr.execute("SELECT sum(h.number_of_days_temp) as days, h.employee_id from hr_holidays h join hr_holidays_status s on (s.id=h.holiday_status_id) where h.type='add' and h.state='validate' and s.limit=False group by h.employee_id")
+ res = cr.dictfetchall()
+ remaining = {}
+ for r in res:
+ remaining[r['employee_id']] = r['days']
+ for employee_id in ids:
+ if not remaining.get(employee_id):
+ remaining[employee_id] = 0.0
+ return remaining
+
_columns = {
- 'remaining_leaves': fields.function(_emp_remaining_days, method=True, string='Remaining Leaves',fnct_inv=_data_compute, type="float", help='Remaining Leaves', store=True, readonly=False),
+ 'remaining_leaves': fields.function(_get_remaining_days, method=True, string='Remaining Leaves', fnct_inv=_set_remaining_days, type="float", help='Remaining Leaves', store=True),
}
hr_employee()
diff --git a/addons/hr_holidays/hr_holidays_view.xml b/addons/hr_holidays/hr_holidays_view.xml
index 36f15ac85b8..56fb7faddfc 100644
--- a/addons/hr_holidays/hr_holidays_view.xml
+++ b/addons/hr_holidays/hr_holidays_view.xml
@@ -443,48 +443,16 @@
id="act_hr_employee_holiday_request"/>
-
-
- hr.employee.form.assign
- hr.employee
-
- form
-
-
-
-
-
-
-
- hr.employee.tree
+ hr.employee.leave.tree
hr.employee
-
tree
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+