diff --git a/addons/hr_holidays/static/src/components/day_selection/day_selection.js b/addons/hr_holidays/static/src/components/day_selection/day_selection.js new file mode 100644 index 00000000000000..7683655b2c67ac --- /dev/null +++ b/addons/hr_holidays/static/src/components/day_selection/day_selection.js @@ -0,0 +1,36 @@ +import { selectionField, SelectionField } from "@web/views/fields/selection/selection_field"; +import { registry } from "@web/core/registry"; + +export class DaySelectionField extends SelectionField { + static props = { + ...SelectionField.props, + month: String, + }; + + get options() { + let allOptions = super.options; + const monthValue = this.props.record.data[this.props.month]; + const maxDay = new Date(2020, monthValue, 0).getDate(); + allOptions = allOptions.filter((option) => option[0] <= maxDay); + return allOptions; + } +} + +export const daySelectionField = { + ...selectionField, + component: DaySelectionField, + extractProps({ attrs }) { + return { + ...selectionField.extractProps(...arguments), + month: attrs.month, + }; + }, + fieldDependencies: ({ attrs }) => [ + { + name: attrs.month, + type: "selection", + }, + ], +}; + +registry.category("fields").add("day_selection", daySelectionField); diff --git a/addons/hr_holidays/views/hr_leave_accrual_views.xml b/addons/hr_holidays/views/hr_leave_accrual_views.xml index a097fdbec8f74b..08072d7788c6b3 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 @@ -195,7 +195,7 @@ options="{'links': {'other': 'carryover_custom_date'}, 'observe': 'carryover'}"/> : the - of