[IMP] [Leaves] Context problem: creating a leave from the employee form.
authorTejas Tank <tta@openerp.com>
Mon, 11 Feb 2013 10:57:01 +0000 (16:27 +0530)
committerTejas Tank <tta@openerp.com>
Mon, 11 Feb 2013 10:57:01 +0000 (16:27 +0530)
bzr revid: tta@openerp.com-20130211105701-gzl5vsmx01ckdled

addons/hr_holidays/hr_holidays.py
addons/hr_holidays/hr_holidays_view.xml

index c7d7867..11b3cef 100644 (file)
@@ -117,7 +117,10 @@ class hr_holidays(osv.osv):
         },
     }
 
-    def _employee_get(self, cr, uid, context=None):
+    def _employee_get(self, cr, uid, context=None):        
+        emp_id = context.get('default_employee_id', False)
+        if emp_id:
+            return emp_id
         ids = self.pool.get('hr.employee').search(cr, uid, [('user_id', '=', uid)], context=context)
         if ids:
             return ids[0]
@@ -204,9 +207,9 @@ class hr_holidays(osv.osv):
         leave_ids = obj_res_leave.search(cr, uid, [('holiday_id', 'in', ids)], context=context)
         return obj_res_leave.unlink(cr, uid, leave_ids, context=context)
 
-    def onchange_type(self, cr, uid, ids, holiday_type):
-        result = {'value': {'employee_id': False}}
-        if holiday_type == 'employee':
+    def onchange_type(self, cr, uid, ids, holiday_type, employee_id):
+        result = {}
+        if holiday_type == 'employee' and not employee_id:
             ids_employee = self.pool.get('hr.employee').search(cr, uid, [('user_id','=', uid)])
             if ids_employee:
                 result['value'] = {
index f8b4ad0..041094c 100644 (file)
@@ -78,7 +78,7 @@
                             <field name="category_id" attrs="{'required':[('holiday_type','=','category')], 'invisible':[('holiday_type','=','employee')], 'readonly':[('state','!=','draft'), ('state','!=','confirm')]}"/>
                         </group>
                         <group>
-                            <field name="holiday_type" on_change="onchange_type(holiday_type)" attrs="{'readonly':[('state','!=','draft')]}" width="130" string="Mode" groups="base.group_hr_user"/>
+                            <field name="holiday_type" on_change="onchange_type(holiday_type, employee_id)" attrs="{'readonly':[('state','!=','draft')]}" width="130" string="Mode" groups="base.group_hr_user"/>
                             <field name="employee_id" attrs="{'required':[('holiday_type','=','employee')],'invisible':[('holiday_type','=','category')]}" on_change="onchange_employee(employee_id)" groups="base.group_hr_user"/>
                             <field name="department_id" attrs="{'readonly':[('holiday_type','=','category')]}" groups="base.group_hr_user"/>
                         </group>