Skip to content

Commit bbbebd3

Browse files
committed
[IMP] hr_holidays: limit accrual plans and levels day selection based on selected month
The day selection for accrual plans carryover date and accrual levels yearly date is now limited to 29 or 30 depending on which month is selected. Task: 6191776
1 parent eb38cf1 commit bbbebd3

2 files changed

Lines changed: 38 additions & 2 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { selectionField, SelectionField } from "@web/views/fields/selection/selection_field";
2+
import { registry } from "@web/core/registry";
3+
4+
export class DaySelectionField extends SelectionField {
5+
static props = {
6+
...SelectionField.props,
7+
month: String,
8+
};
9+
10+
get options() {
11+
let allOptions = super.options;
12+
const monthValue = this.props.record.data[this.props.month];
13+
const maxDay = new Date(2020, monthValue, 0).getDate();
14+
allOptions = allOptions.filter((option) => option[0] <= maxDay);
15+
return allOptions;
16+
}
17+
}
18+
19+
export const daySelectionField = {
20+
...selectionField,
21+
component: DaySelectionField,
22+
extractProps({ attrs }) {
23+
return {
24+
...selectionField.extractProps(...arguments),
25+
month: attrs.month,
26+
};
27+
},
28+
fieldDependencies: ({ attrs }) => [
29+
{
30+
name: attrs.month,
31+
type: "selection",
32+
},
33+
],
34+
};
35+
36+
registry.category("fields").add("day_selection", daySelectionField);

addons/hr_holidays/views/hr_leave_accrual_views.xml

Lines changed: 2 additions & 2 deletions
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" class="o_field_accrual" widget="day_selection" month="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>
@@ -195,7 +195,7 @@
195195
options="{'links': {'other': 'carryover_custom_date'}, 'observe': 'carryover'}"/>
196196
<span id="carryover_custom_date">
197197
: the
198-
<field name="carryover_day" placeholder="select a day"
198+
<field name="carryover_day" widget="day_selection" month="carryover_month" style="width: 50px;" placeholder="select a day"
199199
required="carryover_date == 'other'"/>
200200
of
201201
<field name="carryover_month" placeholder="select a month"

0 commit comments

Comments
 (0)