i have selected the start date. this selected date how will i validate/check to current date?
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Accounting
- Inventory
- PoS
- Project management
- MRP
This question has been flagged
3
Replies
10409
Views
Hi, you can use the below code to validate...
from datetime import datetime
start = datetime(2015, 1, 1)
current = datetime.now()
print current
print start < current
You can use current date as default
'today_date' : fields.date.context_today
Hi,
You can try the following code.
@api.constrains('start_date')
def _check_start_date(self):
for rec in self:
if rec.start_date raise ValidationError('start date cannot be in past')
Regards
Hi,
You can do something like below:
def _check_dates(self, cr, uid, ids, context=None):
if context == None:
context = {}
obj_task = self.browse(cr, uid, ids[0], context=context)
start = obj_task.start_date or False
end = time.strftime('%Y-%m-%d')
if start and end :
if start < end:
return False
return True
_constraints = [
(_check_dates, 'Error ! Start Date must be greater then Current Date', ['start_date'])
]
You can also apply this method on onchange method of start_date.
Hope this may help you.
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign up