From 2576db8c77d6a8316b03d790f3e55d9240e80a0a Mon Sep 17 00:00:00 2001 From: Rana Date: Fri, 8 May 2026 10:50:51 +0200 Subject: [PATCH] [FIX] hr_holidays: Accrual UX The selection field of days in the accrual plan milestones was always showing 31 days in the options regardless the month. A new JavaScript Class was created that extends the "SelecionField" to dynamically change the options and show the number of days depending on the month by accessing the month from props. Task: 6199932 --- .../accrual_day_selection.js | 41 +++++++++++++++++++ .../views/hr_leave_accrual_views.xml | 8 ++-- 2 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 addons/hr_holidays/static/src/components/accrual_day_selection/accrual_day_selection.js diff --git a/addons/hr_holidays/static/src/components/accrual_day_selection/accrual_day_selection.js b/addons/hr_holidays/static/src/components/accrual_day_selection/accrual_day_selection.js new file mode 100644 index 00000000000000..470ac587133ea6 --- /dev/null +++ b/addons/hr_holidays/static/src/components/accrual_day_selection/accrual_day_selection.js @@ -0,0 +1,41 @@ +import { SelectionField, selectionField } from "@web/views/fields/selection/selection_field"; +import { registry } from "@web/core/registry"; + +export class AccrualDaySelection extends SelectionField { + static props = { + ...SelectionField.props, + }; + + get options() { + const allOptions = super.options; + + const monthFieldName = this.props.monthFieldName; + + if (!monthFieldName) return allOptions; + + const monthValue = this.props.record.data[monthFieldName]; + + if (!monthValue) return allOptions; + + const month = parseInt(monthValue); + let maxDays = 31; + if ([4, 6, 9, 11].includes(month)) { + maxDays = 30; + } else if (month === 2) { + maxDays = 29; + } + + return allOptions.filter((opt) => parseInt(opt[0]) <= maxDays); + } +} + + +registry.category("fields").add("accrual_day_dropdown", { + ...selectionField, + component: AccrualDaySelection, + extractProps: (fieldInfo, dynamicInfo) => { + const props = selectionField.extractProps(fieldInfo,dynamicInfo); + props.monthFieldName = fieldInfo.options.month_field; + return props; +}, +}); diff --git a/addons/hr_holidays/views/hr_leave_accrual_views.xml b/addons/hr_holidays/views/hr_leave_accrual_views.xml index a097fdbec8f74b..edb4c7978916a7 100644 --- a/addons/hr_holidays/views/hr_leave_accrual_views.xml +++ b/addons/hr_holidays/views/hr_leave_accrual_views.xml @@ -36,17 +36,17 @@ on the - + of and the - + of on the - + of @@ -196,7 +196,7 @@ : the + required="carryover_date == 'other'" widget="accrual_day_dropdown" options="{'month_field': 'carryover_month'}"/> of