Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
1 Ответить
5612 Представления

Hi all

I have defined these fields:

   'date_beg': fields.selection([(num, str(num)) for num in range(1900, (datetime.now().year)+1 )], 'Año inicial'),

   'date_end': fields.selection([(num, str(num)) for num in range(1900, (datetime.now().year)+1 )], 'Año final'),

They generate integer variables in my table:

ID          date_beg       date_end

1              1999                2005

2              2000                2004

3              1990                1995


My requirement is that when user types a year in search view, odoo will show the records on which this year belongs based on ranges.

For example, If I type '2003' in search view and I have above table values, then odoo will display records with id value 1 & 2.

Please, some suggestions!!

Thanks in advance!

Аватар
Отменить
Лучший ответ

Hello,

A way, (maybe not the best) is to add a function field with a function search to adapt the query.

And you can Add a filter "By year" in search view to make it invisible for end user...


def _search_year(self, cr, uid, obj, name, args, context):
x = [('date_beg', '>=', args[0][2]), ('date_end', '<=', args[0][2])]
res = self.search(cr, uid, x, context=context)
return [('id', 'in', res)]

...

    'date_beg': fields.selection([(num, str(num)) for num in range(1900, (datetime.now().year)+1 )], 'Año inicial'),
'date_end': fields.selection([(num, str(num)) for num in range(1900, (datetime.now().year)+1 )], 'Año final'),
'date_search': fields.function(lambda self: self, string='Año search', type='integer', fnct_search=_search_year)

Let us know it it works ... 

Аватар
Отменить
Автор

awesome!! this works! Thanks a lot!

It is a sample but you need to check all args and not only take the first one ... [0][2] should disappear ...

Related Posts Ответы Просмотры Активность
3
июн. 25
1783
1
янв. 25
18447
0
сент. 21
1388
1
янв. 20
4369
1
дек. 19
6872