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