禁用Odoo日期选择器中的先前日期 [英] Disable previous dates in Odoo datepicker

查看:95
本文介绍了禁用Odoo日期选择器中的先前日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想限制用户从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 by setting 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日期选择器中的先前日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆