Skip to content

Commit fe36bdb

Browse files
committed
[FIX] hr_payroll_account: restrict invalid days in accrual plans and milestones
Currently, it is possible to select non-existent days like February 31st when configuring accrual plans and their milestones. Restricts the day selection according to the month. Task-6297384
1 parent 0c8eba6 commit fe36bdb

3 files changed

Lines changed: 44 additions & 6 deletions

File tree

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

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

addons/hr_holidays/views/hr_leave_accrual_views.xml

Lines changed: 5 additions & 5 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" month="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" month="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" month="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,8 +204,8 @@
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"
208-
required="carryover_date == 'other'"/>
207+
<field name="carryover_day" placeholder="select a day" widget="day_selection" month="carryover_month"
208+
required="carryover_date == 'other'" class="w-100"/>
209209
of
210210
<field name="carryover_month" placeholder="select a month"
211211
required="carryover_date == 'other'"/>

0 commit comments

Comments
 (0)