-
-
-
+
+
diff --git a/addons/hr_org_chart/static/src/js/hr_org_chart.js b/addons/hr_org_chart/static/src/js/hr_org_chart.js
deleted file mode 100644
index 783abd91894..00000000000
--- a/addons/hr_org_chart/static/src/js/hr_org_chart.js
+++ /dev/null
@@ -1,199 +0,0 @@
-odoo.define('web.OrgChart', function (require) {
-"use strict";
-
-var AbstractField = require('web.AbstractField');
-var concurrency = require('web.concurrency');
-var core = require('web.core');
-var field_registry = require('web.field_registry');
-var session = require('web.session');
-
-var QWeb = core.qweb;
-var _t = core._t;
-
-var FieldOrgChart = AbstractField.extend({
-
- events: {
- "click .o_employee_redirect": "_onEmployeeRedirect",
- "click .o_employee_sub_redirect": "_onEmployeeSubRedirect",
- "click .o_employee_more_managers": "_onEmployeeMoreManager"
- },
- /**
- * @constructor
- * @override
- */
- init: function (parent, options) {
- this._super.apply(this, arguments);
- this.dm = new concurrency.DropMisordered();
- this.employee = null;
- },
-
- //--------------------------------------------------------------------------
- // Private
- //--------------------------------------------------------------------------
- /**
- * Get the chart data through a rpc call.
- *
- * @private
- * @param {integer} employee_id
- * @returns {Promise}
- */
- _getOrgData: function () {
- return this.dm.add(this._rpc({
- route: '/hr/get_org_chart',
- params: {
- employee_id: this.employee,
- context: session.user_context,
- },
- })).then(function (data) {
- return data;
- });
- },
- /**
- * Get subordonates of an employee through a rpc call.
- *
- * @private
- * @param {integer} employee_id
- * @returns {Promise}
- */
- _getSubordinatesData: function (employee_id, type) {
- return this.dm.add(this._rpc({
- route: '/hr/get_subordinates',
- params: {
- employee_id: employee_id,
- subordinates_type: type,
- context: session.user_context,
- },
- }));
- },
- /**
- * @override
- * @private
- */
- _render: function () {
- if (!this.recordData.id) {
- return this.$el.html(QWeb.render("hr_org_chart", {
- managers: [],
- children: [],
- }));
- }
- else if (!this.employee) {
- // the widget is either dispayed in the context of a hr.employee form or a res.users form
- this.employee = this.recordData.employee_ids !== undefined ? this.recordData.employee_ids.res_ids[0] : this.recordData.id;
- }
-
- var self = this;
- return this._getOrgData().then(function (orgData) {
- if (_.isEmpty(orgData)) {
- orgData = {
- managers: [],
- children: [],
- }
- }
- orgData.view_employee_id = self.recordData.id;
- self.$el.html(QWeb.render("hr_org_chart", orgData));
- self.$('[data-bs-toggle="popover"]').each(function () {
- $(this).popover({
- html: true,
- title: function () {
- var $title = $(QWeb.render('hr_orgchart_emp_popover_title', {
- employee: {
- name: $(this).data('emp-name'),
- id: $(this).data('emp-id'),
- },
- }));
- $title.on('click',
- '.o_employee_redirect', _.bind(self._onEmployeeRedirect, self));
- return $title;
- },
- container: this,
- placement: 'left',
- trigger: 'focus',
- content: function () {
- var $content = $(QWeb.render('hr_orgchart_emp_popover_content', {
- employee: {
- id: $(this).data('emp-id'),
- name: $(this).data('emp-name'),
- direct_sub_count: parseInt($(this).data('emp-dir-subs')),
- indirect_sub_count: parseInt($(this).data('emp-ind-subs')),
- },
- }));
- $content.on('click',
- '.o_employee_sub_redirect', _.bind(self._onEmployeeSubRedirect, self));
- return $content;
- },
- template: QWeb.render('hr_orgchart_emp_popover', {}),
- });
- });
- });
- },
-
- //--------------------------------------------------------------------------
- // Handlers
- //--------------------------------------------------------------------------
-
- _onEmployeeMoreManager: function(event) {
- event.preventDefault();
- this.employee = parseInt($(event.currentTarget).data('employee-id'));
- this._render();
- },
- /**
- * Redirect to the employee form view.
- *
- * @private
- * @param {MouseEvent} event
- * @returns {Promise} action loaded
- */
- _onEmployeeRedirect: function (event) {
- var self = this;
- event.preventDefault();
- var employee_id = parseInt($(event.currentTarget).data('employee-id'));
- return this._rpc({
- model: 'hr.employee',
- method: 'get_formview_action',
- args: [employee_id],
- }).then(function(action) {
- return self.do_action(action);
- });
- },
- /**
- * Redirect to the sub employee form view.
- *
- * @private
- * @param {MouseEvent} event
- * @returns {Promise} action loaded
- */
- _onEmployeeSubRedirect: function (event) {
- event.preventDefault();
- var employee_id = parseInt($(event.currentTarget).data('employee-id'));
- var type = $(event.currentTarget).data('type') || 'direct';
- var self = this;
- if (employee_id) {
- this._getSubordinatesData(employee_id, type).then(function(data) {
- var domain = [['id', 'in', data]];
- return self._rpc({
- model: 'hr.employee',
- method: 'get_formview_action',
- args: [employee_id],
- }).then(function(action) {
- action = _.extend(action, {
- 'name': _t('Team'),
- 'view_mode': 'kanban,list,form',
- 'views': [[false, 'kanban'], [false, 'list'], [false, 'form']],
- 'domain': domain,
- 'context': {
- 'default_parent_id': employee_id,
- }
- });
- delete action['res_id'];
- return self.do_action(action);
- });
- });
- }
- },
-});
-
-field_registry.add('hr_org_chart', FieldOrgChart);
-
-return FieldOrgChart;
-
-});
diff --git a/addons/hr_org_chart/static/tests/hr_org_chart_tests.js b/addons/hr_org_chart/static/tests/hr_org_chart_tests.js
index d8de512d14e..dc5864a1e4b 100644
--- a/addons/hr_org_chart/static/tests/hr_org_chart_tests.js
+++ b/addons/hr_org_chart/static/tests/hr_org_chart_tests.js
@@ -1,38 +1,42 @@
-odoo.define('hr_org_chart.tests', function (require) {
-"use strict";
+/** @odoo-module **/
-var FormView = require('web.FormView');
-var testUtils = require("web.test_utils");
+import { getFixture } from "@web/../tests/helpers/utils";
+import { makeView, setupViewRegistries } from "@web/../tests/views/helpers";
-var createView = testUtils.createView;
+let target;
+let serverData;
-QUnit.module('hr_org_chart', {
- before: function () {
- this.data = {
- hr_employee: {
- fields: {
- child_ids: {string: "one2many Subordinates field", type: "one2many", relation: 'hr_employee'},
+QUnit.module("hr_org_chart", {
+ async beforeEach() {
+ target = getFixture();
+ serverData = {
+ models: {
+ hr_employee: {
+ fields: {
+ child_ids: {string: "one2many Subordinates field", type: "one2many", relation: 'hr_employee'},
+ },
+ records: [{
+ id: 1,
+ child_ids: [],
+ }]
},
- records: [{
- id: 1,
- child_ids: [],
- }]
- }
+ },
};
+ setupViewRegistries();
},
}, function () {
QUnit.test("hr org chart: empty render", async function (assert) {
assert.expect(2);
- var form = await createView({
- View: FormView,
- model: 'hr_employee',
- data: this.data,
+ await makeView({
+ type: "form",
+ resModel: 'hr_employee',
+ serverData: serverData,
arch:
'
',
- res_id: 1,
+ resId: 1,
mockRPC: function (route, args) {
if (route === '/hr/get_org_chart') {
assert.ok('employee_id' in args, "it should have 'employee_id' as argument");
@@ -44,44 +48,40 @@ QUnit.module('hr_org_chart', {
} else if (route === '/hr/get_redirect_model') {
return Promise.resolve('hr.employee');
}
- return this._super(route, args);
}
});
- assert.strictEqual(form.$('[name="child_ids"]').children().length, 1,
+ assert.strictEqual($(target.querySelector('[name="child_ids"]')).children().length, 1,
"the chart should have 1 child");
- form.destroy();
});
QUnit.test("hr org chart: render without data", async function (assert) {
assert.expect(2);
- var form = await createView({
- View: FormView,
- model: 'hr_employee',
- data: this.data,
+ await makeView({
+ type: "form",
+ resModel: 'hr_employee',
+ serverData: serverData,
arch:
'
',
- res_id: 1,
+ resId: 1,
mockRPC: function (route, args) {
if (route === '/hr/get_org_chart') {
assert.ok('employee_id' in args, "it should have 'employee_id' as argument");
return Promise.resolve({}); // return no data
}
- return this._super(route, args);
}
});
- assert.strictEqual(form.$('[name="child_ids"]').children().length, 1,
+ assert.strictEqual($(target.querySelector('[name="child_ids"]')).children().length, 1,
"the chart should have 1 child");
- form.destroy();
});
QUnit.test("hr org chart: basic render", async function (assert) {
assert.expect(3);
- var form = await createView({
- View: FormView,
- model: 'hr_employee',
- data: this.data,
+ await makeView({
+ type: "form",
+ resModel: 'hr_employee',
+ serverData: serverData,
arch:
'
' +
'