This question has been flagged

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

PRODUCT: A

APPLICATION DATA

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!!


Thanks!

Avatar
Discard