Odoo Help


Python Warning message display

on 9/9/15, 1:19 AM 2,234 views

I have written a function like below Written in Python and XML. Which function like if user selects past date it will display a warning message called 'Past date not allowed.' I need to get warning message like 'Past date not allowed. Date selected is 04-09-2015(It should display the selected date also). How can we do this.


def onchange_start_date_past(self, cr, uid, ids, start_date, eofdate, year2, context=None):

res = {'value':{}}

chng_year = datetime.strptime(start_date, "%Y-%m-%d %H:%M:%S")

today = time.strftime('%Y-%m-%d %H:%M:%S')

current_date = datetime.strptime(today, '%Y-%m-%d %H:%M:%S')

if chng_year.year and year2:

if str(chng_year.year) != str(year2):

#res['value']['date_start'] = ''

res.update({'warning': {'title': _('Warning !'), 'message': _('Please enter correct Year.')}})

return res

d = self.months_between1(chng_year, current_date)

if d < 0:

#res['value']['date_start'] = ''

res.update({'warning': {'title': _('Warning !'), 'message': _('Past date not allowed.')}})

return res

return start_date


return False


&lt;field name='date_start' on_change="onchange_start_date_past(date_start, date_end, parent.year)"/&gt;

@hardikgiri Goswami Thanks a lot

on 9/9/15, 2:18 AM

Please accept the answer.

Hardikgiri Goswami
on 9/9/15, 2:18 AM

Hardikgiri Goswami

--Hardikgiri Goswami--
| 2 2 5
Rajkot, India
--Hardikgiri Goswami--

OpenERP/Odoo Customization/Integration Expert / Python Programmer

Email : hardikgiri.goswami@gmail.com

Skype ID : hardikgiri.goswami

Hardikgiri Goswami
On 9/9/15, 1:58 AM

Try This:

res.update({'warning': {'title': _('Warning !'), 'message': _('Past date not allowed.' + str(start_date))}})

Thank you

on 9/9/15, 3:02 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 9/9/15, 1:19 AM
Seen: 2234 times
Last updated: 9/9/15, 3:02 AM