Skip to content

[IMP] hr_holidays: restrict day selection by month#5195

Draft
anchevalier wants to merge 1 commit into
master-hr-onboarding-cheanfrom
master-hr_holidays-accrual_day_selection_by_month-chean
Draft

[IMP] hr_holidays: restrict day selection by month#5195
anchevalier wants to merge 1 commit into
master-hr-onboarding-cheanfrom
master-hr_holidays-accrual_day_selection_by_month-chean

Conversation

@anchevalier

Copy link
Copy Markdown

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

@anchevalier anchevalier self-assigned this Jun 26, 2026
@robodoo

robodoo commented Jun 26, 2026

Copy link
Copy Markdown

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 Mahmoudk3m left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@anchevalier anchevalier force-pushed the master-hr_holidays-accrual_day_selection_by_month-chean branch from 238bbb1 to dc221fe Compare July 8, 2026 12:13
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);
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants