Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

Search options are not getting refined. (Coding problem)

Subscribe

Get notified when there's activity on this post

This question has been flagged
searchcontext
3953 Views
Avatar
Arjun Khode

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:

XML:

<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"/>            
                </field>
                <xpath expr="//field[@name='product_id']" position="attributes">
                    <attribute name="context">
                        {'boatmodel_id': parent.boatmodel_id}
                    </attribute>
                </xpath>
            </field>
        </record>

PY:

class product_template(osv.osv):
    _inherit="product.template"
    _columns={
              '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")
            context={}
        if context.get('boatmodel_id'):
            print("CONTEXT========")
            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):
    _inherit="sale.order"
    _columns={
              '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

0
Avatar
Discard
Mansi Kariya (mka)

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.

Arjun Khode
Author

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 ?

Mansi Kariya (mka)

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.

Arjun Khode
Author

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

Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Sign up
Related Posts Replies Views Activity
what I should put in the search([ ]) to match date in different model/database?
search context calculation
Avatar
Avatar
Avatar
6
Mar 18
8761
context.get not working in xml search filter domain Solved
search context domain_filter
Avatar
1
May 16
10167
Context: function never called - need help
python search context
Avatar
0
May 15
3715
many2one search context
many2one search context
Avatar
Avatar
2
Mar 15
8501
How do I filter a spreadsheet pivot to the current/previous month
search
Avatar
Avatar
1
Jul 25
1460
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now