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

Hello Gurus

I am confused by this error. Both values should be datetime, shouldnt they??

As you can tell, I am not much of a programmer.


scheduled_start = fields.Datetime(string="Scheduled Start", default=lambda self: fields.Datetime.today(), tracking=True)
scheduled_finish = fields.Datetime(string="Scheduled Finish", default=lambda self: fields.Datetime.today(), tracking=True)

ERROR:

if vals['scheduled_finish']

TypeError: '


Ive tried to cast to datetime and str types but no combination seems to work. Little help please?

TIA


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

Not sure what happened to the rest of the error but I'll try again:
if vals['scheduled_finish'] < self.scheduled_start:
TypeError: '<' not supported between instances of 'str' and 'datetime.datetime'

คำตอบที่ดีที่สุด

Hello Wombate,


This is TypeError comes when you matched the str and datetime

To handle this in write method :


//Code in Comment//


Thanks & Regards,

Email:  odoo@aktivsoftware.com           

Skype: kalpeshmaheshwari

อวตาร
ละทิ้ง

Code:

def write(self, vals):
res = super().write(vals)
if isinstance(vals.get("scheduled_finish"), str):
vals["scheduled_finish"] = datetime.strptime(vals['scheduled_finish'], '%Y-%m-%d %H:%M:%S')

if vals['scheduled_finish'] < self.scheduled_start:
# your logic here
return res

ผู้เขียน

Perfect Jainesh! Thank you so much.

คำตอบที่ดีที่สุด

Hi,

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
2
ก.พ. 25
743
0
ธ.ค. 24
588
1
เม.ย. 23
4740
1
มี.ค. 15
25443
1
มี.ค. 15
3951