Odoo JS/XML Example Sign in Sign out Attedance
Odoo 10
Dropbox Module: Dropbox/Help OE/Odoo_JS_10/sign_in_out and Dropbox/Help OE/Odoo_JS_10/display_clock
XML File
<template >
<t t-name="sign_in_out.SignUp">
<span style="color:white"><a class="fa btn-primary fa-sign-out fa-sign-in"/></span>
</t>
<t t-name="SignOut">
<span style="color:white"><a class="fa btn-primary fa-sign-out fa-sign-out"/></span>
</t>
</template>
JS File
odoo.define('sign_in_out',function(require) {
"use strict";
var Session = require('web.session');
var core = require('web.core');
var SystrayMenu = require('web.SystrayMenu');
var Widget = require('web.Widget');
var Model = require('web.Model');
var chat_manager = require('mail.chat_manager');
var QWeb = core.qweb;
var _t = core._t;
var SignUp = Widget.extend({
template:'sign_in_out.SignUp',
init: function() {
},
events: {
"click": "on_click",
},
on_click: function (event) {
var self = this;
var atendance = new Model('hr.attendance');
var sign = new Model('sign.out');
sign.call('login')
self.$el.html(QWeb.render("SignOut"));
},
});
SystrayMenu.Items.push(SignUp);
return SignUp;
});
Python File
from datetime import datetime
from odoo import models, fields, api, exceptions, _, SUPERUSER_ID
class SigninOut(models.Model):
_name = 'sign.out'
@api.model
def login(self):
employee = self.env['hr.employee'].search([('user_id', '=', self.env.uid)], limit=1)
action_date = fields.Datetime.now()
if employee.attendance_state != 'checked_in':
vals = {
'employee_id': self.env.uid,
'check_in': action_date,
}
self.env['hr.attendance'].create(vals)
return True
else:
attendance = self.env['hr.attendance'].search([('employee_id', '=', self.env.uid), ('check_out', '=', False)], limit=1)
if attendance:
attendance.check_out = action_date
else:
raise exceptions.UserError(_('Cannot perform check out on %(empl_name)s, could not find corresponding check in. '
'Your attendances have probably been modified manually by human resources.') % {'empl_name': self.name, })
return True