[IMP] hr: remove mixins
Prefer using hooks instead. Makes use of the new open_chat_hook from mail when possible. closes odoo/odoo#100764 X-original-commit: d058734cf55f2c3f46f2f23e0bbbfc54f2f0da15 Related: odoo/enterprise#31605 Signed-off-by: William Braeckman (wbr) <wbr@odoo.com>
This commit is contained in:
@@ -53,7 +53,6 @@
|
||||
'hr/static/src/models/*.js',
|
||||
],
|
||||
'web.assets_backend': [
|
||||
'hr/static/src/mixins/*.js',
|
||||
'hr/static/src/views/**/*.js',
|
||||
'hr/static/src/components/**/*',
|
||||
'hr/static/src/user_menu/*.js',
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
/** @odoo-module */
|
||||
|
||||
export const ArchiveEmployeeMixin = {
|
||||
_openArchiveEmployee(id) {
|
||||
return {
|
||||
type: 'ir.actions.act_window',
|
||||
name: this.env._t('Employee Termination'),
|
||||
res_model: 'hr.departure.wizard',
|
||||
views: [[false, 'form']],
|
||||
view_mode: 'form',
|
||||
target: 'new',
|
||||
context: {
|
||||
'active_id': id,
|
||||
'toggle_active': true,
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -1,10 +0,0 @@
|
||||
/** @odoo-module */
|
||||
|
||||
const { Component } = owl;
|
||||
|
||||
export const EmployeeChatMixin = {
|
||||
async openChat(employeeId) {
|
||||
const messaging = await Component.env.services.messaging.get();
|
||||
messaging.openChat({ employeeId });
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import { useService } from "@web/core/utils/hooks";
|
||||
|
||||
const { useComponent, useEnv } = owl;
|
||||
|
||||
export function useArchiveEmployee() {
|
||||
const component = useComponent();
|
||||
const env = useEnv();
|
||||
const action = useService("action");
|
||||
return (id) => {
|
||||
action.doAction({
|
||||
type: 'ir.actions.act_window',
|
||||
name: env._t('Employee Termination'),
|
||||
res_model: 'hr.departure.wizard',
|
||||
views: [[false, 'form']],
|
||||
view_mode: 'form',
|
||||
target: 'new',
|
||||
context: {
|
||||
'active_id': id,
|
||||
'toggle_active': true,
|
||||
}
|
||||
}, {
|
||||
onClose: async () => {
|
||||
await component.model.load();
|
||||
component.model.notify();
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,20 +1,18 @@
|
||||
/** @odoo-module */
|
||||
|
||||
import { registry } from '@web/core/registry';
|
||||
import { useService } from "@web/core/utils/hooks";
|
||||
import { patch } from '@web/core/utils/patch';
|
||||
|
||||
import { formView } from '@web/views/form/form_view';
|
||||
import { FormController } from '@web/views/form/form_controller';
|
||||
import { FormRenderer } from '@web/views/form/form_renderer';
|
||||
|
||||
import { ArchiveEmployeeMixin } from '../mixins/archive_employee_mixin';
|
||||
import { EmployeeChatMixin } from '../mixins/chat_mixin';
|
||||
import { useArchiveEmployee } from '@hr/views/archive_employee_hook';
|
||||
import { useOpenChat } from "@mail/views/open_chat_hook";
|
||||
|
||||
export class EmployeeFormController extends FormController {
|
||||
setup() {
|
||||
super.setup();
|
||||
this.actionService = useService('action');
|
||||
this.archiveEmployee = useArchiveEmployee();
|
||||
}
|
||||
|
||||
getActionMenuItems() {
|
||||
@@ -25,23 +23,18 @@ export class EmployeeFormController extends FormController {
|
||||
|
||||
const archiveAction = menuItems.other.find((item) => item.key === "archive");
|
||||
if (archiveAction) {
|
||||
archiveAction.callback = () => {
|
||||
const archiveAction = this._openArchiveEmployee(this.model.root.resId);
|
||||
this.actionService.doAction(archiveAction, {
|
||||
onClose: async () => {
|
||||
await this.model.load();
|
||||
this.model.notify();
|
||||
}
|
||||
});
|
||||
};
|
||||
archiveAction.callback = this.archiveEmployee.bind(this, this.model.root.resId);
|
||||
}
|
||||
return menuItems;
|
||||
}
|
||||
}
|
||||
patch(EmployeeFormController.prototype, 'employee_form_controller_archive_mixin', ArchiveEmployeeMixin);
|
||||
|
||||
export class EmployeeFormRenderer extends FormRenderer {}
|
||||
patch(EmployeeFormRenderer.prototype, 'employee_form_renderer_mixin', EmployeeChatMixin);
|
||||
export class EmployeeFormRenderer extends FormRenderer {
|
||||
setup() {
|
||||
super.setup();
|
||||
this.openChat = useOpenChat(this.props.record.resModel);
|
||||
}
|
||||
}
|
||||
|
||||
registry.category('views').add('hr_employee_form', {
|
||||
...formView,
|
||||
|
||||
@@ -1,17 +1,24 @@
|
||||
/** @odoo-module */
|
||||
|
||||
import { registry } from '@web/core/registry';
|
||||
import { patch } from '@web/core/utils/patch';
|
||||
|
||||
import { kanbanView } from '@web/views/kanban/kanban_view';
|
||||
import { KanbanModel } from '@web/views/kanban/kanban_model';
|
||||
|
||||
import { EmployeeChatMixin } from '../mixins/chat_mixin';
|
||||
export class EmployeeKanbanRecord extends KanbanModel.Record {
|
||||
async openChat(employeeId) {
|
||||
const messaging = await this.model.messaging.get();
|
||||
messaging.openChat({ employeeId });
|
||||
}
|
||||
}
|
||||
|
||||
export class EmployeeKanbanRecord extends KanbanModel.Record {}
|
||||
patch(EmployeeKanbanRecord.prototype, 'employee_kanban_record_mixin', EmployeeChatMixin);
|
||||
|
||||
export class EmployeeKanbanModel extends KanbanModel {}
|
||||
export class EmployeeKanbanModel extends KanbanModel {
|
||||
setup(params, { messaging }) {
|
||||
super.setup(...arguments);
|
||||
this.messagingService = messaging;
|
||||
}
|
||||
}
|
||||
EmployeeKanbanModel.services = [...KanbanModel.services, "messaging"];
|
||||
EmployeeKanbanModel.Record = EmployeeKanbanRecord;
|
||||
|
||||
registry.category('views').add('hr_employee_kanban', {
|
||||
|
||||
@@ -1,18 +1,16 @@
|
||||
/** @odoo-module */
|
||||
|
||||
import { registry } from '@web/core/registry';
|
||||
import { useService } from "@web/core/utils/hooks";
|
||||
import { patch } from '@web/core/utils/patch';
|
||||
|
||||
import { listView } from '@web/views/list/list_view';
|
||||
import { ListController } from '@web/views/list/list_controller';
|
||||
|
||||
import { ArchiveEmployeeMixin } from '../mixins/archive_employee_mixin';
|
||||
import { useArchiveEmployee } from '@hr/views/archive_employee_hook';
|
||||
|
||||
export class EmployeeListController extends ListController {
|
||||
setup() {
|
||||
super.setup();
|
||||
this.actionService = useService('action');
|
||||
this.archiveEmployee = useArchiveEmployee();
|
||||
}
|
||||
|
||||
getActionMenuItems() {
|
||||
@@ -26,20 +24,11 @@ export class EmployeeListController extends ListController {
|
||||
|
||||
const archiveAction = menuItems.other.find((item) => item.key === "archive");
|
||||
if (archiveAction) {
|
||||
archiveAction.callback = () => {
|
||||
const archiveAction = this._openArchiveEmployee(this.model.root.resId);
|
||||
this.actionService.doAction(archiveAction, {
|
||||
onClose: async () => {
|
||||
await this.model.load();
|
||||
this.model.notify();
|
||||
}
|
||||
});
|
||||
};
|
||||
archiveAction.callback = this.archiveEmployee.bind(this, selectedRecords[0].resId);
|
||||
}
|
||||
return menuItems;
|
||||
}
|
||||
}
|
||||
patch(EmployeeListController.prototype, 'employee_list_controller_archive_mixin', ArchiveEmployeeMixin);
|
||||
|
||||
registry.category('views').add('hr_employee_list', {
|
||||
...listView,
|
||||
|
||||
Reference in New Issue
Block a user