Disable previous dates in Odoo datepicker

旧巷老猫 提交于 2020-12-08 03:25:22

问题


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


回答1:


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


来源:https://stackoverflow.com/questions/38581583/disable-previous-dates-in-odoo-datepicker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!