Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
2 Răspunsuri
5111 Vizualizări

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

Imagine profil
Abandonează
Cel mai bun răspuns

Hello Supreeth KV,

Please find code in comment. 

I hope this will help you. 

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

Imagine profil
Abandonează

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

Cel mai bun răspuns

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.

Imagine profil
Abandonează
Autor

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