跳至內容
選單
此問題已被標幟
2 回覆
1562 瀏覽次數

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,

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
2
2月 25
1395
0
12月 24
999
1
4月 23
5195
1
3月 15
26189
1
3月 15
4263