[FIX] hr_attendance: crash when opening the app

'session' is no longer an widget attribute, 'getSession()' should
be used instead.

Also remove a dead JS field widget (not used since
odoo/odoo@158f779b46)
This commit is contained in:
Aaron Bohy
2017-04-14 22:35:27 +02:00
parent b9c76ddab5
commit 2eda2a7296
4 changed files with 63 additions and 31 deletions
@@ -1,29 +0,0 @@
odoo.define('hr_attendance.field_widget', function (require) {
"use strict";
var AbstractField = require('web.AbstractField');
var core = require('web.core');
var field_registry = require('web.field_registry');
var _t = core._t;
var PresenceIndicator = AbstractField.extend({
template: 'PresenceIndicator',
start: function() {
this.$el.tooltip({title: _t("Employee Presence<br/>Green: checked in<br/>Red: checked out"), trigger: 'hover'});
return this._super();
},
render: function() {
this.$el.toggleClass("oe_hr_attendance_status_green", this.value === 'checked_in');
this.$el.toggleClass("oe_hr_attendance_status_red", this.value === 'checked_out');
},
is_set: function() {
return true;
}
});
field_registry.add('hr_attendance_form_presence_indicator', PresenceIndicator);
});
@@ -22,7 +22,7 @@ var MyAttendances = Widget.extend({
this._rpc({
model: 'hr.employee',
method: 'search_read',
args: [[['user_id', '=', self.session.uid]], ['attendance_state', 'name']],
args: [[['user_id', '=', self.getSession().uid]], ['attendance_state', 'name']],
})
.then(function (res) {
if (_.isEmpty(res) ) {
@@ -0,0 +1,56 @@
odoo.define('hr_attendance.tests', function (require) {
"use strict";
var testUtils = require('web.test_utils');
var MyAttendances = require('hr_attendance.my_attendances');
QUnit.module('HR Attendance', {
beforeEach: function () {
this.data = {
'hr.employee': {
fields: {
name: {string: 'Name', type: 'char'},
attendance_state: {
string: 'State',
type: 'selection',
selection: [[1, "In"], [2, "Out"]],
default: 1,
},
user_id: {string: 'user ID', type: 'integer'},
},
records: [{
id: 1,
name: "Employee A",
attendance_state: 1,
user_id: 1,
}],
},
};
},
}, function () {
QUnit.module('My attendances (client action)');
QUnit.test('simple rendering', function (assert) {
assert.expect(1);
var $target = $('#qunit-fixture');
var clientAction = new MyAttendances(null);
testUtils.addMockEnvironment(clientAction, {
data: this.data,
session: {
uid: 1,
},
});
clientAction.appendTo($target);
assert.strictEqual(clientAction.$('.o_hr_attendance_kiosk_mode h1').text(), 'Welcome Employee A',
"should have rendered the client action without crashing");
clientAction.destroy();
});
});
});
@@ -3,7 +3,6 @@
<template id="assets_backend" name="hr_attendance assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/hr_attendance/static/src/js/employee_kanban_view_handler.js"></script>
<script type="text/javascript" src="/hr_attendance/static/src/js/field_widget.js"></script>
<script type="text/javascript" src="/hr_attendance/static/src/js/greeting_message.js"></script>
<script type="text/javascript" src="/hr_attendance/static/src/js/kiosk_mode.js"></script>
<script type="text/javascript" src="/hr_attendance/static/src/js/kiosk_confirm.js"></script>
@@ -11,4 +10,10 @@
<link rel="stylesheet" href="/hr_attendance/static/src/less/hr_attendance.less"/>
</xpath>
</template>
<template id="qunit_suite" name="hr attendance tests" inherit_id="web.qunit_suite">
<xpath expr="//script[contains(@src, '/web/static/tests/views/kanban_tests.js')]" position="after">
<script type="text/javascript" src="/hr_attendance/static/tests/hr_attendance_tests.js"></script>
</xpath>
</template>
</odoo>