Skip to content

Commit adad142

Browse files
committed
[FIX] hr_holidays: accrual plan day selection
Disable selecting non existing day of the month in accrual plan milestones Task: 5998551
1 parent 7502b2b commit adad142

2 files changed

Lines changed: 52 additions & 4 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { registry } from "@web/core/registry";
2+
import { SelectionField, selectionField } from "@web/views/fields/selection/selection_field";
3+
import { useEffect, useState } from "@odoo/owl";
4+
5+
function getDaysInMonth(month) {
6+
const m = parseInt(month, 10);
7+
if (!m || m < 1 || m > 12) return 31;
8+
return new Date(2020, m, 0).getDate();
9+
}
10+
11+
export class DaySelectField extends SelectionField {
12+
13+
static props = {
14+
...SelectionField.props,
15+
monthField: { type: String, optional: true },
16+
};
17+
18+
setup() {
19+
super.setup();
20+
this.ALL_DAY_OPTIONS = super.options;
21+
this.ALL_DAY_OPTIONS.sort((a) => parseInt(a));
22+
this.state = useState({
23+
maxDays: getDaysInMonth(this.props.record.data[this.props.monthField]),
24+
});
25+
26+
useEffect(() => {
27+
const monthValue = this.props.record.data[this.props.monthField];
28+
this.state.maxDays = getDaysInMonth(monthValue);
29+
}, () => [this.props.record.data[this.props.monthField]]);
30+
}
31+
32+
get options() {
33+
return this.ALL_DAY_OPTIONS.slice(0, this.state.maxDays);
34+
}
35+
}
36+
37+
export const daySelect = {
38+
...selectionField,
39+
component: DaySelectField,
40+
extractProps(fieldInfo, widget) {
41+
return {
42+
...selectionField.extractProps(fieldInfo, widget),
43+
monthField: fieldInfo.attrs.month_field,
44+
};
45+
},
46+
};
47+
48+
registry.category("fields").add("day_select", daySelect);

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" widget="day_select" month_field="first_month" placeholder="select a day" required="frequency == 'biyearly'"/>
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" widget="day_select" month_field="second_month" placeholder="select a day" required="frequency == 'biyearly'"/>
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" widget="day_select" month_field="yearly_month" required="frequency == 'yearly'" placeholder="select a day"/>
5050
of
5151
<field nolabel="1" name="yearly_month" class="o_field_accrual" required="frequency == 'yearly'" placeholder="select a month"/>
5252
</span>
@@ -192,7 +192,7 @@
192192
options="{'links': {'other': 'carryover_custom_date'}, 'observe': 'carryover'}"/>
193193
<span id="carryover_custom_date">
194194
: the
195-
<field name="carryover_day" placeholder="select a day"
195+
<field name="carryover_day" placeholder="select a day" widget="day_select" month_field="carryover_month"
196196
required="carryover_date == 'other'"/>
197197
of
198198
<field name="carryover_month" placeholder="select a month"

0 commit comments

Comments
 (0)