Reputation: 497
I have defined a field called 'datetime'.
Here the time should be set to 08:00 by default and date we need to set manually.
How can we do this ?
I did something like this, here am setting date & time by default. But unable to set only time.
_defaults = {
'date_start': lambda self,cr,uid,context=None: fields.date.context_today(self,cr,uid,context) + " 02:30:00",
}
Please Suggest.
Thanks.
Upvotes: 2
Views: 73
Reputation: 14746
You should try following,
from datetime import datetime
_defaults = {
'date_start': datetime.now().strftime("%Y-%m-%d") + " 08:00:000",
}
### Suppose user will input start date in date_start field then your code should be like this,
def create(self, cr, uid, vals, context=None):
date = vals.get('date_start',False)
if date:
vals.update({'date_start':date.strftime("%Y-%m-%d") + " 08:00:000"})
return super(class_name, self).create(cr, uid, vals, context=context)
Upvotes: 1