Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Comment thread
feraz-odoo marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { registry } from "@web/core/registry";
import {
SelectionField,
selectionField,
selectionFieldProps,
} from "@web/views/fields/selection/selection_field";
import { useProps } from "@odoo/owl";

function daysInMonth(month) {
return new Date(2024, month, 0).getDate();
}

export class SelectionDayInMonthField extends SelectionField {
props = useProps({
...selectionFieldProps,
month_field: { type: String, optional: false },
});

get options() {
const month_field = this.props.month_field;
const month = this.props.record.data[month_field] ?? null;
const cap = daysInMonth(month) || 31;
const days = [];
for (let i = 1; i <= cap; i++) {
days.push([i.toString(), i.toString()]);
}
return days;
}
}

export const selectionDayInMonthField = {
...selectionField,
component: SelectionDayInMonthField,

extractProps({ options }) {
const props = selectionField.extractProps(...arguments);
props.month_field = options.month_field;
return props;
},
};

registry.category("fields").add("selection_day_in_month", selectionDayInMonthField);
25 changes: 20 additions & 5 deletions addons/hr_holidays/views/hr_leave_accrual_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,29 @@
</span>
<span name="biyearly" invisible="frequency != 'biyearly'">
on the
<field nolabel="1" name="first_month_day" class="o_hr_narrow_field-3" placeholder="select a day" required="frequency == 'biyearly'"/>
<field nolabel="1" name="first_month_day"
class="o_hr_narrow_field-3" placeholder="select a day"
widget="selection_day_in_month"
options="{'month_field': 'first_month'}"
required="frequency == 'biyearly'"/>
of
<field name="first_month" class="o_hr_narrow_field-5" placeholder="select a month" required="frequency == 'biyearly'"/>
and the
<field nolabel="1" name="second_month_day" class="o_hr_narrow_field-3" placeholder="select a day" required="frequency == 'biyearly'"/>
<field nolabel="1" name="second_month_day"
class="o_hr_narrow_field-3" placeholder="select a day"
widget="selection_day_in_month"
options="{'month_field': 'second_month'}"
required="frequency == 'biyearly'"/>
of
<field nolabel="1" name="second_month" class="o_hr_narrow_field-5" placeholder="select a month" required="frequency == 'biyearly'"/>
</span>
<span name="yearly" invisible="frequency != 'yearly'">
on the
<field nolabel="1" name="yearly_day" class="o_hr_narrow_field-3" required="frequency == 'yearly'" placeholder="select a day"/>
<field nolabel="1" name="yearly_day"
class="o_hr_narrow_field-3" placeholder="select a day"
widget="selection_day_in_month"
options="{'month_field': 'yearly_month'}"
required="frequency == 'yearly'"/>
of
<field nolabel="1" name="yearly_month" class="o_hr_narrow_field-5" required="frequency == 'yearly'" placeholder="select a month"/>
</span>
Expand Down Expand Up @@ -204,8 +216,11 @@
options="{'links': {'other': 'carryover_custom_date'}, 'observe': 'carryover'}"/>
<span id="carryover_custom_date">
: the
<field name="carryover_day" placeholder="select a day"
required="carryover_date == 'other'"/>
<field name="carryover_day"
placeholder="select a day"
widget="selection_day_in_month"
options="{'month_field': 'carryover_month'}"
required="carryover_date == 'other'"/>
of
<field name="carryover_month" placeholder="select a month"
required="carryover_date == 'other'"/>
Expand Down