Passa al contenuto
Odoo Menu
  • Accedi
  • Provalo gratis
  • App
    Finanze
    • Contabilità
    • Fatturazione
    • Note spese
    • Fogli di calcolo (BI)
    • Documenti
    • Firma
    Vendite
    • CRM
    • Vendite
    • Punto vendita Negozio
    • Punto vendita Ristorante
    • Abbonamenti
    • Noleggi
    Siti web
    • Configuratore sito web
    • E-commerce
    • Blog
    • Forum
    • Live chat
    • E-learning
    Supply chain
    • Magazzino
    • Produzione
    • PLM
    • Acquisti
    • Manutenzione
    • Qualità
    Risorse umane
    • Dipendenti
    • Assunzioni
    • Ferie
    • Valutazioni
    • Referral dipendenti
    • Parco veicoli
    Marketing
    • Social marketing
    • E-mail marketing
    • SMS marketing
    • Eventi
    • Marketing automation
    • Sondaggi
    Servizi
    • Progetti
    • Fogli ore
    • Assistenza sul campo
    • Helpdesk
    • Pianificazione
    • Appuntamenti
    Produttività
    • Comunicazioni
    • Approvazioni
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    App di terze parti Odoo Studio Piattaforma cloud Odoo
  • Settori
    Retail
    • Libreria
    • Negozio di abbigliamento
    • Negozio di arredamento
    • Alimentari
    • Ferramenta
    • Negozio di giocattoli
    Cibo e ospitalità
    • Bar e pub
    • Ristorante
    • Fast food
    • Pensione
    • Grossista di bevande
    • Hotel
    Agenzia immobiliare
    • Agenzia immobiliare
    • Studio di architettura
    • Edilizia
    • Gestione immobiliare
    • Impresa di giardinaggio
    • Associazione di proprietari immobiliari
    Consulenza
    • Società di contabilità
    • Partner Odoo
    • Agenzia di marketing
    • Studio legale
    • Selezione del personale
    • Audit e certificazione
    Produzione
    • Tessile
    • Metallo
    • Arredamenti
    • Alimentare
    • Birrificio
    • Ditta di regalistica aziendale
    Benessere e sport
    • Club sportivo
    • Negozio di ottica
    • Centro fitness
    • Centro benessere
    • Farmacia
    • Parrucchiere
    Commercio
    • Tuttofare
    • Hardware e assistenza IT
    • Ditta di installazione di pannelli solari
    • Calzolaio
    • Servizi di pulizia
    • Servizi di climatizzazione
    Altro
    • Organizzazione non profit
    • Ente per la tutela ambientale
    • Agenzia di cartellonistica pubblicitaria
    • Studio fotografico
    • Punto noleggio di biciclette
    • Rivenditore di software
    Carica tutti i settori
  • Community
    Apprendimento
    • Tutorial
    • Documentazione
    • Certificazioni 
    • Formazione
    • Blog
    • Podcast
    Potenzia la tua formazione
    • Programma educativo
    • Scale Up! Business Game
    • Visita Odoo
    Ottieni il software
    • Scarica
    • Versioni a confronto
    • Note di versione
    Collabora
    • Github
    • Forum
    • Eventi
    • Traduzioni
    • Diventa nostro partner
    • Servizi per partner
    • Registra la tua società di contabilità
    Ottieni servizi
    • Trova un partner
    • Trova un contabile
    • Incontra un esperto
    • Servizi di implementazione
    • Testimonianze dei clienti
    • Supporto
    • Aggiornamenti
    GitHub Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Richiedi una demo
  • Prezzi
  • Aiuto

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

  • CRM
  • e-Commerce
  • Contabilità
  • Magazzino
  • PoS
  • Progetti
  • MRP
All apps
È necessario essere registrati per interagire con la community.
Tutti gli articoli Persone Badge
Etichette (Mostra tutto)
odoo accounting v14 pos v15
Sul forum
È necessario essere registrati per interagire con la community.
Tutti gli articoli Persone Badge
Etichette (Mostra tutto)
odoo accounting v14 pos v15
Sul forum
Assistenza

How to Use Selection on Many2one Field ?

Iscriviti

Ricevi una notifica quando c'è un'attività per questo post

La domanda è stata contrassegnata
many2oneselectionrulefuntion
3 Risposte
17117 Visualizzazioni
Avatar
Miftahussalam

As describe in https://doc.odoo.com/6.0/developer/2_5_Objects_Fields_Methods/field_type/#relational-types

I have created a many2one field with custom selection function :

def _get_partner_sup(self, cr, uid, context=None):
    obj = self.pool.get('res.partner')
    ids = obj.search(cr, uid, [('supplier','=',True), ('is_company','=',True)])
    res = obj.read(cr, uid, ids, ['name', 'id','email'], context)
    res = [(r['id'], r['name']) for r in res]    
    return res

_columns = {
    'partner_sup_id': fields.many2one('res.partner', 'Select Supplier 2 ', selection=_get_partner_sup),
}

But it's still like a normal many2one field. What is wrong ?

And I don't want use widget='selection' or domain=[('supplier','=',True), ('is_company','=',True)]

Thanks in Advance

3
Avatar
Abbandona
Avatar
Temur
Risposta migliore

Wrong parameter. The many2one field doesn't have parameter "selection". 

Can you explain please, why you don't want to use:

_columns = {
'partner_sup_id': fields.many2one('res.partner', 'Select Supplier 2 ', domain=[('supplier','=',True), ('is_company','=',True)),
}
you can also set domain in the XML, if you like to have domain filter only in the particular page.

?

if you want to limit displayed columns(fields) to the 'name' field in the selection(you seem to try this in your function), then you've to achieve it with custom view (treeview) for this model.

2
Avatar
Abbandona
Avatar
Axel Mendoza
Risposta migliore

You can use any of the provided Options here but the final adjustment is that you need to set the widget selection for the field in your xml view definition. For example:

#in your .py  

_columns = {

    'partner_sup_id': fields.many2one('res.partner', 'Select Supplier 2 ', domain=[('supplier','=',True), ('is_company','=',True)),

}

 

#in your xml
 

<field name="partner_sup_id" widget="selection">
 

1
Avatar
Abbandona
Avatar
Deepa Venkatesh
Risposta migliore


Well if you don't want to use Domain / Widget...

Then you can try with either of these options

Option 1:

Define a field as Selection, instead of Many2One, along with a selection to achieve your requirement...

Coming to your Requirement:

def _get_partner_sup(self, cr, uid, context=None):

obj = self.pool.get('res.partner')

ids = obj.search(cr, uid, [('supplier','=',True), ('is_company','=',True)])

res = obj.read(cr, uid, ids, ['name', 'id','email'], context)

res = [(r['id'], r['name']) for r in res]

return res

_columns = {

'partner_sup_id': fields.Selection(selection=_get_partner_sup),

}

Option2: If your intention is just not to provide Create/Edit option to the users, then in XML, against that fields just "options={'no_create':True}", by doing this also, you can achieve the same...

0
Avatar
Abbandona
Ti stai godendo la conversazione? Non leggere soltanto, partecipa anche tu!

Crea un account oggi per scoprire funzionalità esclusive ed entrare a far parte della nostra fantastica community!

Registrati
Post correlati Risposte Visualizzazioni Attività
Display values from a pushed dict into a Many2one
many2one selection
Avatar
0
ott 20
3978
fields.many2one ('my.model', selection=_selection_function ) Retourn all 'my.model' records
many2one selection
Avatar
1
ago 17
4516
Why is a selection field used when a many2one field is better?
many2one selection
Avatar
0
mar 15
3725
many to one filed shows object only
many2one selection
Avatar
Avatar
1
mar 15
6952
Filter out results in a Many2One
many2one selection help
Avatar
Avatar
1
set 23
2348
Community
  • Tutorial
  • Documentazione
  • Forum
Open source
  • Scarica
  • Github
  • Runbot
  • Traduzioni
Servizi
  • Hosting Odoo.sh
  • Supporto
  • Aggiornamenti
  • Sviluppi personalizzati
  • Formazione
  • Trova un contabile
  • Trova un partner
  • Diventa nostro partner
Chi siamo
  • La nostra azienda
  • Branding
  • Contattaci
  • Lavora con noi
  • Eventi
  • Podcast
  • Blog
  • Clienti
  • Note legali • Privacy
  • Sicurezza
الْعَرَبيّة 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 è un gestionale di applicazioni aziendali open source pensato per coprire tutte le esigenze della tua azienda: CRM, Vendite, E-commerce, Magazzino, Produzione, Fatturazione elettronica, Project Management e molto altro.

Il punto di forza di Odoo è quello di offrire un ecosistema unico di app facili da usare, intuitive e completamente integrate tra loro.

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