Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
5630 มุมมอง

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.

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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





อวตาร
ละทิ้ง
ผู้เขียน

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 ตอบกลับ มุมมอง กิจกรรม
1
ส.ค. 21
7771
2
ต.ค. 19
12746
Hide menu for all except specific group แก้ไขแล้ว
1
พ.ย. 22
3328
Live tracking in odoo. แก้ไขแล้ว
2
ส.ค. 22
7669
1
พ.ค. 22
5792