Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
1 Răspunde
5620 Vizualizări

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.

Imagine profil
Abandonează
Cel mai bun răspuns

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





Imagine profil
Abandonează
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

Related Posts Răspunsuri Vizualizări Activitate
1
aug. 21
7768
2
oct. 19
12742
1
nov. 22
3323
2
aug. 22
7665
1
mai 22
5787