问题描述
我想限制用户从odoo-8的日期选择器中选择上一个日期.请给我如何禁用odoo datepicker中的以前的日期
有一个用于该模块的
我以前是这样做的在字段上设置一次onchange,每次更改该字段时都会触发该onchange,在onchange中,您可以将日期转换为python日期(使用odoo的默认时间格式)并将其与当前日期进行比较
from datetime导入datetime从openerp导入api从openerp.tools导入DEFAULT_SERVER_DATE_FORMAT从openerp.exceptions导入警告@ api.onchange('current_date')def onchange_date():如果datetime.strptime(self.current_date,DEFAULT_SERVER_DATE_FORMAT).date()<datetime.now().date():引发警告(请选择一个等于或大于当前日期的日期")返回False返回my_date
I want to restrict the user selecting previous date from the date picker of odoo-8. Please give me how to disable previous dates in odoo datepicker
There's a module for that https://apps.openerp.com/apps/modules/8.0/web_widget_datepicker_options/
If you have a date field named current_date
<field name="current_date" />
After installing the module, just add the option for the jquery datepicker minDate
and set it to 0 like this
<field name="current_date" options="{'datepicker':{'minDate': 0}}"/>
Screenshot
I previously did this bysetting an onchange on the field that'll be triggered every time the field is changed, and in the onchange you can convert the date to a python date (with odoo's default time format) and compare it to the current date
from datetime import datetime
from openerp import api
from openerp.tools import DEFAULT_SERVER_DATE_FORMAT
from openerp.exceptions import Warning
@api.onchange('current_date')
def onchange_date(self):
if datetime.strptime(self.current_date, DEFAULT_SERVER_DATE_FORMAT).date() < datetime.now().date():
raise warning('Please select a date equal/or greater than the current date')
return False
return my_date
这篇关于禁用Odoo日期选择器中的先前日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!