From ac367e4ceb26224cd0c994948d98725b57a0b4d6 Mon Sep 17 00:00:00 2001 From: Cedric Snauwaert Date: Wed, 12 Dec 2012 16:21:26 +0100 Subject: [PATCH 1/2] [FIX]fix problem when trying to add line entry in my current timesheet bzr revid: csn@openerp.com-20121212152126-czq2fwo1oxkvt73o --- addons/hr_timesheet/hr_timesheet.py | 17 ++++++++++------- addons/hr_timesheet_sheet/hr_timesheet_sheet.py | 6 ++++-- .../hr_timesheet_sheet_view.xml | 8 ++++---- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/addons/hr_timesheet/hr_timesheet.py b/addons/hr_timesheet/hr_timesheet.py index 9e5337492d9..26893c1da9e 100644 --- a/addons/hr_timesheet/hr_timesheet.py +++ b/addons/hr_timesheet/hr_timesheet.py @@ -99,7 +99,7 @@ class hr_analytic_timesheet(osv.osv): 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 @@ class hr_analytic_timesheet(osv.osv): 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 @@ class hr_analytic_timesheet(osv.osv): 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 @@ class hr_analytic_timesheet(osv.osv): 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 @@ class hr_analytic_timesheet(osv.osv): '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 @@ class hr_analytic_timesheet(osv.osv): 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 diff --git a/addons/hr_timesheet_sheet/hr_timesheet_sheet.py b/addons/hr_timesheet_sheet/hr_timesheet_sheet.py index 6a060410d6d..f4ab61b028f 100644 --- a/addons/hr_timesheet_sheet/hr_timesheet_sheet.py +++ b/addons/hr_timesheet_sheet/hr_timesheet_sheet.py @@ -218,8 +218,10 @@ class hr_timesheet_sheet(osv.osv): 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 diff --git a/addons/hr_timesheet_sheet/hr_timesheet_sheet_view.xml b/addons/hr_timesheet_sheet/hr_timesheet_sheet_view.xml index 6de6be6c08d..defc4e1e0a9 100644 --- a/addons/hr_timesheet_sheet/hr_timesheet_sheet_view.xml +++ b/addons/hr_timesheet_sheet/hr_timesheet_sheet_view.xml @@ -80,7 +80,8 @@
@@ -94,7 +95,6 @@ - @@ -103,7 +103,7 @@ - + @@ -134,7 +134,7 @@ - + From 182ea633d76d42fc1dbc611029012b5194d75e1a Mon Sep 17 00:00:00 2001 From: Cedric Snauwaert Date: Wed, 12 Dec 2012 17:27:38 +0100 Subject: [PATCH 2/2] [REF]invert if-else condition bzr revid: csn@openerp.com-20121212162738-2nwkk3r0f45bmvzs --- addons/hr_timesheet/hr_timesheet.py | 6 +++--- addons/hr_timesheet_sheet/hr_timesheet_sheet_view.xml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/addons/hr_timesheet/hr_timesheet.py b/addons/hr_timesheet/hr_timesheet.py index 26893c1da9e..f6cd3366226 100644 --- a/addons/hr_timesheet/hr_timesheet.py +++ b/addons/hr_timesheet/hr_timesheet.py @@ -136,10 +136,10 @@ class hr_analytic_timesheet(osv.osv): emp_obj = self.pool.get('hr.employee') if context is None: context = {} - 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: + if context.get('employee_id'): emp_id = [context.get('employee_id')] + else: + emp_id = emp_obj.search(cr, uid, [('user_id','=',context.get('user_id') or uid)], limit=1, context=context) 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) diff --git a/addons/hr_timesheet_sheet/hr_timesheet_sheet_view.xml b/addons/hr_timesheet_sheet/hr_timesheet_sheet_view.xml index defc4e1e0a9..1dd9d8323bf 100644 --- a/addons/hr_timesheet_sheet/hr_timesheet_sheet_view.xml +++ b/addons/hr_timesheet_sheet/hr_timesheet_sheet_view.xml @@ -80,7 +80,7 @@