diff --git a/addons/base_import/static/src/js/import.js b/addons/base_import/static/src/js/import.js index 407d38dacd7..510afaaead8 100644 --- a/addons/base_import/static/src/js/import.js +++ b/addons/base_import/static/src/js/import.js @@ -123,10 +123,10 @@ openerp.base_import = function (instance) { this.exit(); } }, - init: function (parent, params) { + init: function (parent, action) { var self = this; this._super.apply(this, arguments); - this.res_model = params.model; + this.res_model = action.params.model; // import object id this.id = null; this.Import = new instance.web.Model('base_import.import'); diff --git a/addons/hr/__openerp__.py b/addons/hr/__openerp__.py index cf3a7936657..b4b8e982845 100644 --- a/addons/hr/__openerp__.py +++ b/addons/hr/__openerp__.py @@ -24,7 +24,7 @@ 'version': '1.1', 'author': 'OpenERP SA', 'category': 'Human Resources', - 'sequence': 12, + 'sequence': 21, 'website': 'http://www.openerp.com', 'summary': 'Jobs, Departments, Employees Details', 'description': """ diff --git a/addons/hr_evaluation/__openerp__.py b/addons/hr_evaluation/__openerp__.py index fb3d87f2bc1..fb303ff28e4 100644 --- a/addons/hr_evaluation/__openerp__.py +++ b/addons/hr_evaluation/__openerp__.py @@ -24,6 +24,7 @@ 'version': '0.1', 'author': 'OpenERP SA', 'category': 'Human Resources', + 'sequence': 31, 'website': 'http://www.openerp.com', 'summary': 'Periodical Evaluations, Appraisals, Surveys', 'images': ['images/hr_evaluation_analysis.jpeg','images/hr_evaluation.jpeg'], diff --git a/addons/hr_expense/__openerp__.py b/addons/hr_expense/__openerp__.py index 4b273a9cc81..ec108b696bf 100644 --- a/addons/hr_expense/__openerp__.py +++ b/addons/hr_expense/__openerp__.py @@ -24,7 +24,7 @@ 'name': 'Expense Management', 'version': '1.0', 'category': 'Human Resources', - 'sequence': 30, + 'sequence': 29, 'summary': 'Expenses Validation, Invoicing', 'description': """ Manage expenses by Employees diff --git a/addons/hr_expense/hr_expense_view.xml b/addons/hr_expense/hr_expense_view.xml index dda977a8a93..fbaa4c1f87e 100644 --- a/addons/hr_expense/hr_expense_view.xml +++ b/addons/hr_expense/hr_expense_view.xml @@ -123,8 +123,8 @@ - - + + diff --git a/addons/hr_holidays/__openerp__.py b/addons/hr_holidays/__openerp__.py index 3cf4a30a2e1..417748d874b 100644 --- a/addons/hr_holidays/__openerp__.py +++ b/addons/hr_holidays/__openerp__.py @@ -25,7 +25,7 @@ 'version': '1.5', 'author': 'OpenERP SA', 'category': 'Human Resources', - 'sequence': 28, + 'sequence': 27, 'summary': 'Holidays, Allocation and Leave Requests', 'website': 'http://www.openerp.com', 'description': """ diff --git a/addons/hr_holidays/hr_holidays.py b/addons/hr_holidays/hr_holidays.py index 0977f3729b4..f315f3d4ef3 100644 --- a/addons/hr_holidays/hr_holidays.py +++ b/addons/hr_holidays/hr_holidays.py @@ -27,6 +27,7 @@ from operator import itemgetter import math import netsvc +import tools from osv import fields, osv from tools.translate import _ @@ -147,10 +148,10 @@ class hr_holidays(osv.osv): } _sql_constraints = [ ('type_value', "CHECK( (holiday_type='employee' AND employee_id IS NOT NULL) or (holiday_type='category' AND category_id IS NOT NULL))", "The employee or employee category of this request is missing."), - ('date_check2', "CHECK ( (type='add') OR (date_from <= date_to))", "The start date must be before the end date !"), - ('date_check', "CHECK ( number_of_days_temp >= 0 )", "The number of days must be greater than 0 !"), + ('date_check2', "CHECK ( (type='add') OR (date_from <= date_to))", "The start date must be anterior to the end date."), + ('date_check', "CHECK ( number_of_days_temp >= 0 )", "The number of days must be greater than 0."), ] - + def _create_resource_leave(self, cr, uid, leaves, context=None): '''This method will create entry in resource calendar leave object at the time of holidays validated ''' obj_res_leave = self.pool.get('resource.calendar.leaves') @@ -182,6 +183,13 @@ class hr_holidays(osv.osv): } return result + def onchange_employee(self, cr, uid, ids, employee_id): + result = {'value': {'department_id': False}} + if employee_id: + employee = self.pool.get('hr.employee').browse(cr, uid, employee_id) + result['value'] = {'department_id': employee.department_id.id} + return result + # TODO: can be improved using resource calendar method def _get_number_of_days(self, date_from, date_to): """Returns a float equals to the timedelta between two dates given as string.""" @@ -196,20 +204,53 @@ class hr_holidays(osv.osv): def unlink(self, cr, uid, ids, context=None): for rec in self.browse(cr, uid, ids, context=context): if rec.state not in ['draft', 'cancel', 'confirm']: - raise osv.except_osv(_('Warning!'),_('You cannot delete a leave which is in %s state!')%(rec.state)) + raise osv.except_osv(_('Warning!'),_('You cannot delete a leave which is in %s state.')%(rec.state)) return super(hr_holidays, self).unlink(cr, uid, ids, context) def onchange_date_from(self, cr, uid, ids, date_to, date_from): - result = {} - if date_to and date_from: + """ + If there are no date set for date_to, automatically set one 8 hours later than + the date_from. + Also update the number_of_days. + """ + # date_to has to be greater than date_from + if (date_from and date_to) and (date_from > date_to): + raise osv.except_osv(_('Warning!'),_('The start date must be anterior to the end date.')) + + result = {'value': {}} + + # No date_to set so far: automatically compute one 8 hours later + if date_from and not date_to: + date_to_with_delta = datetime.datetime.strptime(date_from, tools.DEFAULT_SERVER_DATETIME_FORMAT) + datetime.timedelta(hours=8) + result['value']['date_to'] = str(date_to_with_delta) + + # Compute and update the number of days + if (date_to and date_from) and (date_from <= date_to): diff_day = self._get_number_of_days(date_from, date_to) - result['value'] = { - 'number_of_days_temp': round(math.floor(diff_day))+1 - } - return result - result['value'] = { - 'number_of_days_temp': 0, - } + result['value']['number_of_days_temp'] = round(math.floor(diff_day))+1 + else: + result['value']['number_of_days_temp'] = 0 + + return result + + def onchange_date_to(self, cr, uid, ids, date_to, date_from): + """ + Update the number_of_days. + """ + + # date_to has to be greater than date_from + if (date_from and date_to) and (date_from > date_to): + raise osv.except_osv(_('Warning!'),_('The start date must be anterior to the end date.')) + + result = {'value': {}} + + # Compute and update the number of days + if (date_to and date_from) and (date_from <= date_to): + diff_day = self._get_number_of_days(date_from, date_to) + result['value']['number_of_days_temp'] = round(math.floor(diff_day))+1 + else: + result['value']['number_of_days_temp'] = 0 + return result def set_to_draft(self, cr, uid, ids, context=None): @@ -430,10 +471,10 @@ class hr_employee(osv.osv): def _get_remaining_days(self, cr, uid, ids, name, args, context=None): cr.execute("""SELECT sum(h.number_of_days) as days, - h.employee_id + h.employee_id from hr_holidays h - join hr_holidays_status s on (s.id=h.holiday_status_id) + join hr_holidays_status s on (s.id=h.holiday_status_id) where h.state='validate' and s.limit=False and @@ -448,9 +489,9 @@ class hr_employee(osv.osv): remaining[employee_id] = 0.0 return remaining - def _get_leave_status(self, cr, uid, ids, name, args, context=None): + def _get_leave_status(self, cr, uid, ids, name, args, context=None): holidays_obj = self.pool.get('hr.holidays') - holidays_id = holidays_obj.search(cr, uid, + holidays_id = holidays_obj.search(cr, uid, [('employee_id', 'in', ids), ('date_from','<=',time.strftime('%Y-%m-%d %H:%M:%S')), ('date_to','>=',time.strftime('%Y-%m-%d 23:59:59')),('type','=','remove'),('state','not in',('cancel','refuse'))], context=context) @@ -476,7 +517,7 @@ class hr_employee(osv.osv): ('validate1', 'Waiting Second Approval'), ('validate', 'Approved'), ('cancel', 'Cancelled')]), 'current_leave_id': fields.function(_get_leave_status, multi="leave_status", string="Current Leave Type",type='many2one', relation='hr.holidays.status'), 'leave_date_from': fields.function(_get_leave_status, multi='leave_status', type='date', string='From Date'), - 'leave_date_to': fields.function(_get_leave_status, multi='leave_status', type='date', string='To Date'), + 'leave_date_to': fields.function(_get_leave_status, multi='leave_status', type='date', string='To Date'), } hr_employee() diff --git a/addons/hr_holidays/hr_holidays_view.xml b/addons/hr_holidays/hr_holidays_view.xml index e92679e0bad..4691f7ebd71 100644 --- a/addons/hr_holidays/hr_holidays_view.xml +++ b/addons/hr_holidays/hr_holidays_view.xml @@ -13,9 +13,9 @@ action_holidays_unread - + action - + hr.holidays client_action_multi @@ -31,9 +31,9 @@ action_holidays_read - + action - + hr.holidays client_action_multi @@ -83,7 +83,7 @@ - + Leave Request hr.holidays 1 @@ -93,7 +93,7 @@