Odoo Help

0

0
3 Answers
0
Rohit Ramnani (ror)
2017/08/10 3:04

Just write following code and call this method into selection field like :

  def _get_years(self):

        this_year = datetime.today().year

        results = sorted([(str(x), str(x)) for x in range(this_year - 40, this_year + 1)],reverse = True)

        return results

year_selection : fields.Selection(_get_years,string="select year)

1 Comment
Deb Joy
2017/08/10 20:28

Thank you! It worked.

0
Avatar

Avinash Nk

--Avinash Nk--

10270
| 5 4 9
Calicut, India
--Avinash Nk--

Odoo Developer

LinkedIn : https://in.linkedin.com/in/avinash-nk




Avinash Nk
2017/08/10 1:32

Hi Dee Yoj,

Try This Code 

from datetime import datetime
from odoo import fields, models, api


class YourClass(models.Model):
_inherit = 'your.model'

this_year = datetime.today().year
range_of_years = range(this_year - 40, this_year + 1)
descending_range = sorted(range_of_years, reverse=True)
_get_years = [(str(x), str(x)) for x in descending_range]
year_selection = fields.Selection(_get_years, string="Select Year")


 Thank you.

1 Comment
Deb Joy
2017/08/10 1:44

It worked! thank you so much.

Ask a Question
Writer
Keep Informed
1 follower(s)
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 eLearning platform and experience all Odoo Apps through learning videos, use cases and quizzes.

Test it now