| 1 |
import { _t } from "@web/core/l10n/translation"; |
| 2 |
import { patch } from "@web/core/utils/patch"; |
| 3 |
|
| 4 |
import { HrPresenceStatus, hrPresenceStatus } from "@hr/components/hr_presence_status/hr_presence_status"; |
| 5 |
import { HrPresenceStatusPrivate, hrPresenceStatusPrivate } from "@hr/components/hr_presence_status_private/hr_presence_status_private"; |
| 6 |
import { |
| 7 |
HrPresenceStatusPill, |
| 8 |
hrPresenceStatusPill, |
| 9 |
} from "@hr/components/hr_presence_status_pill/hr_presence_status_pill"; |
| 10 |
import { |
| 11 |
HrPresenceStatusPrivatePill, |
| 12 |
hrPresenceStatusPrivatePill, |
| 13 |
} from "@hr/components/hr_presence_status_private_pill/hr_presence_status_private_pill"; |
| 14 |
|
| 15 |
const patchHrPresenceStatus = () => ({ |
| 16 |
|
| 17 |
get label() { |
| 18 |
if (this.value.includes("holiday")) { |
| 19 |
return _t("%(label)s, back on %(date)s", |
| 20 |
{ |
| 21 |
label: super.label, |
| 22 |
date: this.props.record.data['leave_date_to'].toLocaleString( |
| 23 |
{ |
| 24 |
day: 'numeric', |
| 25 |
month: 'short', |
| 26 |
year: 'numeric', |
| 27 |
} |
| 28 |
) |
| 29 |
} |
| 30 |
) |
| 31 |
} |
| 32 |
return super.label |
| 33 |
}, |
| 34 |
|
| 35 |
get icon() { |
| 36 |
if (this.value.startsWith("presence_holiday")) { |
| 37 |
return "fa-plane"; |
| 38 |
} |
| 39 |
return super.icon; |
| 40 |
}, |
| 41 |
|
| 42 |
get color() { |
| 43 |
if (this.value.startsWith("presence_holiday")) { |
| 44 |
return `${this.value === "presence_holiday_present" ? "text-success" : "o_icon_employee_absent"}`; |
| 45 |
} |
| 46 |
return super.color; |
| 47 |
}, |
| 48 |
}); |
| 49 |
|
| 50 |
const patchHrPresenceStatusPill = () => ({ |
| 51 |
get color() { |
| 52 |
if (this.value.startsWith("presence_holiday")) { |
| 53 |
return this.value === "presence_holiday_present" |
| 54 |
? "btn-outline-success" |
| 55 |
: "btn-outline-warning"; |
| 56 |
} |
| 57 |
return super.color; |
| 58 |
}, |
| 59 |
}); |
| 60 |
|
| 61 |
|
| 62 |
patch(HrPresenceStatus.prototype, patchHrPresenceStatus()); |
| 63 |
patch(HrPresenceStatusPrivate.prototype, patchHrPresenceStatus()); |
| 64 |
|
| 65 |
|
| 66 |
patch(HrPresenceStatusPill.prototype, patchHrPresenceStatusPill()); |
| 67 |
|
| 68 |
const patchHrPresenceStatusPrivate = () => ({ |
| 69 |
get label() { |
| 70 |
if (this.props.record.data.current_leave_id){ |
| 71 |
let label = this.props.record.data.current_leave_id.display_name; |
| 72 |
if (this.props.record.data.leave_date_to) { |
| 73 |
label += _t(", back on ") + this.props.record.data['leave_date_to'].toLocaleString( |
| 74 |
{ |
| 75 |
day: 'numeric', |
| 76 |
month: 'short', |
| 77 |
year: 'numeric', |
| 78 |
} |
| 79 |
) |
| 80 |
} |
| 81 |
return label; |
| 82 |
} |
| 83 |
return super.label; |
| 84 |
} |
| 85 |
}); |
| 86 |
|
| 87 |
patch(HrPresenceStatusPrivate.prototype, patchHrPresenceStatusPrivate()); |
| 88 |
patch(HrPresenceStatusPrivatePill.prototype, patchHrPresenceStatusPrivate()); |
| 89 |
|
| 90 |
Object.assign(hrPresenceStatus, { |
| 91 |
fieldDependencies: [ |
| 92 |
...hrPresenceStatus.fieldDependencies, |
| 93 |
{ name: "leave_date_to", type: "date" }, |
| 94 |
], |
| 95 |
}); |
| 96 |
|
| 97 |
Object.assign(hrPresenceStatusPrivate, { |
| 98 |
fieldDependencies: [ |
| 99 |
...hrPresenceStatusPrivate.fieldDependencies, |
| 100 |
...hrPresenceStatus.fieldDependencies, |
| 101 |
{ name: "current_leave_id", type:"many2one"}, |
| 102 |
], |
| 103 |
}); |
| 104 |
|
| 105 |
Object.assign(hrPresenceStatusPill, { |
| 106 |
fieldDependencies: [ |
| 107 |
...hrPresenceStatusPill.fieldDependencies, |
| 108 |
{ name: "leave_date_to", type: "date" }, |
| 109 |
], |
| 110 |
}); |
| 111 |
|
| 112 |
Object.assign(hrPresenceStatusPrivatePill, { |
| 113 |
fieldDependencies: [ |
| 114 |
...hrPresenceStatusPrivatePill.fieldDependencies, |
| 115 |
...hrPresenceStatusPill.fieldDependencies, |
| 116 |
{ name: "current_leave_id", type: "many2one" }, |
| 117 |
], |
| 118 |
}); |