Help

Is it possible to show the 'year' in date field as drop down like selection or many2one in openerp?

Closed
Avatar
Jasad

The question has been closed

by
Ray Carnes
on 09/26/2013 13:34:47

Is it possible to show the 'year' in date field as drop down like selection or many2one in openerp? . I have a situation that, i need to choose the year only from date field as a drop down.

2 Comments
Avatar
Discard
Avatar
Susi
-

i have the problem same with u, and i use your code 'tahun': fields.selection([(num, str(num)) for num in range(1900, (datetime.now().year)+1 )], 'Year'), error undefined datetime and now and i have use code import datetime...but its doesnt work..

Avatar
PT SIVI
-

Susi, try this

at the top of py file

from datetime import datetime, timedelta

it works for me

1 Answer
10
Avatar
Jasad
Best Answer

Hi All,

Finally found out the answer:

eg: 'year': fields.selection([(num, str(num)) for num in range(1900, (datetime.now().year)+1 )], 'Year'),

4 Comments
Avatar
Discard
Avatar
Bejaoui Souheil
-

thank you, +1

Avatar
Diego Calzadilla
-

great!!

Avatar
tertiadev
-

Thanks for this good answer! For Odoo 8: year = fields.Selection([(num, str(num)) for num in range( ((datetime.datetime.now().year)-10), ((datetime.datetime.now().year)+1) )] to get the last 10 years as a selection.

Avatar
Murugan Chinnasamy
-

This working fine!!!