From 6ff5f9eb160f1e2924bfbaf0f6c557341e91b24b Mon Sep 17 00:00:00 2001 From: "Xavier Bol (xbo)" Date: Mon, 28 Aug 2023 15:43:02 +0200 Subject: [PATCH] [REF] hr: create hr_presence_status widget Before this commit, the hr presence status icon is hardcoded in each view in which the icon is needed. This commit creates a widget for that icon to be able to use that widget in the views in which the icon is needed to avoid duplicating the code. task-3376776 --- .../hr_presence_status/hr_presence_status.js | 77 +++++++++++++++++++ .../hr_presence_status/hr_presence_status.xml | 8 ++ addons/hr/views/hr_employee_public_views.xml | 27 +------ addons/hr/views/hr_employee_views.xml | 40 +--------- .../hr_presence_status/hr_presence_status.js | 22 ++++++ addons/hr_holidays/views/hr_views.xml | 42 +--------- .../hr_presence_status/hr_presence_status.js | 65 ++++++++++++++++ .../views/hr_employee_views.xml | 41 +--------- 8 files changed, 181 insertions(+), 141 deletions(-) create mode 100644 addons/hr/static/src/components/hr_presence_status/hr_presence_status.js create mode 100644 addons/hr/static/src/components/hr_presence_status/hr_presence_status.xml create mode 100644 addons/hr_holidays/static/src/components/hr_presence_status/hr_presence_status.js create mode 100644 addons/hr_homeworking/static/src/components/hr_presence_status/hr_presence_status.js diff --git a/addons/hr/static/src/components/hr_presence_status/hr_presence_status.js b/addons/hr/static/src/components/hr_presence_status/hr_presence_status.js new file mode 100644 index 00000000000..b409f128f66 --- /dev/null +++ b/addons/hr/static/src/components/hr_presence_status/hr_presence_status.js @@ -0,0 +1,77 @@ +/** @odoo-module */ + +import { Component } from "@odoo/owl"; + +import { _t } from "@web/core/l10n/translation"; +import { registry } from "@web/core/registry"; +import { standardFieldProps } from "@web/views/fields/standard_field_props"; + +export class HrPresenceStatus extends Component { + static template = "hr.HrPresenceStatus"; + static props = { + ...standardFieldProps, + tag: { type: String, optional: true }, + }; + static defaultProps = { + tag: "small", + }; + + get classNames() { + const classNames = ["fa"]; + classNames.push( + `fa-${this.props.tag === "small" ? "fw" : "2x"}`, + this.icon, + "o_button_icon", + "hr_presence", + "align-middle", + this.color, + ) + return classNames.join(" "); + } + + get color() { + switch (this.value) { + case "presence_present": + case "presence_absent_active": + return "text-success"; + case "presence_absent": + return "text-muted"; + case "presence_to_define": + return "text-warning"; + default: + return ""; + } + } + + get icon() { + return `fa-circle${this.value.startsWith("presence_absent") ? "-o" : ""}`; + } + + get label() { + return this.value !== false + ? this.options.find(([value, label]) => value === this.value)[1] + : ""; + } + + get options() { + return this.props.record.fields[this.props.name].selection.filter( + (option) => option[0] !== false && option[1] !== "" + ); + } + + get value() { + return this.props.record.data[this.props.name]; + } +} + +export const hrPresenceStatus = { + component: HrPresenceStatus, + displayName: _t("HR Presence Status"), + extractProps({ viewType }, dynamicInfo) { + return { + tag: viewType === "kanban" ? "span" : "small", + }; + }, +}; + +registry.category("fields").add("hr_presence_status", hrPresenceStatus) diff --git a/addons/hr/static/src/components/hr_presence_status/hr_presence_status.xml b/addons/hr/static/src/components/hr_presence_status/hr_presence_status.xml new file mode 100644 index 00000000000..db69c3d542b --- /dev/null +++ b/addons/hr/static/src/components/hr_presence_status/hr_presence_status.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/addons/hr/views/hr_employee_public_views.xml b/addons/hr/views/hr_employee_public_views.xml index 53d8d16bb38..9b06c5d1c95 100644 --- a/addons/hr/views/hr_employee_public_views.xml +++ b/addons/hr/views/hr_employee_public_views.xml @@ -147,31 +147,8 @@