Cedric Snauwaert (OpenERP) has proposed merging 
lp:~openerp-dev/openobject-addons/trunk-timesheet-fix-csn into 
lp:openobject-addons.

Requested reviews:
  qdp (OpenERP) (qdp)

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-timesheet-fix-csn/+merge/139495

Fix My Timesheet problems when trying to add new line in "My Current 
Timesheet>details", add employee_id to context to have a more precise error 
message in _getAnalyticJournal function (instead of always having the first 
user with user_id==False).

change context.get('user_id',uid) to context.get('user_id') or uid : in the 
first case, if user_id exist in the context (which is the case in timesheet) 
and its value is False, the result will be False, in the second case even if 
the value is False, the result will be uid which is what we want.
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-timesheet-fix-csn/+merge/139495
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-addons/trunk-timesheet-fix-csn.
=== modified file 'hr_timesheet/hr_timesheet.py'
--- hr_timesheet/hr_timesheet.py	2012-11-29 22:26:45 +0000
+++ hr_timesheet/hr_timesheet.py	2012-12-12 15:53:34 +0000
@@ -99,7 +99,7 @@
         if context is None:
             context = {}
         emp_obj = self.pool.get('hr.employee')
-        emp_id = emp_obj.search(cr, uid, [('user_id', '=', context.get('user_id', uid))], context=context)
+        emp_id = emp_obj.search(cr, uid, [('user_id', '=', context.get('user_id') or uid)], context=context)
         if emp_id:
             emp = emp_obj.browse(cr, uid, emp_id[0], context=context)
             if emp.product_id:
@@ -110,7 +110,7 @@
         emp_obj = self.pool.get('hr.employee')
         if context is None:
             context = {}
-        emp_id = emp_obj.search(cr, uid, [('user_id', '=', context.get('user_id', uid))], context=context)
+        emp_id = emp_obj.search(cr, uid, [('user_id', '=', context.get('user_id') or uid)], context=context)
         if emp_id:
             emp = emp_obj.browse(cr, uid, emp_id[0], context=context)
             if emp.product_id:
@@ -121,7 +121,7 @@
         emp_obj = self.pool.get('hr.employee')
         if context is None:
             context = {}
-        emp_id = emp_obj.search(cr, uid, [('user_id', '=', context.get('user_id', uid))], context=context)
+        emp_id = emp_obj.search(cr, uid, [('user_id', '=', context.get('user_id') or uid)], context=context)
         if emp_id:
             emp = emp_obj.browse(cr, uid, emp_id[0], context=context)
             if bool(emp.product_id):
@@ -136,8 +136,11 @@
         emp_obj = self.pool.get('hr.employee')
         if context is None:
             context = {}
-        emp_id = emp_obj.search(cr, uid, [('user_id', '=', context.get('user_id', uid))], context=context)
-        if not emp_id :
+        if not context.get('employee_id'):
+            emp_id = emp_obj.search(cr, uid, [('user_id','=',context.get('user_id') or uid)], limit=1, context=context)
+        else:
+            emp_id = [context.get('employee_id')]
+        if not emp_id:
             raise osv.except_osv(_('Warning!'), _('Please create an employee for this user, using the menu: Human Resources > Employees.'))
         emp = emp_obj.browse(cr, uid, emp_id[0], context=context)
         if emp.journal_id:
@@ -152,7 +155,7 @@
         'general_account_id': _getGeneralAccount,
         'journal_id': _getAnalyticJournal,
         'date': lambda self, cr, uid, ctx: ctx.get('date', fields.date.context_today(self,cr,uid,context=ctx)),
-        'user_id': lambda obj, cr, uid, ctx: ctx.get('user_id', uid),
+        'user_id': lambda obj, cr, uid, ctx: ctx.get('user_id') or uid,
     }
     def on_change_account_id(self, cr, uid, ids, account_id, context=None):
         return {'value':{}}
@@ -169,7 +172,7 @@
         if context is None:
             context = {}
         emp_obj = self.pool.get('hr.employee')
-        emp_id = emp_obj.search(cr, uid, [('user_id', '=', context.get('user_id', uid))], context=context)
+        emp_id = emp_obj.search(cr, uid, [('user_id', '=', context.get('user_id') or uid)], context=context)
         ename = ''
         if emp_id:
             ename = emp_obj.browse(cr, uid, emp_id[0], context=context).name

=== modified file 'hr_timesheet_sheet/hr_timesheet_sheet.py'
--- hr_timesheet_sheet/hr_timesheet_sheet.py	2012-12-08 12:43:19 +0000
+++ hr_timesheet_sheet/hr_timesheet_sheet.py	2012-12-12 15:53:34 +0000
@@ -218,8 +218,10 @@
     def onchange_employee_id(self, cr, uid, ids, employee_id, context=None):
         department_id =  False
         if employee_id:
-            department_id = self.pool.get('hr.employee').browse(cr, uid, employee_id, context=context).department_id.id
-        return {'value': {'department_id': department_id}}
+            empl_id = self.pool.get('hr.employee').browse(cr, uid, employee_id, context=context)
+            department_id = empl_id.department_id.id
+            user_id = empl_id.user_id.id
+        return {'value': {'department_id': department_id, 'user_id': user_id,}}
 
     # ------------------------------------------------
     # OpenChatter methods and notifications

=== modified file 'hr_timesheet_sheet/hr_timesheet_sheet_view.xml'
--- hr_timesheet_sheet/hr_timesheet_sheet_view.xml	2012-12-08 12:43:19 +0000
+++ hr_timesheet_sheet/hr_timesheet_sheet_view.xml	2012-12-12 15:53:34 +0000
@@ -80,7 +80,8 @@
                     </div>
                     <div class="oe_title">
                         <label for="employee_id" class="oe_edit_only"/>
-                        <h1><field name="employee_id" on_change="onchange_employee_id(employee_id)" class="oe_inline"/></h1>
+                        <h1><field name="employee_id" on_change="onchange_employee_id(employee_id)" class="oe_inline" context="{'employee_id': employee_id, 'user_id':user_id}"/></h1>
+                        <field name="user_id" invisible="1"/>
                     </div>
                     <group>
                         <group>
@@ -94,7 +95,6 @@
                             <field name="total_attendance" widget="float_time"/>
                             <field name="total_timesheet" widget="float_time"/>
                             <field name="total_difference" widget="float_time"/>
-                            <field name="user_id" invisible="1"/>
                         </group>
                     </group>
                     <notebook>
@@ -103,7 +103,7 @@
                             </widget>
                         </page>
                         <page string="Details">
-                            <field context="{'user_id':user_id, 'timesheet_date_from': date_from, 'timesheet_date_to': date_to}" name="timesheet_ids" nolabel="1">
+                            <field context="{'employee_id': employee_id, 'user_id':user_id, 'timesheet_date_from': date_from, 'timesheet_date_to': date_to}" name="timesheet_ids" nolabel="1">
                                 <tree editable="top" string="Timesheet Activities">
                                     <field name="date"/>
                                     <field domain="[('type','in',['normal', 'contract']), ('state', '&lt;&gt;', 'close'),('use_timesheets','=',1)]" name="account_id" on_change="on_change_account_id(account_id, user_id)" context="{'default_use_timesheets': 1}"/>
@@ -134,7 +134,7 @@
                         </page>
                         <page string="Attendances" groups="base.group_hr_attendance">
                             <group>
-                                <field context="{'user_id':user_id}" name="attendances_ids" nolabel="1">
+                                <field context="{'employee_id': employee_id, 'user_id':user_id}" name="attendances_ids" nolabel="1">
                                     <tree string="Attendances" editable="bottom">
                                         <field name="name"/>
                                         <field name="action"/>

_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to     : openerp-dev-gtk@lists.launchpad.net
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help   : https://help.launchpad.net/ListHelp

Reply via email to