diff --git a/addons/hr_holidays/static/src/components/selection_day_in_month/selection_day_in_month.js b/addons/hr_holidays/static/src/components/selection_day_in_month/selection_day_in_month.js new file mode 100644 index 00000000000000..1854af85c52ebf --- /dev/null +++ b/addons/hr_holidays/static/src/components/selection_day_in_month/selection_day_in_month.js @@ -0,0 +1,42 @@ +import { registry } from "@web/core/registry"; +import { + SelectionField, + selectionField, + selectionFieldProps, +} from "@web/views/fields/selection/selection_field"; +import { useProps } from "@odoo/owl"; + +function daysInMonth(month) { + return new Date(2024, month, 0).getDate(); +} + +export class SelectionDayInMonthField extends SelectionField { + props = useProps({ + ...selectionFieldProps, + month_field: { type: String, optional: false }, + }); + + get options() { + const month_field = this.props.month_field; + const month = this.props.record.data[month_field] ?? null; + const cap = daysInMonth(month) || 31; + const days = []; + for (let i = 1; i <= cap; i++) { + days.push([i.toString(), i.toString()]); + } + return days; + } +} + +export const selectionDayInMonthField = { + ...selectionField, + component: SelectionDayInMonthField, + + extractProps({ options }) { + const props = selectionField.extractProps(...arguments); + props.month_field = options.month_field; + return props; + }, +}; + +registry.category("fields").add("selection_day_in_month", selectionDayInMonthField); diff --git a/addons/hr_holidays/views/hr_leave_accrual_views.xml b/addons/hr_holidays/views/hr_leave_accrual_views.xml index 2a8a8f043e3ea9..710f998b33eaed 100644 --- a/addons/hr_holidays/views/hr_leave_accrual_views.xml +++ b/addons/hr_holidays/views/hr_leave_accrual_views.xml @@ -36,17 +36,29 @@ on the - + of and the - + of on the - + of @@ -204,8 +216,11 @@ options="{'links': {'other': 'carryover_custom_date'}, 'observe': 'carryover'}"/> : the - + of