From 516f2b5e4a36861d087f45144f772c0f53df2036 Mon Sep 17 00:00:00 2001 From: vikri-odoo Date: Tue, 27 Jan 2026 14:08:36 +0100 Subject: [PATCH] [FIX] hr_holiday: prevent accrual day selection of invalid days (e.g., Feb 31st) via new widget Steps to reproduce: Open accrual milstone form containing the custom day selection field. Select "February" as the month and observe that "31" remains a selectable option in the day dropdown. Bug Cause: The standard selection field used static values (1-31) and lacked dynamic cross-field validation between the month and day inputs. Solution: Created a new Odoo field widget to handle day selection. This widget dynamically calculates the maximum number of days allowed based on the selected month and year, effectively disabling or removing invalid dates like February 31st. --- .../accrual_day_field/accrual_day_field.js | 28 +++++++++++++++++++ .../views/hr_leave_accrual_views.xml | 8 +++--- 2 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 addons/hr_holidays/static/src/components/accrual_day_field/accrual_day_field.js diff --git a/addons/hr_holidays/static/src/components/accrual_day_field/accrual_day_field.js b/addons/hr_holidays/static/src/components/accrual_day_field/accrual_day_field.js new file mode 100644 index 0000000000000..144792c0c4342 --- /dev/null +++ b/addons/hr_holidays/static/src/components/accrual_day_field/accrual_day_field.js @@ -0,0 +1,28 @@ +import { registry } from "@web/core/registry"; +import { SelectionField } from "@web/views/fields/selection/selection_field"; +import { standardFieldProps } from "@web/views/fields/standard_field_props"; + +export class AccrualDayField extends SelectionField { + + static props = { + ...standardFieldProps, + monthField: { + type: String, + } + } + + get options() { + let options = super.options; + const carryover_month = this.props.record.data[this.props.monthField]; + const lastDay = new Date(2020, carryover_month, 0).getDate(); + options = options.filter((option) => option[0] <= lastDay); + return options; + } +} + +registry.category("fields").add("accrual_day", { + component: AccrualDayField, + extractProps: ({ attrs }) => ({ + monthField: attrs.monthField + }) +}); diff --git a/addons/hr_holidays/views/hr_leave_accrual_views.xml b/addons/hr_holidays/views/hr_leave_accrual_views.xml index 53e2df20c6ff2..2634d52e9016f 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 @@ -192,7 +192,7 @@ options="{'links': {'other': 'carryover_custom_date'}, 'observe': 'carryover'}"/> : the - of