From ee951c945bfda9a3ebfdf90874697d68f2494807 Mon Sep 17 00:00:00 2001 From: William Braeckman Date: Tue, 20 Sep 2022 12:19:32 +0000 Subject: [PATCH] [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) --- addons/hr/__manifest__.py | 1 - .../src/mixins/archive_employee_mixin.js | 18 ----------- addons/hr/static/src/mixins/chat_mixin.js | 10 ------- .../static/src/views/archive_employee_hook.js | 30 +++++++++++++++++++ addons/hr/static/src/views/form_view.js | 27 +++++++---------- addons/hr/static/src/views/kanban_view.js | 19 ++++++++---- addons/hr/static/src/views/list_view.js | 17 ++--------- 7 files changed, 56 insertions(+), 66 deletions(-) delete mode 100644 addons/hr/static/src/mixins/archive_employee_mixin.js delete mode 100644 addons/hr/static/src/mixins/chat_mixin.js create mode 100644 addons/hr/static/src/views/archive_employee_hook.js diff --git a/addons/hr/__manifest__.py b/addons/hr/__manifest__.py index 68782c6b4e4..6180b6ddb88 100644 --- a/addons/hr/__manifest__.py +++ b/addons/hr/__manifest__.py @@ -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', diff --git a/addons/hr/static/src/mixins/archive_employee_mixin.js b/addons/hr/static/src/mixins/archive_employee_mixin.js deleted file mode 100644 index 351777d23bd..00000000000 --- a/addons/hr/static/src/mixins/archive_employee_mixin.js +++ /dev/null @@ -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, - } - } - } -}; diff --git a/addons/hr/static/src/mixins/chat_mixin.js b/addons/hr/static/src/mixins/chat_mixin.js deleted file mode 100644 index 3b75270e762..00000000000 --- a/addons/hr/static/src/mixins/chat_mixin.js +++ /dev/null @@ -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 }); - }, -} diff --git a/addons/hr/static/src/views/archive_employee_hook.js b/addons/hr/static/src/views/archive_employee_hook.js new file mode 100644 index 00000000000..e97d445ff27 --- /dev/null +++ b/addons/hr/static/src/views/archive_employee_hook.js @@ -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(); + }, + }); + } +} diff --git a/addons/hr/static/src/views/form_view.js b/addons/hr/static/src/views/form_view.js index 43d4c344973..aeecabcf946 100644 --- a/addons/hr/static/src/views/form_view.js +++ b/addons/hr/static/src/views/form_view.js @@ -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, diff --git a/addons/hr/static/src/views/kanban_view.js b/addons/hr/static/src/views/kanban_view.js index 46681947252..c0d62167e7e 100644 --- a/addons/hr/static/src/views/kanban_view.js +++ b/addons/hr/static/src/views/kanban_view.js @@ -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', { diff --git a/addons/hr/static/src/views/list_view.js b/addons/hr/static/src/views/list_view.js index a0bea74c2c6..6f1a322c5a6 100644 --- a/addons/hr/static/src/views/list_view.js +++ b/addons/hr/static/src/views/list_view.js @@ -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,