Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
5650 Widoki

Hello Community,

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.

Awatar
Odrzuć
Najlepsza odpowiedź

that is because values['deadline'] is str object not time object...

to handle that:

from  odoo.tools  import  DEFAULT_SERVER_DATE_FORMAT as DF
from datetime import datetime

dt_obj = datetime.strptime(values['deadline'], DF)
dt_obj.replace(hour=23, minute=59, second=59, microsecond=999999)
values['deadline'] = fields.Datetime.to_string(dt_obj)

if it helped you just vote





Awatar
Odrzuć
Autor

Hi Beshoy, Run your code getting no error but time is still 5:30.

@api.model
def create(self, values):
if 'deadline' in values:
dt_obj = datetime.strptime(values['deadline'], DF)
dt_obj.replace(hour=23, minute=59, second=59, microsecond=999999)
values['deadline'] = fields.Datetime.to_string(dt_obj)
line = super(SurveyUserInputInherit, self).create(values)
return line

Powiązane posty Odpowiedzi Widoki Czynność
1
sie 21
7791
2
paź 19
12781
1
lis 22
3356
2
sie 22
7689
1
maj 22
5820