Odoo Help


Correctly search in one2many specific row

Diego Calzadilla
on 5/26/15, 1:58 AM 867 views

Hi, in product template I have defined one2many field to get something like this:



BRAND          MODEL         INIT YEAR         FINAL YEAR

nissan             sentra           2000                  2005

mazda             aveo             1998                  2004

The aim of this structure is to be able to search by model and year. Using the search box and typing 'sentra' as Model parameter, I get product A, this is great, just after this, I type 1998 as 'Search year' parameter and I also get product A because 1998 is part of range in row 2, this is wrong according to my requirement.

Is it possible that after typing the model paramater search the year only in the row in which appears the desired model?

Some piece of code:

     <field string="Model" name="application_data_product_template_ids" filter_domain="[('application_data_product_template_ids.model', 'ilike',self)]"/>

     <field name="date_search" />


        def _search_year(self, cr, uid, obj, name, args, context):

             x = [('application_data_product_template_ids.date_beg', '<=', args[0][2]),  ('application_data_product_template_ids.dateend', '>=', args[0][2])]

             res = self.search(cr, uid, x, context=context)

             return [('id', 'in', res)]

        'date_search': fields.function(lambda self: self, string='Search year', type='integer', fnct_search=_search_year),

Please, give some suggestions!!


About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 5/26/15, 1:58 AM
Seen: 867 times
Last updated: 5/26/15, 1:58 AM