Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odpovědět
5616 Zobrazení

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.

Avatar
Zrušit
Nejlepší odpověď

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





Avatar
Zrušit
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 Odpovědi Zobrazení Aktivita
1
srp 21
7766
2
říj 19
12740
1
lis 22
3323
2
srp 22
7665
1
kvě 22
5787