[IMP] hr_holidays: restrict day selection by month#5195
Draft
anchevalier wants to merge 1 commit into
Draft
Conversation
|
This PR targets the un-managed branch odoo-dev/odoo:master-hr-onboarding-chean, it needs to be retargeted before it can be merged. |
Mahmoudk3m
requested changes
Jul 8, 2026
Mahmoudk3m
left a comment
There was a problem hiding this comment.
Thanks for your work, left some comments 🚀
Before this commit, it was possible to select an invalid day for a given month in accrual plans (e.g. February 31st). This commit introduces a dedicated field widget that dynamically restricts the available day values according to the selected month, preventing invalid selections while providing a better user experience. Task: 6334330
238bbb1 to
dc221fe
Compare
Mahmoudk3m
reviewed
Jul 8, 2026
Comment on lines
+4
to
+24
| const LEAP_YEAR = 2020; | ||
|
|
||
| function getLastDayOfMonth(month) { | ||
| return month | ||
| ? new Date(LEAP_YEAR, Number(month), 0).getDate() | ||
| : 31; | ||
| } | ||
|
|
||
| export class DaySelectionByMonthField extends SelectionField { | ||
| static props = { | ||
| ...SelectionField.props, | ||
| selectedMonth: { type: String, optional: true }, | ||
| }; | ||
|
|
||
| get options() { | ||
| const selectedMonth = this.props.record.data[this.props.selectedMonth]; | ||
| const lastDay = getLastDayOfMonth(selectedMonth); | ||
|
|
||
| return super.options.filter(([day]) => day <= lastDay); | ||
| } | ||
| } |
There was a problem hiding this comment.
Suggested change
| const LEAP_YEAR = 2020; | |
| function getLastDayOfMonth(month) { | |
| return month | |
| ? new Date(LEAP_YEAR, Number(month), 0).getDate() | |
| : 31; | |
| } | |
| export class DaySelectionByMonthField extends SelectionField { | |
| static props = { | |
| ...SelectionField.props, | |
| selectedMonth: { type: String, optional: true }, | |
| }; | |
| get options() { | |
| const selectedMonth = this.props.record.data[this.props.selectedMonth]; | |
| const lastDay = getLastDayOfMonth(selectedMonth); | |
| return super.options.filter(([day]) => day <= lastDay); | |
| } | |
| } | |
| export class DaySelectionByMonthField extends SelectionField { | |
| static props = { | |
| ...SelectionField.props, | |
| selectedMonth: { type: String, optional: true }, | |
| }; | |
| get options() { | |
| const selectedMonth = this.props.record.data[this.props.selectedMonth]; | |
| const allDays = this.props.record.fields[this.props.name].selection; | |
| const maxDays = new Date(2024, month, 0).getDate(); | |
| return allDays.filter(opt => parseInt(opt[0]) <= maxDays); | |
| } | |
| } |
Maybe we could do something like this instead?
Author
There was a problem hiding this comment.
This approach could work after replacing month with selectedMonth, but I would keep using super.options here since it already exposes the field selection from the base SelectionField. I would also keep the LEAP_YEAR constant, or at least add a comment, to avoid having 2024 as a magic number.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Before this commit, it was possible to select an invalid day for a given month in accrual plans (e.g. February 31st).
This commit introduces a dedicated field widget that dynamically restricts the available day values according to the selected month, preventing invalid selections while providing a better user experience.
Task: 6334330