Skip to content

Commit 785c23a

Browse files
sidum-odooarpi-odoo
authored andcommitted
[IMP] hr_holidays: restricted the day selection according to the month
Problem: Currently it's possible to select the "31st of February" in accrual plan and in its milestones, see: https://imgur.com/a/z3PqyE6 Solution: Created a new day_selection field component, extending from the selection field component. This new component takes a month_field as an option. It retrieves the selected month and compute the allowed days list. Task-6289950
1 parent 4021d1b commit 785c23a

3 files changed

Lines changed: 50 additions & 6 deletions

File tree

addons/hr_holidays/static/src/components/accrual_level/accrual_levels.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
}
1111

1212
.o_accrual {
13-
.o_field_accrual, .o_field_selection, .o_field_filterable_selection {
13+
.o_field_accrual, .o_field_selection, .o_field_day_selection, .o_field_filterable_selection {
1414
width: fit-content !important;
1515

1616
&:not(.o_readonly_modifier) > *:first-child {
@@ -20,7 +20,7 @@
2020
field-sizing: content;
2121
}
2222

23-
&:not(.o_field_selection, .o_field_filterable_selection) > *:first-child {
23+
&:not(.o_field_selection, .o_field_day_selection, .o_field_filterable_selection) > *:first-child {
2424
max-width: 8ch;
2525
}
2626
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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_field: {
8+
type: String,
9+
optional: true
10+
},
11+
}
12+
13+
get options() {
14+
let month = parseInt(this.props.record.data[this.props.month_field]);
15+
if (month) {
16+
let days_number = new Date(2024, month, 0).getDate()
17+
let new_options = []
18+
for (let i = 0 ; i < days_number ; i++) new_options[i] = [i + 1, i + 1]
19+
return new_options
20+
}
21+
else {
22+
return super.options
23+
}
24+
}
25+
}
26+
27+
export const daySelection = {
28+
...selectionField,
29+
component: DaySelectionField,
30+
extractProps({ options }) {
31+
const props = selectionField.extractProps(...arguments);
32+
props.month_field = options["month_field"];
33+
return props;
34+
},
35+
fieldDependencies({ options }){
36+
if (options["month_field"]) {
37+
return [{
38+
"name": options["month_field"]
39+
}]
40+
}
41+
},
42+
};
43+
44+
registry.category("fields").add("day_selection", daySelection);

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_hr_narrow_field-3" placeholder="select a day" required="frequency == 'biyearly'"/>
39+
<field nolabel="1" name="first_month_day" widget="day_selection" options="{'month_field' : 'first_month'}" class="o_hr_narrow_field-3" placeholder="select a day" required="frequency == 'biyearly'"/>
4040
of
4141
<field name="first_month" class="o_hr_narrow_field-5" placeholder="select a month" required="frequency == 'biyearly'"/>
4242
and the
43-
<field nolabel="1" name="second_month_day" class="o_hr_narrow_field-3" placeholder="select a day" required="frequency == 'biyearly'"/>
43+
<field nolabel="1" name="second_month_day" widget="day_selection" options="{'month_field' : 'second_month'}" class="o_hr_narrow_field-3" placeholder="select a day" required="frequency == 'biyearly'"/>
4444
of
4545
<field nolabel="1" name="second_month" class="o_hr_narrow_field-5" 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_hr_narrow_field-3" required="frequency == 'yearly'" placeholder="select a day"/>
49+
<field nolabel="1" name="yearly_day" widget="day_selection" options="{'month_field' : 'yearly_month'}" class="o_hr_narrow_field-3" required="frequency == 'yearly'" placeholder="select a day"/>
5050
of
5151
<field nolabel="1" name="yearly_month" class="o_hr_narrow_field-5" required="frequency == 'yearly'" placeholder="select a month"/>
5252
</span>
@@ -204,7 +204,7 @@
204204
options="{'links': {'other': 'carryover_custom_date'}, 'observe': 'carryover'}"/>
205205
<span id="carryover_custom_date">
206206
: the
207-
<field name="carryover_day" placeholder="select a day"
207+
<field name="carryover_day" widget="day_selection" options="{'month_field': 'carryover_month'}" placeholder="select a day"
208208
required="carryover_date == 'other'"/>
209209
of
210210
<field name="carryover_month" placeholder="select a month"

0 commit comments

Comments
 (0)