From 5cc4b243b683f7ecf69b1ae2e18247d82950e50b Mon Sep 17 00:00:00 2001 From: mtr Date: Tue, 28 Jun 2011 17:16:33 +0530 Subject: [PATCH 1/5] [FIX] hr_holidays:-Exception raised on confirmation of leave request is now translated in user's lang. lp bug: https://launchpad.net/bugs/798739 fixed bzr revid: mtr@mtr-20110628114633-78h4k4q3d8jectjo --- addons/hr_holidays/hr_holidays.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/addons/hr_holidays/hr_holidays.py b/addons/hr_holidays/hr_holidays.py index 7074fd5cecc..4c000aab968 100644 --- a/addons/hr_holidays/hr_holidays.py +++ b/addons/hr_holidays/hr_holidays.py @@ -224,14 +224,20 @@ class hr_holidays(osv.osv): return True def holidays_validate(self, cr, uid, ids, *args): - self.check_holidays(cr, uid, ids) + context = {} + lang = self.pool.get('res.users').browse(cr, uid, uid).context_lang + context.update({'lang': lang}) + self.check_holidays(cr, uid, ids, context=context) obj_emp = self.pool.get('hr.employee') ids2 = obj_emp.search(cr, uid, [('user_id', '=', uid)]) manager = ids2 and ids2[0] or False return self.write(cr, uid, ids, {'state':'validate1', 'manager_id': manager}) def holidays_validate2(self, cr, uid, ids, *args): - self.check_holidays(cr, uid, ids) + context = {} + lang = self.pool.get('res.users').browse(cr, uid, uid).context_lang + context.update({'lang': lang}) + self.check_holidays(cr, uid, ids, context=context) obj_emp = self.pool.get('hr.employee') ids2 = obj_emp.search(cr, uid, [('user_id', '=', uid)]) manager = ids2 and ids2[0] or False @@ -277,7 +283,10 @@ class hr_holidays(osv.osv): return True def holidays_confirm(self, cr, uid, ids, *args): - self.check_holidays(cr, uid, ids) + context = {} + lang = self.pool.get('res.users').browse(cr, uid, uid).context_lang + context.update({'lang': lang}) + self.check_holidays(cr, uid, ids, context=context) return self.write(cr, uid, ids, {'state':'confirm'}) def holidays_refuse(self, cr, uid, ids, *args): @@ -302,8 +311,10 @@ class hr_holidays(osv.osv): return True - def check_holidays(self, cr, uid, ids): + def check_holidays(self, cr, uid, ids, context=None): holi_status_obj = self.pool.get('hr.holidays.status') + if context is None: + context = {} for record in self.browse(cr, uid, ids): if record.holiday_type == 'employee' and record.type == 'remove': if record.employee_id and not record.holiday_status_id.limit: From c2ba873ab842a98efa4f12cb9b73784c6fd577bc Mon Sep 17 00:00:00 2001 From: mtr Date: Thu, 30 Jun 2011 14:06:02 +0530 Subject: [PATCH 2/5] [IMP] hr_holidays: improved code for translation using context bzr revid: mtr@mtr-20110630083602-au21nsi3yyw97qnp --- addons/hr_holidays/hr_holidays.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/addons/hr_holidays/hr_holidays.py b/addons/hr_holidays/hr_holidays.py index 4c000aab968..3dfc9370ecc 100644 --- a/addons/hr_holidays/hr_holidays.py +++ b/addons/hr_holidays/hr_holidays.py @@ -224,9 +224,8 @@ class hr_holidays(osv.osv): return True def holidays_validate(self, cr, uid, ids, *args): - context = {} lang = self.pool.get('res.users').browse(cr, uid, uid).context_lang - context.update({'lang': lang}) + context = {'lang': lang} self.check_holidays(cr, uid, ids, context=context) obj_emp = self.pool.get('hr.employee') ids2 = obj_emp.search(cr, uid, [('user_id', '=', uid)]) @@ -234,9 +233,8 @@ class hr_holidays(osv.osv): return self.write(cr, uid, ids, {'state':'validate1', 'manager_id': manager}) def holidays_validate2(self, cr, uid, ids, *args): - context = {} lang = self.pool.get('res.users').browse(cr, uid, uid).context_lang - context.update({'lang': lang}) + context = {'lang': lang} self.check_holidays(cr, uid, ids, context=context) obj_emp = self.pool.get('hr.employee') ids2 = obj_emp.search(cr, uid, [('user_id', '=', uid)]) @@ -283,9 +281,8 @@ class hr_holidays(osv.osv): return True def holidays_confirm(self, cr, uid, ids, *args): - context = {} lang = self.pool.get('res.users').browse(cr, uid, uid).context_lang - context.update({'lang': lang}) + context = {'lang': lang} self.check_holidays(cr, uid, ids, context=context) return self.write(cr, uid, ids, {'state':'confirm'}) @@ -313,8 +310,6 @@ class hr_holidays(osv.osv): def check_holidays(self, cr, uid, ids, context=None): holi_status_obj = self.pool.get('hr.holidays.status') - if context is None: - context = {} for record in self.browse(cr, uid, ids): if record.holiday_type == 'employee' and record.type == 'remove': if record.employee_id and not record.holiday_status_id.limit: From a7e16487e484cffa2a0b817340808816c2ee139c Mon Sep 17 00:00:00 2001 From: Mustufa Rangwala Date: Thu, 30 Jun 2011 14:59:05 +0530 Subject: [PATCH 3/5] [IMP] Hr_holidays: Improve the code by making generic method for context lang get bzr revid: mra@mra-laptop-20110630092905-4ggbh1i7bnm7ibqb --- addons/hr_holidays/hr_holidays.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/addons/hr_holidays/hr_holidays.py b/addons/hr_holidays/hr_holidays.py index 3dfc9370ecc..7756e218ce0 100644 --- a/addons/hr_holidays/hr_holidays.py +++ b/addons/hr_holidays/hr_holidays.py @@ -223,9 +223,12 @@ class hr_holidays(osv.osv): wf_service.trg_create(uid, 'hr.holidays', id, cr) return True - def holidays_validate(self, cr, uid, ids, *args): + def get_user_lang(self, cr, uid, ids): lang = self.pool.get('res.users').browse(cr, uid, uid).context_lang - context = {'lang': lang} + return {'lang': lang} + + def holidays_validate(self, cr, uid, ids, *args): + context = self.get_user_lang(cr, uid, ids) self.check_holidays(cr, uid, ids, context=context) obj_emp = self.pool.get('hr.employee') ids2 = obj_emp.search(cr, uid, [('user_id', '=', uid)]) @@ -233,8 +236,7 @@ class hr_holidays(osv.osv): return self.write(cr, uid, ids, {'state':'validate1', 'manager_id': manager}) def holidays_validate2(self, cr, uid, ids, *args): - lang = self.pool.get('res.users').browse(cr, uid, uid).context_lang - context = {'lang': lang} + context = self.get_user_lang(cr, uid, ids) self.check_holidays(cr, uid, ids, context=context) obj_emp = self.pool.get('hr.employee') ids2 = obj_emp.search(cr, uid, [('user_id', '=', uid)]) @@ -281,8 +283,7 @@ class hr_holidays(osv.osv): return True def holidays_confirm(self, cr, uid, ids, *args): - lang = self.pool.get('res.users').browse(cr, uid, uid).context_lang - context = {'lang': lang} + context = self.get_user_lang(cr, uid, ids) self.check_holidays(cr, uid, ids, context=context) return self.write(cr, uid, ids, {'state':'confirm'}) From d93d0aa0faf14c043eaf7eebf1e49a1b65a0e16f Mon Sep 17 00:00:00 2001 From: mtr Date: Tue, 5 Jul 2011 12:41:51 +0530 Subject: [PATCH 4/5] [IMP] hr_holidays: passed context as an argument in all the methods() bzr revid: mtr@mtr-20110705071151-lhg6wqbphg9hoysw --- addons/hr_holidays/hr_holidays.py | 39 +++++++++++++------------ addons/hr_holidays/hr_holidays_view.xml | 12 ++++---- 2 files changed, 27 insertions(+), 24 deletions(-) diff --git a/addons/hr_holidays/hr_holidays.py b/addons/hr_holidays/hr_holidays.py index 7756e218ce0..e2cf2a5bace 100644 --- a/addons/hr_holidays/hr_holidays.py +++ b/addons/hr_holidays/hr_holidays.py @@ -161,7 +161,7 @@ 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) - def onchange_type(self, cr, uid, ids, holiday_type): + def onchange_type(self, cr, uid, ids, holiday_type, context=None): result = {'value': {'employee_id': False}} if holiday_type == 'employee': ids_employee = self.pool.get('hr.employee').search(cr, uid, [('user_id','=', uid)]) @@ -172,7 +172,7 @@ class hr_holidays(osv.osv): return result # TODO: can be improved using resource calendar method - def _get_number_of_days(self, date_from, date_to): + def _get_number_of_days(self, date_from, date_to, context=None): """Returns a float equals to the timedelta between two dates given as string.""" DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S" @@ -188,10 +188,12 @@ class hr_holidays(osv.osv): raise osv.except_osv(_('Warning!'),_('You cannot delete a leave which is not in draft state !')) return super(hr_holidays, self).unlink(cr, uid, ids, context) - def onchange_date_from(self, cr, uid, ids, date_to, date_from): + def onchange_date_from(self, cr, uid, ids, date_to, date_from, context=None): result = {} + if context is None: + context = {} if date_to and date_from: - diff_day = self._get_number_of_days(date_from, date_to) + diff_day = self._get_number_of_days(date_from, date_to, context=context) result['value'] = { 'number_of_days_temp': round(diff_day)+1 } @@ -212,7 +214,7 @@ class hr_holidays(osv.osv): } return {'warning': warning} - def set_to_draft(self, cr, uid, ids, *args): + def set_to_draft(self, cr, uid, ids, context=None): self.write(cr, uid, ids, { 'state': 'draft', 'manager_id': False, @@ -223,20 +225,18 @@ class hr_holidays(osv.osv): wf_service.trg_create(uid, 'hr.holidays', id, cr) return True - def get_user_lang(self, cr, uid, ids): - lang = self.pool.get('res.users').browse(cr, uid, uid).context_lang - return {'lang': lang} - - def holidays_validate(self, cr, uid, ids, *args): - context = self.get_user_lang(cr, uid, ids) + def holidays_validate(self, cr, uid, ids, context=None): + if context is None: + context = {} self.check_holidays(cr, uid, ids, context=context) obj_emp = self.pool.get('hr.employee') ids2 = obj_emp.search(cr, uid, [('user_id', '=', uid)]) manager = ids2 and ids2[0] or False return self.write(cr, uid, ids, {'state':'validate1', 'manager_id': manager}) - def holidays_validate2(self, cr, uid, ids, *args): - context = self.get_user_lang(cr, uid, ids) + def holidays_validate2(self, cr, uid, ids, context=None): + if context is None: + context = {} self.check_holidays(cr, uid, ids, context=context) obj_emp = self.pool.get('hr.employee') ids2 = obj_emp.search(cr, uid, [('user_id', '=', uid)]) @@ -282,20 +282,23 @@ class hr_holidays(osv.osv): wf_service.trg_validate(uid, 'hr.holidays', leave_id, 'second_validate', cr) return True - def holidays_confirm(self, cr, uid, ids, *args): - context = self.get_user_lang(cr, uid, ids) + def holidays_confirm(self, cr, uid, ids, context=None): + if context is None: + context = {} self.check_holidays(cr, uid, ids, context=context) return self.write(cr, uid, ids, {'state':'confirm'}) - def holidays_refuse(self, cr, uid, ids, *args): + def holidays_refuse(self, cr, uid, ids, context=None): + if context is None: + context = {} obj_emp = self.pool.get('hr.employee') ids2 = obj_emp.search(cr, uid, [('user_id', '=', uid)]) manager = ids2 and ids2[0] or False self.write(cr, uid, ids, {'state': 'refuse', 'manager_id2': manager}) - self.holidays_cancel(cr, uid, ids) + self.holidays_cancel(cr, uid, ids, context=context) return True - def holidays_cancel(self, cr, uid, ids, *args): + def holidays_cancel(self, cr, uid, ids, context=None): obj_crm_meeting = self.pool.get('crm.meeting') for record in self.browse(cr, uid, ids): # Delete the meeting diff --git a/addons/hr_holidays/hr_holidays_view.xml b/addons/hr_holidays/hr_holidays_view.xml index 608fda554fb..45f8aa8c3f5 100644 --- a/addons/hr_holidays/hr_holidays_view.xml +++ b/addons/hr_holidays/hr_holidays_view.xml @@ -71,7 +71,7 @@
- + @@ -83,8 +83,8 @@ - - + + @@ -115,7 +115,7 @@ - + @@ -181,8 +181,8 @@ - - + + From 9784142fe7bc141f9695dbf0d6d4ed7d18c08a67 Mon Sep 17 00:00:00 2001 From: mtr Date: Tue, 5 Jul 2011 14:45:25 +0530 Subject: [PATCH 5/5] [IMP] hr_holidays: removed condition checked for context and context passed in xml bzr revid: mtr@mtr-20110705091525-hm0772szzv6xa3zc --- addons/hr_holidays/hr_holidays.py | 10 ---------- addons/hr_holidays/hr_holidays_view.xml | 12 ++++++------ 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/addons/hr_holidays/hr_holidays.py b/addons/hr_holidays/hr_holidays.py index e2cf2a5bace..2fcd594bee0 100644 --- a/addons/hr_holidays/hr_holidays.py +++ b/addons/hr_holidays/hr_holidays.py @@ -190,8 +190,6 @@ class hr_holidays(osv.osv): def onchange_date_from(self, cr, uid, ids, date_to, date_from, context=None): result = {} - if context is None: - context = {} if date_to and date_from: diff_day = self._get_number_of_days(date_from, date_to, context=context) result['value'] = { @@ -226,8 +224,6 @@ class hr_holidays(osv.osv): return True def holidays_validate(self, cr, uid, ids, context=None): - if context is None: - context = {} self.check_holidays(cr, uid, ids, context=context) obj_emp = self.pool.get('hr.employee') ids2 = obj_emp.search(cr, uid, [('user_id', '=', uid)]) @@ -235,8 +231,6 @@ class hr_holidays(osv.osv): return self.write(cr, uid, ids, {'state':'validate1', 'manager_id': manager}) def holidays_validate2(self, cr, uid, ids, context=None): - if context is None: - context = {} self.check_holidays(cr, uid, ids, context=context) obj_emp = self.pool.get('hr.employee') ids2 = obj_emp.search(cr, uid, [('user_id', '=', uid)]) @@ -283,14 +277,10 @@ class hr_holidays(osv.osv): return True def holidays_confirm(self, cr, uid, ids, context=None): - if context is None: - context = {} self.check_holidays(cr, uid, ids, context=context) return self.write(cr, uid, ids, {'state':'confirm'}) def holidays_refuse(self, cr, uid, ids, context=None): - if context is None: - context = {} obj_emp = self.pool.get('hr.employee') ids2 = obj_emp.search(cr, uid, [('user_id', '=', uid)]) manager = ids2 and ids2[0] or False diff --git a/addons/hr_holidays/hr_holidays_view.xml b/addons/hr_holidays/hr_holidays_view.xml index 45f8aa8c3f5..608fda554fb 100644 --- a/addons/hr_holidays/hr_holidays_view.xml +++ b/addons/hr_holidays/hr_holidays_view.xml @@ -71,7 +71,7 @@ - + @@ -83,8 +83,8 @@ - - + + @@ -115,7 +115,7 @@ - + @@ -181,8 +181,8 @@ - - + +