I am having Odoo 17 instance where I want to keep only specific date range enabled for selection in Date time picker, I have tried _getDatepickerOptions() but it is not working, I have used _getFlatpickrOptions() but not working, can I get some example of document for the same?
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- ลูกค้าสัมพันธ์
- e-Commerce
- ระบบบัญชี
- สินค้าคงคลัง
- PoS
- Project
- MRP
คำถามนี้ถูกตั้งค่าสถานะ
Hii,
Full Working Example in Odoo 17
Custom JavaScript Widget
/** @odoo-module **/
import { registry } from "@web/core/registry";
import { DateTimeField } from "@web/views/fields/datetime/datetime_field";
export class RestrictedDateTime extends DateTimeField {
/**
* Override flatpickr options to restrict the date range
*/
_getFlatpickrOptions() {
const options = super._getFlatpickrOptions();
return {
...options,
minDate: "2025-08-01",
maxDate: "2025-08-31",
};
}
}
// Register the widget
registry.category("fields").add("restricted_datetime", RestrictedDateTime);
Assign the Widget in XML View
You need to use your new widget restricted_datetime on the datetime field:
<field name="your_datetime_field" widget="restricted_datetime"/>
i hope it is usefull
Hi,
Try with the following code.
Python
from_period = fields.Date(string="From Date", required=True,
help="Choose the from date")
to_period = fields.Date(string="To Date", required=True,
help="Choose the to date")
XML
<label for="from_period" string="Period"/>
<div class="o_row">
<field name="from_period" widget="daterange" nolabel="1"
class="oe_inline"
options="{'related_end_date': 'to_period'}"/>
<i class="fa fa-long-arrow-right mx-2"
aria-label="Arrow icon" title="Arrow"/>
<field name="to_period" widget="daterange" nolabel="1"
class="oe_inline"
options="{'related_start_date': 'from_period'}"/>
</div>
Hope it helps
Hi Kedar Dave,
Use
<field name="date_begin" widget="daterange" options="{'related_end_date': 'date_end'}"/>
<field name="date_end" widget="daterange" options="{'related_start_date': 'date_begin'}"/>
Hope this help.
สนุกกับการพูดคุยนี้ใช่ไหม? เข้าร่วมเลย!
สร้างบัญชีวันนี้เพื่อเพลิดเพลินไปกับฟีเจอร์พิเศษและมีส่วนร่วมกับคอมมูนิตี้ที่ยอดเยี่ยมของเรา!
ลงชื่อRelated Posts | ตอบกลับ | มุมมอง | กิจกรรม | |
---|---|---|---|---|
|
1
พ.ย. 19
|
4024 | ||
|
0
ต.ค. 16
|
3773 | ||
|
1
มี.ค. 15
|
6171 | ||
|
3
มิ.ย. 25
|
826 | ||
|
0
มิ.ย. 24
|
1953 |