Odoo Help

1

dynamic selection for year [Closed]

By
Maniganda
on 5/21/13, 5:58 AM 2,437 views

The Question has been closed

by
Sudhir Arya (ERP Harbor Consulting Services)
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 (ERP Harbor Consulting Services)

--Sudhir Arya (ERP Harbor Consulting Services)--
11031
| 6 8 8
Ahmedabad, India
--Sudhir Arya (ERP Harbor Consulting Services)--

• Co-Founder & Co-Owner at ERP Harbor Consulting Services

• ERP Consultant / ERP Customization / TechnoFunctional Expert

• Sound knowledge in Python, Odoo (Open ERP), XML, PostgreSQL

• Domain knowledge of Sale Management, Purchase Management, Warehouse Management, Manufacturing, Multi Company Configuration & Management, HR Management, Medical Management, Construction Management, Education Management, Point of Sale, Third Party Integrations

• Positive attitude and quick Learner

• Good analytical skill, quick bug and issue tracing and find the solution

• Good knowledge and experience in payment gateway integration with Odoo

• Ready to accept new challenges

Top 10 Odoo contributor On Stackoverflow 

LinkedIn

Blog

Stackoverflow

Sudhir Arya
ERP Harbor Consulting Services
skype: 
sudhir@erpharbor.com 
Sudhir Arya (ERP Harbor Consulting Services)
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 (ERP Harbor Consulting Services)
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 (ERP Harbor Consulting Services)
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 (ERP Harbor Consulting Services)
on 5/21/13, 7:49 AM

Thank you for clear explanation

Maniganda
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.

Register

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)

Stats

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