Reputation: 1168
I my trying to set default time in odoo create function get below error:
TypeError: replace() takes no keyword arguments
Code:
@api.model
def create(self, values):
if 'deadline' in values:
values['deadline'].replace(hour=23, minute=59, second=59, microsecond=999999)
line = super(SurveyUserInputInherit, self).create(values)
return line
Thanks in advance.
Upvotes: 1
Views: 269
Reputation: 196
Odoo stores datetime fields as string. So if you want to replace time in create
function you need to convert it to datetime first. You can do it with function fields.Datetime.from_string
and then again convert it to string, with fields.Datetime.to_string
or just str
So in your case, this should do it:
from odoo import fields
@api.model
def create(self, values):
if 'deadline' in values:
deadline = fields.Datetime.from_string(values['deadline'])
deadline = deadline.replace(hour=23, minute=59, second=59)
values['deadline'] = fields.Datetime.to_string(deadline)
line = super(SurveyUserInputInherit, self).create(values)
return line
Btw odoo doesn't store microsecond so it is unnecessary to replace.
Upvotes: 2