diff options
| author | Aaron Bohy <aab@odoo.com> | 2017-04-13 22:18:20 +0200 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2017-04-14 22:35:27 +0200 |
| commit | 2eda2a7296dd5aeaeae3cea82736d72534a22e1f (patch) | |
| tree | 3decb531c6bb366031dd8d8d585e55b641c928bf | |
| parent | b9c76ddab580399513b602311c6b9d94eb3046e6 (diff) | |
[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@158f779b46ff0e854a548179d8d9749cd9cf0162)
4 files changed, 63 insertions, 31 deletions
diff --git a/addons/hr_attendance/static/src/js/field_widget.js b/addons/hr_attendance/static/src/js/field_widget.js deleted file mode 100644 index f8a884702f7..00000000000 --- a/addons/hr_attendance/static/src/js/field_widget.js +++ /dev/null @@ -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); - -}); diff --git a/addons/hr_attendance/static/src/js/my_attendances.js b/addons/hr_attendance/static/src/js/my_attendances.js index 083fa94220e..a1e11c05f40 100644 --- a/addons/hr_attendance/static/src/js/my_attendances.js +++ b/addons/hr_attendance/static/src/js/my_attendances.js @@ -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) ) { diff --git a/addons/hr_attendance/static/tests/hr_attendance_tests.js b/addons/hr_attendance/static/tests/hr_attendance_tests.js new file mode 100644 index 00000000000..0f09069048c --- /dev/null +++ b/addons/hr_attendance/static/tests/hr_attendance_tests.js @@ -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(); + }); + +}); + +}); diff --git a/addons/hr_attendance/views/web_asset_backend_template.xml b/addons/hr_attendance/views/web_asset_backend_template.xml index 7fd986c7ac2..4263a3f314d 100644 --- a/addons/hr_attendance/views/web_asset_backend_template.xml +++ b/addons/hr_attendance/views/web_asset_backend_template.xml @@ -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> |
