[FIX] hr_attendance: check the user is an employee by checking if (s)he belongs to the "Employee" group

bzr revid: chs@openerp.com-20121214152453-tvtjuvvmefw9qcrp
This commit is contained in:
Christophe Simonis 2012-12-14 16:24:53 +01:00
parent e8832cb0cb
commit 539af8a8f0
1 changed files with 11 additions and 23 deletions

View File

@ -72,34 +72,22 @@ 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.done(function () {
$.when(self.is_employee()).done(function(is_employee) {
if (!is_employee || self.attendanceslider) {
return;
if (_.isUndefined(self.attendanceslider)) {
return;
}
// check current user is an employee
var Users = new instance.web.Model('res.users');
Users.call('has_group', ['base.group_user']).done(function(is_employee) {
if (is_employee) {
self.attendanceslider = new instance.hr_attendance.AttendanceSlider(self);
self.attendanceslider.prependTo(instance.webclient.$('.oe_systray'));
} else {
self.attendanceslider = null;
}
self.attendanceslider = new instance.hr_attendance.AttendanceSlider(self);
self.attendanceslider.prependTo(instance.webclient.$('.oe_systray'));
});
});
},