Přejít na obsah
Odoo Menu
  • Přihlásit se
  • Vyzkoušejte zdarma
  • Aplikace
    Finance
    • Účetnictví
    • Fakturace
    • Výdaje
    • Spreadsheet (BI)
    • Dokumenty
    • Podpisy
    Prodej
    • CRM
    • Prodej
    • POS Obchod
    • POS Restaurace
    • Předplatné
    • Pronájem
    Webové stránky
    • Webové stránky
    • E-shop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Dodavatelský řetězec
    • Sklad
    • Výroba
    • PLM
    • Nákup
    • Údržba
    • Kvalita
    Lidské zdroje
    • Zaměstnanci
    • Nábor
    • Volno
    • Hodnocení zaměstnanců
    • Doporučení
    • Vozový park
    Marketing
    • Marketing sociálních sítí
    • Emailový marketing
    • SMS Marketing
    • Události
    • Marketingová automatizace
    • Dotazníky
    Služby
    • Projekt
    • Časové výkazy
    • Práce v terénu
    • Helpdesk
    • Plánování
    • Schůzky
    Produktivita
    • Diskuze
    • Schvalování
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Aplikace třetích stran Odoo Studio Odoo cloudová platforma
  • Branže
    Maloobchod
    • Knihkupectví
    • Obchod s oblečením
    • Obchod s nábytkem
    • Potraviny
    • Obchod s hardwarem
    • Hračkářství
    Jídlo a pohostinství
    • Bar a Pub
    • Restaurace
    • Fast Food
    • Penzion
    • Distributor nápojů
    • Hotel
    Nemovitost
    • Realitní kancelář
    • Architektonická firma
    • Stavba
    • Správa nemovitostí
    • Zahradnictví
    • Asociace vlastníků nemovitosti
    Poradenství
    • Účetní firma
    • Odoo Partner
    • Marketingová agentura
    • Právník
    • Akvizice talentů
    • Audit a certifikace
    Výroba
    • Textil
    • Kov
    • Nábytek
    • Jídlo
    • Pivovar
    • Korporátní dárky
    Zdraví a fitness
    • Sportovní klub
    • Prodejna brýli
    • Fitness Centrum
    • Wellness praktikové
    • Lékárna
    • Kadeřnictví
    Transakce
    • Údržbář
    • Podpora IT & hardware
    • Systémy solární energie
    • Výrobce obuvi
    • Úklidové služby
    • Služby HVAC
    Ostatní
    • Nezisková organizace
    • Agentura pro životní prostředí
    • Pronájem billboardů
    • Fotografování
    • Leasing jízdních kol
    • Prodejce softwaru
    Procházet všechna odvětví
  • Komunita
    Edukační program
    • Tutoriály
    • Dokumentace
    • Certifikace
    • Vzdělávání
    • Blog
    • Podcast
    Podpora vzdělávání
    • Vzdělávací program
    • Scale Up! Hra na firmu
    • Navštivte Odoo
    Získat software
    • Stáhnout
    • Porovnejte edice
    • Verze
    Spolupráce
    • Github
    • Fórum
    • Události
    • Překlady
    • Stát se partnerem
    • Služby pro partnery
    • Registrujte svou účetní firmu
    Získat služby
    • Najít partnera
    • Najít účetní
    • Setkejte se s poradcem
    • Implementační služby
    • Zákaznické reference
    • Podpora
    • Upgrady
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Dohodnout demo
  • Ceník
  • Pomoc

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

  • CRM
  • e-Commerce
  • Účetnictví
  • Sklad
  • PoS
  • Projekty
  • MRP
All apps
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
Pomoc

name_search is not working for Many2oneReference field

Odebírat

Get notified when there's activity on this post

This question has been flagged
V18Many2oneReference
2 Odpovědi
847 Zobrazení
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
Zrušit
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
Nejlepší odpověď

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
Zrušit
Avatar
Cybrosys Techno Solutions Pvt.Ltd
Nejlepší odpověď

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
Zrušit
Enjoying the discussion? Don't just read, join in!

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

Přihlásit se
Related Posts Odpovědi Zobrazení Aktivita
Hide 'Apps' module from the HOME screen for users not set as 'Administrators'. Vyřešeno
V18
Avatar
Avatar
1
čvn 25
2174
Truenas Official docker odoo self hosted image no persistancy
V18
Avatar
1
kvě 25
2482
Import Products - Internal Notes Vyřešeno
products V18
Avatar
Avatar
Avatar
2
zář 25
632
Error (Real-time connection lost) Odoo 18 Community Vyřešeno
V18 Odoo 18
Avatar
Avatar
Avatar
Avatar
Avatar
12
zář 25
32799
Inventory Adjustments - Importing File Vyřešeno
InventoryAdjustment V18
Avatar
Avatar
Avatar
3
zář 25
2145
Komunita
  • Tutoriály
  • Dokumentace
  • Fórum
Open Source
  • Stáhnout
  • Github
  • Runbot
  • Překlady
Služby
  • Odoo.sh hostování
  • Podpora
  • Upgrade
  • Nestandardní vývoj
  • Edukační program
  • Najít účetní
  • Najít partnera
  • Stát se partnerem
O nás
  • Naše společnost
  • Podklady značky
  • Kontakujte nás
  • Práce
  • Události
  • Podcast
  • Blog
  • Zákazníci
  • Právní dokumenty • Soukromí
  • Zabezpečení
الْعَرَبيّة 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 je balíček open-source aplikací, které pokrývají všechny potřeby vaší společnosti: CRM, e-shop, účetnictví, sklady, kasy, projektové řízení a další.

Unikátní nabídka od Odoo poskytuje velmi jednoduché uživatelské rozhraní a vše je integrované na jednom místě.

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