Skip to Content
Odoo Menú
  • Registra entrada
  • Prova-ho gratis
  • Aplicacions
    Finances
    • Comptabilitat
    • Facturació
    • Despeses
    • Full de càlcul (IA)
    • Documents
    • Signatura
    Vendes
    • CRM
    • Vendes
    • Punt de venda per a botigues
    • Punt de venda per a restaurants
    • Subscripcions
    • Lloguer
    Imatges de llocs web
    • Creació de llocs web
    • Comerç electrònic
    • Blog
    • Fòrum
    • Xat en directe
    • Aprenentatge en línia
    Cadena de subministrament
    • Inventari
    • Fabricació
    • PLM
    • Compres
    • Manteniment
    • Qualitat
    Recursos humans
    • Empleats
    • Reclutament
    • Absències
    • Avaluacions
    • Recomanacions
    • Flota
    Màrqueting
    • Màrqueting Social
    • Màrqueting per correu electrònic
    • Màrqueting per SMS
    • Esdeveniments
    • Automatització del màrqueting
    • Enquestes
    Serveis
    • Projectes
    • Fulls d'hores
    • Servei de camp
    • Suport
    • Planificació
    • Cites
    Productivitat
    • Converses
    • Validacions
    • IoT
    • VoIP
    • Coneixements
    • WhatsApp
    Aplicacions de tercers Odoo Studio Plataforma d'Odoo al núvol
  • Sectors
    Comerç al detall
    • Llibreria
    • Botiga de roba
    • Botiga de mobles
    • Botiga d'ultramarins
    • Ferreteria
    • Botiga de joguines
    Food & Hospitality
    • Bar i pub
    • Restaurant
    • Menjar ràpid
    • Guest House
    • Distribuïdor de begudes
    • Hotel
    Immobiliari
    • Agència immobiliària
    • Estudi d'arquitectura
    • Construcció
    • Gestió immobiliària
    • Jardineria
    • Associació de propietaris de béns immobles
    Consultoria
    • Empresa comptable
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Mobles
    • Menjar
    • Brewery
    • Regals corporatius
    Salut i fitness
    • Club d'esport
    • Òptica
    • Centre de fitness
    • Especialistes en benestar
    • Farmàcia
    • Perruqueria
    Trades
    • Servei de manteniment
    • Hardware i suport informàtic
    • Sistemes d'energia solar
    • Shoe Maker
    • Serveis de neteja
    • Instal·lacions HVAC
    Altres
    • Nonprofit Organization
    • Agència del medi ambient
    • Lloguer de panells publicitaris
    • Fotografia
    • Lloguer de bicicletes
    • Distribuïdors de programari
    Browse all Industries
  • Comunitat
    Aprèn
    • Tutorials
    • Documentació
    • Certificacions
    • Formació
    • Blog
    • Pòdcast
    Potenciar l'educació
    • Programa educatiu
    • Scale-Up! El joc empresarial
    • Visita Odoo
    Obtindre el programari
    • Descarregar
    • Comparar edicions
    • Novetats de les versions
    Col·laborar
    • GitHub
    • Fòrum
    • Esdeveniments
    • Traduccions
    • Converteix-te en partner
    • Services for Partners
    • Registra la teva empresa comptable
    Obtindre els serveis
    • Troba un partner
    • Troba un comptable
    • Contacta amb un expert
    • Serveis d'implementació
    • Referències del client
    • Suport
    • Actualitzacions
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Programar una demo
  • Preus
  • Ajuda

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

  • CRM
  • e-Commerce
  • Comptabilitat
  • Inventari
  • PoS
  • Projectes
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
Ajuda

Search options are not getting refined. (Coding problem)

Subscriure's

Get notified when there's activity on this post

This question has been flagged
searchcontext
3952 Vistes
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
Descartar
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
Autor

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
Autor

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!

Registrar-se
Related Posts Respostes Vistes Activitat
what I should put in the search([ ]) to match date in different model/database?
search context calculation
Avatar
Avatar
Avatar
6
de març 18
8761
context.get not working in xml search filter domain Solved
search context domain_filter
Avatar
1
de maig 16
10167
Context: function never called - need help
python search context
Avatar
0
de maig 15
3715
many2one search context
many2one search context
Avatar
Avatar
2
de març 15
8501
How do I filter a spreadsheet pivot to the current/previous month
search
Avatar
Avatar
1
de jul. 25
1460
Community
  • Tutorials
  • Documentació
  • Fòrum
Codi obert
  • Descarregar
  • GitHub
  • Runbot
  • Traduccions
Serveis
  • Allotjament a Odoo.sh
  • Suport
  • Actualització
  • Desenvolupaments personalitzats
  • Educació
  • Troba un comptable
  • Troba un partner
  • Converteix-te en partner
Sobre nosaltres
  • La nostra empresa
  • Actius de marca
  • Contacta amb nosaltres
  • Llocs de treball
  • Esdeveniments
  • Pòdcast
  • Blog
  • Clients
  • Informació legal • Privacitat
  • Seguretat
الْعَرَبيّة 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 és un conjunt d'aplicacions empresarials de codi obert que cobreix totes les necessitats de la teva empresa: CRM, comerç electrònic, comptabilitat, inventari, punt de venda, gestió de projectes, etc.

La proposta única de valor d'Odoo és ser molt fàcil d'utilitzar i estar totalment integrat, ambdues alhora.

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