Odoo Help

Welcome!

This community 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.

0

Python Warning message display

By
supreeth
on 9/9/15, 1:19 AM 883 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.

Python:

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

else:

return False


XML:

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

@hardikgiri Goswami Thanks a lot

supreeth
on 9/9/15, 2:18 AM

Please accept the answer.

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

Hardikgiri Goswami

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

OpenERP/Odoo Customization/Integration Expert / Python Programmer

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

supreeth
on 9/9/15, 3:02 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

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