From 3ee07b64e29be157eba5dc2a1b89d45dd5cba7e6 Mon Sep 17 00:00:00 2001 From: "ibrahim (ibmah)" Date: Wed, 14 Jan 2026 14:08:09 +0100 Subject: [PATCH] [FIX] hr_holidays: limit days selection for accruals to those of the selected month This disallows the user setting accrual plans for yearly or bi-yearly and selecting a day that doesn't exist (like 30th of February). This also disallows selecting days that aren't present in every year (like 29th of February) since it only occurs once every 4 years and it would be confusing for end-users when the yearly accrual isn't triggered yearly task-5473491 --- .../components/day_of_month/day_of_month.js | 30 +++++++++++++++++++ .../views/hr_leave_accrual_views.xml | 6 ++-- 2 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 addons/hr_holidays/static/src/components/day_of_month/day_of_month.js diff --git a/addons/hr_holidays/static/src/components/day_of_month/day_of_month.js b/addons/hr_holidays/static/src/components/day_of_month/day_of_month.js new file mode 100644 index 0000000000000..0b0120d259804 --- /dev/null +++ b/addons/hr_holidays/static/src/components/day_of_month/day_of_month.js @@ -0,0 +1,30 @@ +import { registry } from "@web/core/registry"; +import { SelectionField, selectionField } from "@web/views/fields/selection/selection_field"; + +export class DayOfMonth extends SelectionField { + static props = { + ...SelectionField.props, + month: String, + }; + + get options() { + const days = this.props.record.fields[this.props.name].selection; + const month = this.props.record.data[this.props.month]; + // using non-leap year (2025) to avoid having the date set to 29th of Feb and only triggering once every 4 years + const lastDay = new Date(2025, month, 0).getDate(); + return days.filter((day) => day[0] <= lastDay); + } +} + +export const dayOfMonth = { + ...selectionField, + component: DayOfMonth, + extractProps({ options }) { + return { + ...selectionField.extractProps(...arguments), + month: options.depends_on, + }; + }, +}; + +registry.category("fields").add("day_of_month", dayOfMonth); diff --git a/addons/hr_holidays/views/hr_leave_accrual_views.xml b/addons/hr_holidays/views/hr_leave_accrual_views.xml index 53e2df20c6ff2..bb2b85558b514 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