Skip to content

Commit 2576db8

Browse files
committed
[FIX] hr_holidays: Accrual UX
The selection field of days in the accrual plan milestones was always showing 31 days in the options regardless the month. A new JavaScript Class was created that extends the "SelecionField" to dynamically change the options and show the number of days depending on the month by accessing the month from props. Task: 6199932
1 parent 4804662 commit 2576db8

2 files changed

Lines changed: 45 additions & 4 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { SelectionField, selectionField } from "@web/views/fields/selection/selection_field";
2+
import { registry } from "@web/core/registry";
3+
4+
export class AccrualDaySelection extends SelectionField {
5+
static props = {
6+
...SelectionField.props,
7+
};
8+
9+
get options() {
10+
const allOptions = super.options;
11+
12+
const monthFieldName = this.props.monthFieldName;
13+
14+
if (!monthFieldName) return allOptions;
15+
16+
const monthValue = this.props.record.data[monthFieldName];
17+
18+
if (!monthValue) return allOptions;
19+
20+
const month = parseInt(monthValue);
21+
let maxDays = 31;
22+
if ([4, 6, 9, 11].includes(month)) {
23+
maxDays = 30;
24+
} else if (month === 2) {
25+
maxDays = 29;
26+
}
27+
28+
return allOptions.filter((opt) => parseInt(opt[0]) <= maxDays);
29+
}
30+
}
31+
32+
33+
registry.category("fields").add("accrual_day_dropdown", {
34+
...selectionField,
35+
component: AccrualDaySelection,
36+
extractProps: (fieldInfo, dynamicInfo) => {
37+
const props = selectionField.extractProps(fieldInfo,dynamicInfo);
38+
props.monthFieldName = fieldInfo.options.month_field;
39+
return props;
40+
},
41+
});

addons/hr_holidays/views/hr_leave_accrual_views.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,17 @@
3636
</span>
3737
<span name="biyearly" invisible="frequency != 'biyearly'">
3838
on the
39-
<field nolabel="1" name="first_month_day" class="o_field_accrual" placeholder="select a day" required="frequency == 'biyearly'"/>
39+
<field nolabel="1" name="first_month_day" class="o_field_accrual" placeholder="select a day" required="frequency == 'biyearly'" widget="accrual_day_dropdown" options="{'month_field': 'first_month'}"/>
4040
of
4141
<field name="first_month" class="o_field_accrual" placeholder="select a month" required="frequency == 'biyearly'"/>
4242
and the
43-
<field nolabel="1" name="second_month_day" class="o_field_accrual" placeholder="select a day" required="frequency == 'biyearly'"/>
43+
<field nolabel="1" name="second_month_day" class="o_field_accrual" placeholder="select a day" required="frequency == 'biyearly'" widget="accrual_day_dropdown" options="{'month_field': 'second_month'}"/>
4444
of
4545
<field nolabel="1" name="second_month" class="o_field_accrual" placeholder="select a month" required="frequency == 'biyearly'"/>
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" class="o_field_accrual" required="frequency == 'yearly'" placeholder="select a day" widget="accrual_day_dropdown" options="{'month_field': 'yearly_month'}"/>
5050
of
5151
<field nolabel="1" name="yearly_month" class="o_field_accrual" required="frequency == 'yearly'" placeholder="select a month"/>
5252
</span>
@@ -196,7 +196,7 @@
196196
<span id="carryover_custom_date">
197197
: the
198198
<field name="carryover_day" placeholder="select a day"
199-
required="carryover_date == 'other'"/>
199+
required="carryover_date == 'other'" widget="accrual_day_dropdown" options="{'month_field': 'carryover_month'}"/>
200200
of
201201
<field name="carryover_month" placeholder="select a month"
202202
required="carryover_date == 'other'"/>

0 commit comments

Comments
 (0)