Odoo Help


Search options are not getting refined. (Coding problem)

Arjun Khode
on 2/12/15, 6:43 AM 806 views

I'm trying to implement a boat company module.

I have various boats, and each boat has model options, like engine names, etc.

In my sale.order module, I have extended the module to be able to enter boat name

In the Order Lines page of that form, I have an option to select the model options relevant to that boat name. And I'm trying to implement a search function that refines the results of that drop down to only the models of that particular boat's id we just selected above.

I wrote the function but it's not working for some reason. Can you please help me out?

Here are the relevant files:


<record id="sale_view_order_form" model="ir.ui.view">
            <field name="model">sale.order</field>
            <field name="inherit_id" ref="sale.view_order_form"/>
            <field name="arch" type="xml">
                <field name="partner_id" position="after">
                    <field name="boatmodel_id"/>            
                <xpath expr="//field[@name='product_id']" position="attributes">
                    <attribute name="context">
                        {'boatmodel_id': parent.boatmodel_id}


class product_template(osv.osv):
              'boatlength':fields.char("Boat Length", size=18),
              'fuelcapacity':fields.char("Fuel Capacity", size=18),
              'modeloptions_id':fields.many2one("product.category","Model Options"),
    def search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, count=False):
        print("Hii Search has started")
        if context is None:
            print("Heloo context was none")
        if context.get('boatmodel_id'):
            print context['boatmodel_id']
            #code to limit by category assigned to the boat model
            productobj=self.pool.get('product.template').read(cr, uid, context['boatmodel_id'],['modeloptions_id'])
            args=[('categ_id','=',productobj['modeloptions_id'][0])] + args
        return super(product_template, self).search(cr, uid, args, offset, limit, order, context=context, count=count)
class sale_order(osv.osv):
              'boatmodel_id':fields.many2one("product.template","Boat Model", domain=[('categ_id.name','=','Boat Models')]),

Note:As you may have noticed, I have written print statements to test the outputs of the search function on the console. But nothing ever gets printed. I guess the search function never gets called. I'm using Odoo 8

Its obvious that your search method will not be called as you are calling and checking method of product_template and you have updated product_id's context which is of product_product. so when making change in product_product will not call search method of product_template.

Mansi Kariya (mka)
on 2/12/15, 6:54 AM

Thanks for pointing it out. Can you suggest a way how I can keep things within product_template and implement the same functionality? Is there anything else I can use instead of product_id ?

Arjun Khode
on 2/12/15, 7:10 AM

But why are you changing template. According to me you are going wrong. instead you need to add this fields to product_product, Any ways its up requirements, But if you maintain though product_product it would be easy and well maintained.

Mansi Kariya (mka)
on 2/12/15, 7:26 AM

Ok. I will try rewriting the code in product_product :)

Arjun Khode
on 2/12/15, 7:32 AM

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: 2/12/15, 6:43 AM
Seen: 806 times
Last updated: 3/16/15, 8:10 AM