Create module web_datetime_picker_default_time

This commit is contained in:
Akim Juillerat
2024-07-10 21:24:05 +02:00
parent c177834d57
commit 65bdd44cf8
10 changed files with 186 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
/** @odoo-module **/
/* Copyright 2024 Camptocamp
* License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) */
import {DatePicker, DateTimePicker} from "@web/core/datepicker/datepicker";
import {patch} from "@web/core/utils/patch";
patch(DateTimePicker.prototype, "DateTimePickerDefaultTime", {
onMounted() {
this._super.apply(this, arguments);
this.addPickerListener("change", ({date, oldDate}) => {
const default_time = this.props.defaultTime;
if (date && !oldDate && default_time) {
// FIXME: Consider TZ
date.set({
hour: default_time.hour,
minute: default_time.minute,
second: default_time.second,
});
window.$(this.rootRef.el).datetimepicker("date", date);
}
});
},
});
DateTimePicker.props = _.extend({}, DatePicker.props, {
defaultTime: {
type: Object,
shape: {
hour: Number,
minute: Number,
second: Number,
},
optional: true,
},
});