Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { registry } from "@web/core/registry";
import { SelectionField, selectionField } from "@web/views/fields/selection/selection_field";

export class MonthSpecificDays extends SelectionField {
static props = {
...SelectionField.props,
monthFieldName: String,
};

get options() {
const days = this.props.record.fields[this.props.name].selection;
const month = this.props.record.data[this.props.monthFieldName];
const lastDay = new Date(2024, month, 0).getDate(); // method call will return last day of the month, used 2024 as it's a leap year
return days.filter((day) => day[0] <= lastDay);
}
}

export const monthSpecificDays = {
...selectionField,
component: MonthSpecificDays,
extractProps({ options }) {
return {
...selectionField.extractProps(...arguments),
monthFieldName: options.depends_on,
};
},
};

registry.category("fields").add("month_specific_days", monthSpecificDays);
8 changes: 4 additions & 4 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,17 @@
</span>
<span name="biyearly" invisible="frequency != 'biyearly'">
on the
<field nolabel="1" name="first_month_day" class="o_field_accrual" placeholder="select a day" required="frequency == 'biyearly'"/>
<field nolabel="1" name="first_month_day" widget="month_specific_days" options="{'depends_on': 'first_month'}" class="o_field_accrual" placeholder="select a day" required="frequency == 'biyearly'"/>
of
<field name="first_month" class="o_field_accrual" placeholder="select a month" required="frequency == 'biyearly'"/>
and the
<field nolabel="1" name="second_month_day" class="o_field_accrual" placeholder="select a day" required="frequency == 'biyearly'"/>
<field nolabel="1" name="second_month_day" widget="month_specific_days" options="{'depends_on': 'second_month'}" class="o_field_accrual" placeholder="select a day" required="frequency == 'biyearly'"/>
of
<field nolabel="1" name="second_month" class="o_field_accrual" placeholder="select a month" required="frequency == 'biyearly'"/>
</span>
<span name="yearly" invisible="frequency != 'yearly'">
on the
<field nolabel="1" name="yearly_day" class="o_field_accrual" required="frequency == 'yearly'" placeholder="select a day"/>
<field nolabel="1" name="yearly_day" widget="month_specific_days" options="{'depends_on': 'yearly_month'}" class="o_field_accrual" required="frequency == 'yearly'" placeholder="select a day"/>
of
<field nolabel="1" name="yearly_month" class="o_field_accrual" required="frequency == 'yearly'" placeholder="select a month"/>
</span>
Expand Down Expand Up @@ -192,7 +192,7 @@
options="{'links': {'other': 'carryover_custom_date'}, 'observe': 'carryover'}"/>
<span id="carryover_custom_date">
: the
<field name="carryover_day" placeholder="select a day"
<field name="carryover_day" widget="month_specific_days" options="{'depends_on': 'carryover_month'}" placeholder="select a day"
required="carryover_date == 'other'"/>
of
<field name="carryover_month" placeholder="select a month"
Expand Down