Skip to content

Commit 48ef753

Browse files
committed
[FIX] Accrual frequency yearly day fixed
Select for yearly day for accrual allowed for users to selected impossible combinations of day and month (i.e. 31st February). UI has been fixed to limit the selection to possible days for each month. task-6199803
1 parent bb78e9a commit 48ef753

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { SelectionField, selectionField } from "@web/views/fields/selection/selection_field";
2+
import { registry } from "@web/core/registry";
3+
4+
export class YearlyDaySelectionField extends SelectionField {
5+
static props = {
6+
...SelectionField.props,
7+
// The name of the field that references the model whose fields will be shown to the user when using /field
8+
month: { type: String },
9+
};
10+
11+
get choices() {
12+
const original_choices = super.choices;
13+
const month = this.props.month;
14+
const monthVal = parseInt(this.props.record.data[month]);
15+
const n_days = luxon.DateTime.local(2020, monthVal).daysInMonth;
16+
return original_choices.filter((option) => parseInt(option.value) <= n_days );
17+
}
18+
}
19+
20+
export const yearlyDaySelectionField = {
21+
...selectionField,
22+
component: YearlyDaySelectionField,
23+
extractProps({attrs, options}, dynamicInfo){
24+
const props = selectionField.extractProps(...arguments);
25+
const month = options.month;
26+
return { ...props, month};
27+
}
28+
}
29+
// Register the widget
30+
registry.category("fields").add("yearly_day_selection_field", yearlyDaySelectionField);

addons/hr_holidays/views/hr_leave_accrual_views.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
</span>
4747
<span name="yearly" invisible="frequency != 'yearly'">
4848
on the
49-
<field nolabel="1" name="yearly_day" class="o_field_accrual" required="frequency == 'yearly'" placeholder="select a day"/>
49+
<field nolabel="1" name="yearly_day" required="frequency == 'yearly'" placeholder="select a day" widget="yearly_day_selection_field" options="{'month': 'yearly_month'}"/>
5050
of
5151
<field nolabel="1" name="yearly_month" class="o_field_accrual" required="frequency == 'yearly'" placeholder="select a month"/>
5252
</span>

0 commit comments

Comments
 (0)