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í
    Food & Hospitality
    • Bar a Pub
    • Restaurace
    • Fast Food
    • Guest House
    • Distributor nápojů
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architektonická firma
    • Stavba
    • Správa nemovitostí
    • Zahradnictví
    • Asociace vlastníků nemovitosti
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketingová agentura
    • Právník
    • Akvizice talentů
    • Audit a certifikace
    Výroba
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Korporátní dárky
    Zdraví a fitness
    • Sportovní klub
    • Prodejna brýli
    • Fitness Centrum
    • Wellness praktikové
    • Lékárna
    • Kadeřnictví
    Trades
    • Údržbář
    • IT hardware a podpora
    • Solar Energy Systems
    • Výrobce obuvi
    • Úklidové služby
    • HVAC Services
    Others
    • Nonprofit Organization
    • Agentura pro životní prostředí
    • Pronájem billboardů
    • Fotografování
    • Leasing jízdních kol
    • Prodejce softwaru
    Browse all Industries
  • 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
    • Services for Partners
    • 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

How to use selection on many2one?

Odebírat

Get notified when there's activity on this post

This question has been flagged
many2onev7selection
2 Odpovědi
15194 Zobrazení
Avatar
René Schuster

As described here, I have created a many2one field with custom selection function:

def _buyer_selection(self, cr, uid, context=None):
    partner_obj = self.pool.get('res.partner');
    res = [];
    partner_ids = partner_obj.search(cr, uid, [('buyer','=',True)]);
    for partner in partner_obj.browse(cr, uid, partner_ids, context=context):
        res.append((partner.id, partner.buyer_code))
    return res;

_columns = {
    'buyer_id': fields.many2one('res.partner', 'Buyer', selection=_buyer_selection),
}

But in the view

    <field name="buyer_id"/>

It still acts like a normal many2one field. All partners selectable, no buyer_code displayed.
Although:

debug_many2one

The debug view shows a perfectly working selection...

What am I missing?!

EDIT:

 <field name="buyer_id" widget="selection"/>

Selection widget doesn't work.
The field will become a selection field indeed, but the custom selection function seems to be overridden:

debug_many2one_2

0
Avatar
Zrušit
Prakash

I think based on your requirement to override name_get method and shows buyer_code

René Schuster
Autor

Thanks for your reply.

I only need the buyer_code in this single case. All other modules should show the partner.name.

Sajad KK

For your situation i think you should use fields.related

Avatar
René Schuster
Autor Nejlepší odpověď

Solved as prakash suggested.

Overriding name_get

def name_get(self, cr, uid, ids, context=None):
    if context.get('view_buyer_code', False):            
        res = [];
        for partner in self.browse(cr, uid, ids, context=context):
            res.append((partner.id, partner.buyer_code));
    else:
        res = super(res_partner_x, self).name_get(cr, uid, ids, context=context);
    return res;

And using context to control the viewed name

<field name="buyer_id" domain="[('buyer','=',True)]" context="{'view_buyer_code': True}"></field>

Only Disadvantage: After selectiong the Buyer the normal Partner name is displayed.
But I guess I can live with that.

0
Avatar
Zrušit
Avatar
Prakash
Nejlepší odpověď

In xml file many2one field add widget="selection"

<field name="buyer_id" widget="selection"/>
0
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
Display values from a pushed dict into a Many2one
many2one selection
Avatar
0
říj 20
3942
fields.many2one ('my.model', selection=_selection_function ) Retourn all 'my.model' records
many2one selection
Avatar
1
srp 17
4503
many to one filed shows object only
many2one selection
Avatar
Avatar
1
bře 15
6934
Why is a selection field used when a many2one field is better?
many2one selection
Avatar
0
bře 15
3721
Filter out results in a Many2One
many2one selection help
Avatar
Avatar
1
zář 23
2336
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