From 280d9e426d3e8e778ed6d1f5c97d4a7d42bfce31 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Fri, 7 Sep 2012 14:23:37 +0200 Subject: [PATCH] [IMP] changed tooltip bzr revid: nicolas.vanhoren@openerp.com-20120907122337-pb8pia5e753zzi32 --- addons/hr_attendance/hr_attendance.py | 14 ++++++++++++++ addons/hr_attendance/static/src/js/attendance.js | 14 ++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/addons/hr_attendance/hr_attendance.py b/addons/hr_attendance/hr_attendance.py index ae05a6143fd..d3bc79bda1a 100644 --- a/addons/hr_attendance/hr_attendance.py +++ b/addons/hr_attendance/hr_attendance.py @@ -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): diff --git a/addons/hr_attendance/static/src/js/attendance.js b/addons/hr_attendance/static/src/js/attendance.js index f05cef2e001..0366fa47c6c 100644 --- a/addons/hr_attendance/static/src/js/attendance.js +++ b/addons/hr_attendance/static/src/js/attendance.js @@ -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,
%s.
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"}); }); },