跳至内容
菜单
此问题已终结
2 回复
5127 查看

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