Skip to Content
Menu
This question has been flagged
1 Reply
2692 Views

@api.multi
@api.onchange('exam_date')
def onchange_date_onday(self):
for rec in self:
if rec.exam_date:
week_day = datetime.strptime(rec.exam_date, "%Y-%m-%d")
rec.day_of_week = week_day.strftime("%A").title()

i wrote this code getting this error what i will do anybody can help me


Avatar
Discard
Best Answer

Hi,

You might have defined the following line outside the if statement,

rec.day_of_week = week_day.strftime("%A").title()


If the value for the rec.exam_date field is not there, the value for the variable week_day is not assigned/defined. Then outside the if statement you are accessing the same undefined the variable, thus you get this error.


You can update your code like this,

if rec.exam_date:
    week_day = datetime.strptime(rec.exam_date, "%Y-%m-%d")

    if week_day:
        rec.day_of_week = week_day.strftime("%A").title()

Thanks

Avatar
Discard
Author

thank you soomuch niyas its working

Related Posts Replies Views Activity
1
Nov 24
18020
1
Sep 23
1206
3
May 23
4095
7
Apr 23
47099
1
Dec 22
6438