[IMP] hr_attendance: visual improvements

bzr revid: nicolas.vanhoren@openerp.com-20120907143044-czya93nj76yx2ofg
This commit is contained in:
niv-openerp 2012-09-07 16:30:44 +02:00
commit ce11811c05
2 changed files with 24 additions and 4 deletions

View File

@ -112,9 +112,23 @@ class hr_employee(osv.osv):
for res in cr.fetchall():
result[res[1]] = res[0] == 'sign_in' and 'present' or 'absent'
return result
def _last_sign(self, cr, uid, ids, name, args, context=None):
result = {}
if not ids:
return result
for id in ids:
result[id] = False
cr.execute("""select max(name) as name
from hr_attendance
where action in ('sign_in', 'sign_out') and employee_id = %s""",(id,))
for res in cr.fetchall():
result[id] = res[0]
return result
_columns = {
'state': fields.function(_state, type='selection', selection=[('absent', 'Absent'), ('present', 'Present')], string='Attendance'),
'last_sign': fields.function(_last_sign, type='datetime', string='Last Sign'),
}
def _action_check(self, cr, uid, emp_id, dt=False, context=None):

View File

@ -27,12 +27,16 @@ openerp.hr_attendance = function (instance) {
});
this.$el.tipsy({
title: function() {
var last_text = instance.web.format_value(self.last_sign, {type: "datetime"});
var current_text = instance.web.format_value(new Date(), {type: "datetime"});
var duration = $.timeago(self.last_sign);
if (self.get("signed_in")) {
return _t("You are currently signed in. Click here to sign out.");
return _.str.sprintf(_t("Last sign in: %s,<br />%s.<br />Click to sign out."), last_text, duration);
} else {
return _t("You are currently signed out. Click here to sign in.");
return _.str.sprintf(_t("Click to Sign In at %s."), current_text);
}
}
},
html: true,
});
return this.check_attendance();
},
@ -42,6 +46,7 @@ openerp.hr_attendance = function (instance) {
hr_employee.call('attendance_action_change', [
[self.employee.id]
]).done(function (result) {
self.last_sign = new Date();
self.set({"signed_in": ! self.get("signed_in")});
});
},
@ -52,11 +57,12 @@ openerp.hr_attendance = function (instance) {
var employee = new instance.web.DataSetSearch(self, 'hr.employee', self.session.user_context, [
['user_id', '=', self.session.uid]
]);
return employee.read_slice(['id', 'name', 'state']).pipe(function (res) {
return employee.read_slice(['id', 'name', 'state', 'last_sign']).pipe(function (res) {
if (_.isEmpty(res))
return;
self.$el.show();
self.employee = res[0];
self.last_sign = instance.web.str_to_datetime(self.employee.last_sign);
self.set({"signed_in": self.employee.state !== "absent"});
});
},