-
Notifications
You must be signed in to change notification settings - Fork 118
[IMP] hr_holidays: cap carryover day selection based on month #5239
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-amgom
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,46 @@ | ||
| import { useProps } from "@odoo/owl"; | ||
| import { registry } from "@web/core/registry"; | ||
| import { SelectionField, selectionField } from "@web/views/fields/selection/selection_field"; | ||
|
|
||
|
|
||
| export class CarryoverDaySelection extends SelectionField { | ||
| props = useProps(); | ||
|
|
||
| get options() { | ||
| const allOptions = super.options; | ||
| const monthFieldName = this.props.monthField; | ||
| const currentMonth = this.props.record.data[monthFieldName]; | ||
|
|
||
| if (!monthFieldName || !currentMonth) { | ||
| return allOptions; | ||
| } | ||
|
|
||
| const monthMaxDays = { | ||
| "1": 31, "2": 29, "3": 31, "4": 30, "5": 31, "6": 30, | ||
| "7": 31, "8": 31, "9": 30, "10": 31, "11": 30, "12": 31 | ||
| }; | ||
|
Comment on lines
+18
to
+21
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. Maybe you can try to make it prettier, something should exists to get the last day of a given month without hardcoding it 👀 (using luxon or standard js Date 🤷♂️) |
||
| const maxAllowedDays = monthMaxDays[currentMonth]; | ||
|
|
||
| return allOptions.filter((option) => parseInt(option[0], 10) <= maxAllowedDays); | ||
| } | ||
| } | ||
|
|
||
| registry.category("fields").add("carryover_day_widget", { | ||
| ...selectionField, | ||
| component: CarryoverDaySelection, | ||
|
|
||
| supportedOptions: [ | ||
| ...(selectionField.supportedOptions || []), | ||
| { name: "month_field", type: "string" } | ||
| ], | ||
|
|
||
| extractProps: (fieldInfo, dynamicInfo) => { | ||
| const props = selectionField.extractProps(fieldInfo, dynamicInfo); | ||
|
|
||
| if (fieldInfo.options && fieldInfo.options.month_field) { | ||
| props.monthField = fieldInfo.options.month_field; | ||
| } | ||
|
|
||
| return props; | ||
| } | ||
|
Comment on lines
+32
to
+45
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. It's good, you can use attrs too. options are more used to set multiples values that will be evaluated. and attrs will be just string. so in your case, an attr is more adapted here I think 👀 |
||
| }); | ||
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.
it's a good practice to add
As it comes from SelectionField