diff --git a/addons/hr_attendance/static/src/js/attendance.js b/addons/hr_attendance/static/src/js/attendance.js index 84516353b9d..281822361ef 100644 --- a/addons/hr_attendance/static/src/js/attendance.js +++ b/addons/hr_attendance/static/src/js/attendance.js @@ -60,7 +60,7 @@ openerp.hr_attendance = function (instance) { return employee.read_slice(['id', 'name', 'state', 'last_sign', 'attendance_access']).then(function (res) { if (_.isEmpty(res) ) return; - if (res[0].attendance_access == false){ + if (res[0].attendance_access === false){ return; } self.$el.show(); @@ -72,16 +72,36 @@ openerp.hr_attendance = function (instance) { }); instance.web.UserMenu.include({ + + is_employee: function() { + var self = this; + if (_.isUndefined(self._is_employee)) { + var Users = new instance.web.Model('res.users'); + return Users.query(['employee']).filter([['id', '=', self.session.uid]]).all().then(function(records) { + if (_.isEmpty(records)) { + self._is_employee = false; + } else { + self._is_employee = records[0].employee; + } + return self._is_employee; + }); + } else { + return $.Deferred().resolve(self._is_employee).promise(); + } + }, + do_update: function () { this._super(); var self = this; - this.update_promise = this.update_promise.done(function () { - if (self.attendanceslider) - return; - self.attendanceslider = new instance.hr_attendance.AttendanceSlider(self); - - self.attendanceslider.prependTo(instance.webclient.$('.oe_systray')); + this.update_promise.done(function () { + $.when(self.is_employee()).done(function(is_employee) { + if (!is_employee || self.attendanceslider) { + return; + } + self.attendanceslider = new instance.hr_attendance.AttendanceSlider(self); + self.attendanceslider.prependTo(instance.webclient.$('.oe_systray')); + }); }); }, }); -} +};