diff --git a/addons/hr_attendance/static/src/js/greeting_message.js b/addons/hr_attendance/static/src/js/greeting_message.js index 113012dbb18..c0f120983ad 100644 --- a/addons/hr_attendance/static/src/js/greeting_message.js +++ b/addons/hr_attendance/static/src/js/greeting_message.js @@ -1,6 +1,8 @@ odoo.define('hr_attendance.greeting_message', function (require) { "use strict"; +var BarcodeHandlerMixin = require('barcodes.BarcodeHandlerMixin'); + var core = require('web.core'); var Model = require('web.Model'); var Widget = require('web.Widget'); @@ -8,27 +10,39 @@ var Widget = require('web.Widget'); var _t = core._t; -var GreetingMessage = Widget.extend({ +var GreetingMessage = Widget.extend(BarcodeHandlerMixin, { template: 'HrAttendanceGreetingMessage', events: { - "click .o_hr_attendance_button_dismiss": function () { this.do_action(this.next_action, {clear_breadcrumbs: true}); }, + "click .o_hr_attendance_button_dismiss": function() { this.do_action(this.next_action, {clear_breadcrumbs: true}); }, }, init: function(parent, action) { - this._super.apply(this, arguments); var self = this; - var default_action = { type: "ir.actions.client", name: 'Attendances', tag: 'hr_attendance_my_attendances', params: {} }; - if(!action.attendance){ - self.session.user_has_group('hr_attendance.group_hr_attendance_user').then(function(has_group){ - if(has_group){ - self.next_action = { type: "ir.actions.client", name: 'Attendances', tag: 'hr_attendance_kiosk_mode', target: 'fullscreen', params: {} }; + this._super.apply(this, arguments); + BarcodeHandlerMixin.init.apply(this, arguments); + + // if no correct action given (due to an erroneous back or refresh from the browser), we set the dismiss button to return + // to the (likely) appropriate menu, according to the user access rights + if(!action.attendance) { + this.stop_listening(); + this.session.user_has_group('hr_attendance.group_hr_attendance_user').then(function(has_group) { + if(has_group) { + self.next_action = 'hr_attendance.hr_attendance_action_kiosk_mode'; + } else { + self.next_action = 'hr_attendance.hr_attendance_action_my_attendances'; } }); return; } - this.next_action = action.next_action || default_action; + + this.next_action = action.next_action || 'hr_attendance.hr_attendance_action_my_attendances'; + // no listening to barcode scans if we aren't coming from the kiosk mode (and thus not going back to it with next_action) + if (this.next_action != 'hr_attendance.hr_attendance_action_kiosk_mode' && this.next_action.tag != 'hr_attendance_kiosk_mode') { + this.stop_listening(); + } this.attendance = action.attendance; + // check in/out times displayed in the greeting message template. this.attendance.check_in_time = (new Date((new Date(this.attendance.check_in)).valueOf() - (new Date()).getTimezoneOffset()*60*1000)).toTimeString().slice(0,8); this.attendance.check_out_time = this.attendance.check_out && (new Date((new Date(this.attendance.check_out)).valueOf() - (new Date()).getTimezoneOffset()*60*1000)).toTimeString().slice(0,8); this.previous_attendance_change_date = action.previous_attendance_change_date; @@ -36,48 +50,42 @@ var GreetingMessage = Widget.extend({ }, start: function() { - if (!this.attendance){ - return; - } - if (this.attendance.check_out) { - this.farewell_message(); - } else { - this.welcome_message(); + if (this.attendance) { + this.attendance.check_out ? this.farewell_message() : this.welcome_message(); } }, welcome_message: function() { var self = this; var now = new Date((new Date(this.attendance.check_in)).valueOf() - (new Date()).getTimezoneOffset()*60*1000); - self.return_to_main_menu = setTimeout( function() { self.do_action(self.next_action, {clear_breadcrumbs: true}); }, 5000); + this.return_to_main_menu = setTimeout( function() { self.do_action(self.next_action, {clear_breadcrumbs: true}); }, 5000); - if(now.getHours()<5){ - self.$('.o_hr_attendance_message_message').append(_t("Good night")); - } else if(now.getHours() < 12){ - if(now.getHours() < 8 && Math.random() < .3){ - if(Math.random()<.75){ - self.$('.o_hr_attendance_message_message').append(_t("The early bird catches the worm")); + if (now.getHours() < 5) { + this.$('.o_hr_attendance_message_message').append(_t("Good night")); + } else if (now.getHours() < 12) { + if (now.getHours() < 8 && Math.random() < 0.3) { + if (Math.random() < 0.75) { + this.$('.o_hr_attendance_message_message').append(_t("The early bird catches the worm")); } else { - self.$('.o_hr_attendance_message_message').append(_t("First come, first served")); + this.$('.o_hr_attendance_message_message').append(_t("First come, first served")); } - } else { - self.$('.o_hr_attendance_message_message').append(_t("Good morning")); + this.$('.o_hr_attendance_message_message').append(_t("Good morning")); } - } else if(now.getHours()<17){ - self.$('.o_hr_attendance_message_message').append(_t("Good afternoon")); - } else if(now.getHours()<23){ - self.$('.o_hr_attendance_message_message').append(_t("Good evening")); + } else if (now.getHours() < 17){ + this.$('.o_hr_attendance_message_message').append(_t("Good afternoon")); + } else if (now.getHours() < 23){ + this.$('.o_hr_attendance_message_message').append(_t("Good evening")); } else { - self.$('.o_hr_attendance_message_message').append(_t("Good night")); + this.$('.o_hr_attendance_message_message').append(_t("Good night")); } if(this.previous_attendance_change_date){ var last_check_out_date = new Date((new Date(this.previous_attendance_change_date)).valueOf() - (new Date()).getTimezoneOffset()*60*1000); if(now.valueOf() - last_check_out_date.valueOf() > 1000*60*60*24*7){ - self.$('.o_hr_attendance_random_message').html(_t("Glad to have you back, it's been a while!")); + this.$('.o_hr_attendance_random_message').html(_t("Glad to have you back, it's been a while!")); } else { - if(Math.random() < .02){ - self.$('.o_hr_attendance_random_message').html(_t("If a job is worth doing, it is worth doing well!")); + if(Math.random() < 0.02){ + this.$('.o_hr_attendance_random_message').html(_t("If a job is worth doing, it is worth doing well!")); } } } @@ -86,38 +94,55 @@ var GreetingMessage = Widget.extend({ farewell_message: function() { var self = this; var now = new Date((new Date(this.attendance.check_out)).valueOf() - (new Date()).getTimezoneOffset()*60*1000); - self.return_to_main_menu = setTimeout( function() { self.do_action(self.next_action, {clear_breadcrumbs: true}); }, 5000); + this.return_to_main_menu = setTimeout( function() { self.do_action(self.next_action, {clear_breadcrumbs: true}); }, 5000); if(this.previous_attendance_change_date){ var last_check_in_date = new Date((new Date(this.previous_attendance_change_date)).valueOf() - (new Date()).getTimezoneOffset()*60*1000); if(now.valueOf() - last_check_in_date.valueOf() > 1000*60*60*12){ - self.$('.o_hr_attendance_warning_message').append(_t("Warning! Last check in was over 12 hours ago.
If this isn't right, please contact Human Resources.")); - clearTimeout(self.return_to_main_menu); + this.$('.o_hr_attendance_warning_message').append(_t("Warning! Last check in was over 12 hours ago.
If this isn't right, please contact Human Resources.")); + clearTimeout(this.return_to_main_menu); + this.stop_listening(); } else if(now.valueOf() - last_check_in_date.valueOf() > 1000*60*60*8){ - self.$('.o_hr_attendance_random_message').html(_t("Another good day's work! See you soon!")); + this.$('.o_hr_attendance_random_message').html(_t("Another good day's work! See you soon!")); } } - if(now.getHours()<12){ - self.$('.o_hr_attendance_message_message').append(_t("Have a good day!")); - } else if(now.getHours()<14){ - self.$('.o_hr_attendance_message_message').append(_t("Have a nice lunch!")); - if(Math.random() < 0.05){ - self.$('.o_hr_attendance_random_message').html(_t("Eat breakfast as a king, lunch as a merchant and supper as a beggar")); - } else if(Math.random() < 0.06){ - self.$('.o_hr_attendance_random_message').html(_t("An apple a day keeps the doctor away")); + if (now.getHours() < 12) { + this.$('.o_hr_attendance_message_message').append(_t("Have a good day!")); + } else if (now.getHours() < 14) { + this.$('.o_hr_attendance_message_message').append(_t("Have a nice lunch!")); + if (Math.random() < 0.05) { + this.$('.o_hr_attendance_random_message').html(_t("Eat breakfast as a king, lunch as a merchant and supper as a beggar")); + } else if (Math.random() < 0.06) { + this.$('.o_hr_attendance_random_message').html(_t("An apple a day keeps the doctor away")); } - } else if(now.getHours()<17){ - self.$('.o_hr_attendance_message_message').append(_t("Have a good afternoon")); + } else if (now.getHours() < 17) { + this.$('.o_hr_attendance_message_message').append(_t("Have a good afternoon")); } else { - if(now.getHours()<18 && Math.random()<0.2){ - self.$('.o_hr_attendance_message_message').append(_t("Early to bed and early to rise, makes a man healthy, wealthy and wise")); + if (now.getHours() < 18 && Math.random() < 0.2) { + this.$('.o_hr_attendance_message_message').append(_t("Early to bed and early to rise, makes a man healthy, wealthy and wise")); } else { - self.$('.o_hr_attendance_message_message').append(_t("Have a good evening")); + this.$('.o_hr_attendance_message_message').append(_t("Have a good evening")); } } }, + on_barcode_scanned: function(barcode) { + var self = this; + if (this.return_to_main_menu) { // in case of multiple scans in the greeting message view, delete the timer, a new one will be created. + clearTimeout(this.return_to_main_menu); + } + var hr_employee = new Model('hr.employee'); + hr_employee.call('attendance_scan', [barcode, ]) + .then(function (result) { + if (result.action) { + self.do_action(result.action); + } else if (result.warning) { + self.do_warn(result.warning); + } + }); + }, + destroy: function () { clearTimeout(this.return_to_main_menu); this._super.apply(this, arguments); diff --git a/addons/hr_attendance/static/src/js/kiosk_confirm.js b/addons/hr_attendance/static/src/js/kiosk_confirm.js index 60e75b73328..f8d113d27d6 100644 --- a/addons/hr_attendance/static/src/js/kiosk_confirm.js +++ b/addons/hr_attendance/static/src/js/kiosk_confirm.js @@ -55,7 +55,7 @@ var KioskConfirm = Widget.extend({ init: function (parent, action) { this._super.apply(this, arguments); - this.next_action = { type: "ir.actions.client", name: "Attendances", tag: 'hr_attendance_kiosk_mode', target: "fullscreen", params: {} }; + this.next_action = 'hr_attendance.hr_attendance_action_kiosk_mode'; this.employee_id = action.employee_id; this.employee_name = action.employee_name; this.employee_state = action.employee_state;