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.

1

dynamic selection for year [Closed]

By
Maniganda
on 5/21/13, 5:58 AM 1,773 views

The Question has been closed

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

Hi,

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.

Thanks.

0

Sudhir Arya (SA)

--Sudhir Arya (SA)--
10150
| 6 8 8
Ahmedabad, India
--Sudhir Arya (SA)--

Working as an OpenERP/Odoo developer and a Team Leader 

Top 5 Odoo contributor On Stackoverflow

LinkedIn

Blog

Stackoverflow

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

Maniganda
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

Maniganda
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

Maniganda
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

Maniganda
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

Maniganda
on 5/21/13, 7:55 AM

About This Community

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

Question tools

0 follower(s)

Stats

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