跳至內容
選單
此問題已被標幟
2 回覆
5108 瀏覽次數

python function that creates automatically a dropdown year selector (that is a "select" element poulated with all years starting from current and dating back to a given year)?

I don't need day/month (otherwise i'd have used the datepicker), i just need the year!

Thanks in advance

頭像
捨棄
最佳答案

Hello Supreeth KV,

Please find code in comment. 

I hope this will help you. 

Thanks & Regards,
Email: odoo@aktivsoftware.com
Skype: kalpeshmaheshwari

頭像
捨棄

You can used the selection field code like this:

def years():
current_year = date.today()
year = current_year.year
y = []
for i in range(2010, year):
Y.append((str(i), str(i)))
return y

最佳答案

I don't know of any functionality, but it should be easily built using a fields.selection and using a method to fill in the options.

Alternatively, if you are going to use this in the context of fiscal years, you can always access the corresponding object (account.fiscalyear) and display it using a selection widget.

頭像
捨棄
作者

fields.selection is not good idea. so i am trying to auto populate the years. i wrote a function like this def "populate_year(self, cr, uid, ids, name, args, context=None): years = date.today().year curryear = date.today().year loops = years[-2:] + 10 year_dropdown = [] for y in range(2010, (datetime.datetime.now().year + loops)): year_dropdown.append((y, y))" But i am facing an issue called "TypeError: populate_year() takes at least 6 arguments (4 given)"