-
Notifications
You must be signed in to change notification settings - Fork 117
[FIX] hr_holidays: dynamic accrual days #4904
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master-hr-onboarding-haabo
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import { registry } from "@web/core/registry"; | ||
| import { SelectionField, selectionField } from "@web/views/fields/selection/selection_field"; | ||
|
|
||
| export class DayMonthSelectionField extends SelectionField { | ||
| static props = { | ||
| ...SelectionField.props, | ||
| selectedMonth: { type: String, optional: true }, | ||
| }; | ||
|
|
||
|
|
||
| get options() { | ||
| const selectedMonth = this.props.record.data[this.props.selectedMonth]; | ||
| if (isNaN(selectedMonth) || selectedMonth < 1 || selectedMonth > 12){ | ||
| throw new Error("Please select a valid month."); | ||
| } | ||
| // The year 2024 is used as a default year as it's a leap year so it will alow us to select the 29th of February (to be more generic) | ||
| const date = new Date(2024, selectedMonth, 0); | ||
| const days = date.getDate(); | ||
| let newChoicesList = Array.from({length: days}, (_, i) => [(i + 1).toString(), (i + 1).toString()]) | ||
| return newChoicesList; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| export const dayMonthSelectionField = { | ||
| ...selectionField, | ||
| component: DayMonthSelectionField, | ||
| extractProps: (fieldInfo, dynamicInfo) => { | ||
| const props = selectionField.extractProps(fieldInfo, dynamicInfo); | ||
| props.selectedMonth = fieldInfo.attrs.selected_month; | ||
| return props; | ||
| }, | ||
| }; | ||
|
|
||
| registry.category("fields").add("day_month_selection", dayMonthSelectionField); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If a user has selected "31" for the day and then changes the month to one with only 30 days, what happens? 🤔
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The widget automatically adjusts I think it's because it's watching on the selectedMonth prop to recall the function on change |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If selectedMonth is undefined or invalid, this could fail silently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added a condition to prompt the user and not give him any day options to select from