コンテンツへスキップ
メニュー
この質問にフラグが付けられました
2 返信
5114 ビュー

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)"