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

name_search is not working for Many2oneReference field

Subscriure's

Get notified when there's activity on this post

This question has been flagged
V18Many2oneReference
2 Respostes
845 Vistes
Avatar
Ihor

I'm using Odoo 18. I have the following models:

  • document.foo

class FooDocument(models.Model):

  _name = 'document.foo'

  _description = 'Foo'


  date = fields.Datetime(

    string='Date',

  )

  number = fields.Char(

    string='Number',

  )

  • document.bar

class BarDocument(models.Model):

  _name = 'document.bar'

  _description = 'Bar'


  date = fields.Datetime(

    string='Date',

  )

  number = fields.Char(

    string='Number',

  )

  • document.invoice
class InvoiceDocument(models.Model):
  _name = 'document.invoice'
  _description = 'Invoice'

  date = fields.Datetime(
    string='Date',
  )
  number = fields.Char(
    string='Number',
  )
  doc_base_name = fields.Selection(
    string='Base Document Type',
    selection=[
      ('document.foo', 'Foo'),
      ('document.bar', 'Bar'),
    ],
    default='document.foo',
  )
  doc_base_id = fields.Many2oneReference(
    string='Base Document',
    model_field='doc_base_name',
  )

Also, I have the following view for document.invoice​​

<record id="document_invoice_view_form" model="ir.ui.view">

<field name="name">document.invoice.form</field>

<field name="model">document.invoice</field>

<field name="arch" type="xml">

<form>

<sheet>

<group>

<field name="date" />

<field name="number" />

<field name="doc_base_name" />

<field name="doc_base_id" />

</group>

</sheet>

</form>

</field>

</record>

Then, I am doing the following actions in the Odoo web interface:

1.Creating new records of document.foo​​

2.Creating a new record of document.invoice

*Choosing Foo value in the doc_base_name (Base Document Type) field

*Trying to choose a value in the doc_base_id (Base Document) field, but there are no values. name_search​ method doesn't return values

How to solve this problem with doc_base_id (Many2oneReference) field?

1
Avatar
Descartar
Ihor
Autor

Thank you for your answers! It turned out the reason was the old version of my 18.0 branch from Github. The problem disappeared after pulling current version.

Avatar
Christoph Farnleitner
Best Answer

Your example source works perfectly fine in terms of having the Many2oneReference field be a (M2o-)selection of Foo or Bar:


The name_search in fact would in your case return always all values - because there just isn't any definition of what an entered name should be searched against (since there's no name field).

If you would, for example, set a _rec_name on the Foo and Bar models (or define an name, or a computed display_name), i.e.

class DocumentFoo(models.Model):
    _name = 'document.foo'
    _description = 'Foo'
    _rec_name = 'number'

    date = fields.Datetime(string='Date', )
    number = fields.Char(string='Number', )

 

also your name_search would actually return a 'filtered' result.

1
Avatar
Descartar
Avatar
Cybrosys Techno Solutions Pvt.Ltd
Best Answer

Hi,

You need to give document.foo and document.bar models a way to represent themselves.


If you want to use the existing number field as the record name:


class FooDocument(models.Model):

    _name = 'document.foo'

    _description = 'Foo'

    _rec_name = 'number' # <--- Add this


    date = fields.Datetime(string='Date')

    number = fields.Char(string='Number')



class BarDocument(models.Model):

    _name = 'document.bar'

    _description = 'Bar'

    _rec_name = 'number' # <--- Add this


    date = fields.Datetime(string='Date')

    number = fields.Char(string='Number')



This way, when you open the dropdown for doc_base_id, Odoo will display the number values of Foo/Bar records.


Hope it helps.

1
Avatar
Descartar
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
Hide 'Apps' module from the HOME screen for users not set as 'Administrators'. Solved
V18
Avatar
Avatar
1
de juny 25
2172
Truenas Official docker odoo self hosted image no persistancy
V18
Avatar
1
de maig 25
2477
Import Products - Internal Notes Solved
products V18
Avatar
Avatar
Avatar
2
de set. 25
630
Error (Real-time connection lost) Odoo 18 Community Solved
V18 Odoo 18
Avatar
Avatar
Avatar
Avatar
Avatar
12
de set. 25
32781
Inventory Adjustments - Importing File Solved
InventoryAdjustment V18
Avatar
Avatar
Avatar
3
de set. 25
2141
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