Odoo Help


dynamic selection for year [Closed]

on 5/21/13, 5:58 AM 2,386 views

The Question has been closed

Sudhir Arya (SA)
on 05/21/2013 07:06:49


i have written functional field for date

def _get_year(self, cr, uid, context=None):
        year = int(time.strftime('%Y'))
        return [((year+r), (year+r)) for r in range(2)]

this is showing the values in selection field , if i try to save and edit the record,the value is not showing.


Sudhir Arya (SA)
On 5/21/13, 6:35 AM

Value of selection fields are store as char in database. So problem is that you are returning year as int. You have to return value in char form.

Try this:

return [(str((year+r)), str((year+r))) for r in range(2)]

This will solve your problem for sure.

year = 2000 #assign starting year
year_range = int(time.strftime('%Y')[-2:]) #this will give current year (like 13 for 2013)
[((str(year+r)), (str(year+r))) for r in range(year_range+1)]

If you want list from 2000 to 2013 + next 10 years, increment range value by 11 because loop starts from 0:

[((str(year+r)), (str(year+r))) for r in range(year_range+11)]

Thank you Arya , the problem is solved

on 5/21/13, 7:04 AM

I have a doubt here, if the current year is 2013 , this will return 2013 and 2014 , and if year is 2014 then i will get 2014 and 2015 , in this 2013 is deleted how to avoid this

on 5/21/13, 7:24 AM

That is because of your code. Method will return current year and next coming year only. So previous value will be overwritten by them and you won't be able to see old year's value.

Sudhir Arya (SA)
on 5/21/13, 7:28 AM

how to make modification for my function so that i can be able to see the previous years

on 5/21/13, 7:39 AM

You can set starting year as static and then can generate year's record till current year.

Sudhir Arya (SA)
on 5/21/13, 7:44 AM

ok ,and it is not possible to store value as integer in database rather than char

on 5/21/13, 7:47 AM

See my updated answer.

Sudhir Arya (SA)
on 5/21/13, 7:49 AM

Thank you for clear explanation

on 5/21/13, 7:55 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

0 follower(s)


Asked: 5/21/13, 5:58 AM
Seen: 2386 times
Last updated: 3/16/15, 8:10 AM