[IMP] hr_org_chart: fix the traceback when we click on See All of the Organization Chart
Steps to reproduce: - Go to Employee - Open the Employee profile and click on Work information. - In the Organization Chart Below the hierarchy See All button is visible. - Click on the 'See All' button. Currently, when we click on the ``see all'' button of the organization chart, the traceback comes. Fixed it in this commit. task-3133047 closes odoo/odoo#110476 X-original-commit: 9f4e1fa80dc75900fb8a2c979568c3ab8f65a635 Signed-off-by: Kevin Baptiste <kba@odoo.com>
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
/** @odoo-module */
|
||||
|
||||
import session from 'web.session'
|
||||
import { useService } from "@web/core/utils/hooks";
|
||||
import { useEnv } from "@odoo/owl";
|
||||
|
||||
/**
|
||||
* Redirect to the sub employee kanban view.
|
||||
*
|
||||
* @private
|
||||
* @param {MouseEvent} event
|
||||
* @returns {Promise} action loaded
|
||||
*
|
||||
*/
|
||||
export function onEmployeeSubRedirect() {
|
||||
const actionService = useService('action');
|
||||
const orm = useService('orm');
|
||||
const rpc = useService('rpc');
|
||||
const env = useEnv();
|
||||
|
||||
return async (event) => {
|
||||
const employeeId = parseInt(event.currentTarget.dataset.employeeId);
|
||||
if (!employeeId) {
|
||||
return {};
|
||||
}
|
||||
const type = event.currentTarget.dataset.type || 'direct';
|
||||
// Get subordonates of an employee through a rpc call.
|
||||
const subordinateIds = await rpc('/hr/get_subordinates', {
|
||||
employee_id: employeeId,
|
||||
subordinates_type: type,
|
||||
context: session.user_context
|
||||
});
|
||||
let action = await orm.call('hr.employee', 'get_formview_action', [employeeId]);
|
||||
action = {...action,
|
||||
name: env._t('Team'),
|
||||
view_mode: 'kanban,list,form',
|
||||
views: [[false, 'kanban'], [false, 'list'], [false, 'form']],
|
||||
domain: [['id', 'in', subordinateIds]],
|
||||
res_id: false,
|
||||
context: {
|
||||
default_parent_id: employeeId,
|
||||
}
|
||||
};
|
||||
actionService.doAction(action);
|
||||
};
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import {Field} from '@web/views/fields/field';
|
||||
import { registry } from "@web/core/registry";
|
||||
import { useService } from "@web/core/utils/hooks";
|
||||
import { usePopover } from "@web/core/popover/popover_hook";
|
||||
import { onEmployeeSubRedirect } from './hooks';
|
||||
|
||||
const { Component, onWillStart, onWillRender, useState } = owl;
|
||||
|
||||
@@ -31,25 +32,7 @@ class HrOrgChartPopover extends Component {
|
||||
this.rpc = useService('rpc');
|
||||
this.orm = useService('orm');
|
||||
this.actionService = useService("action");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get subordonates of an employee through a rpc call.
|
||||
*
|
||||
* @private
|
||||
* @param {integer} employee_id
|
||||
* @returns {Promise}
|
||||
*/
|
||||
async _getSubordinatesData(employee_id, type) {
|
||||
const subData = await this.rpc(
|
||||
'/hr/get_subordinates',
|
||||
{
|
||||
employee_id: employee_id,
|
||||
subordinates_type: type,
|
||||
context: Component.env.session.user_context,
|
||||
}
|
||||
);
|
||||
return subData;
|
||||
this._onEmployeeSubRedirect = onEmployeeSubRedirect();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,35 +46,6 @@ class HrOrgChartPopover extends Component {
|
||||
const action = await this.orm.call('hr.employee', 'get_formview_action', [employeeId]);
|
||||
this.actionService.doAction(action);
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect to the sub employee form view.
|
||||
*
|
||||
* @private
|
||||
* @param {MouseEvent} event
|
||||
* @returns {Promise} action loaded
|
||||
*/
|
||||
async _onEmployeeSubRedirect(event) {
|
||||
const employee_id = parseInt(event.currentTarget.dataset.employeeId);
|
||||
const type = event.currentTarget.dataset.type || 'direct';
|
||||
if (!employee_id) {
|
||||
return {};
|
||||
}
|
||||
const subData = await this._getSubordinatesData(employee_id, type);
|
||||
const domain = [['id', 'in', subData]];
|
||||
var action = await this.orm.call('hr.employee', 'get_formview_action', [employee_id]);
|
||||
action = Object.assign(action, {
|
||||
'name': this.env._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'];
|
||||
this.actionService.doAction(action);
|
||||
}
|
||||
}
|
||||
HrOrgChartPopover.template = 'hr_org_chart.hr_orgchart_emp_popover';
|
||||
|
||||
@@ -107,6 +61,7 @@ export class HrOrgChart extends Field {
|
||||
this.jsonStringify = JSON.stringify;
|
||||
|
||||
this.state = useState({'employee_id': null});
|
||||
this._onEmployeeSubRedirect = onEmployeeSubRedirect();
|
||||
|
||||
onWillStart(this.handleComponentUpdate.bind(this));
|
||||
onWillRender(this.handleComponentUpdate.bind(this));
|
||||
|
||||
Reference in New Issue
Block a user