İçereği Atla
Menü
Bu soru işaretlendi
2 Cevaplar
5139 Görünümler

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

Avatar
Vazgeç
En İyi Yanıt

Hello Supreeth KV,

Please find code in comment. 

I hope this will help you. 

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

Avatar
Vazgeç

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

En İyi Yanıt

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.

Avatar
Vazgeç
Üretici

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