Odoo Help

Welcome!

This community 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.

0

Correctly search in one2many specific row

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

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!

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

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