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

OnChange event of o2m and m2m

Iscriviti

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

La domanda è stata contrassegnata
o2monchangem2m
3 Risposte
28734 Visualizzazioni
Avatar
Antonio Buric

Hi all,

is there any way to find out what record is being added/removed in an onchange event set on a one2many or many2many field?

The problem I ran into is the following - I have a many2many field and a one2many field on the form. Adding a record to m2m field should add one or more records to the o2m field. Using the tuple notation in an onchange event for inserting/deleting records from o2m is insufficient here, I covered most of the cases in the onchange method, but I can't get it right when in edit of an existing master record with saved m2m and o2m entries (I have to know which ID is being added or removed in the onchange event, is anything like that remotely possible - some workaround perhaps?)

5
Avatar
Abbandona
Avatar
Vasiliy Birukov
Risposta migliore

Send x2many as parametr to onchange metod. It will have list of records as following: [[Mode, Option, {'field_name':field_value_record1, ...}], [Mode, Option, {'field_name':field_value_record2, ...}]]

Combination of Mode, Options and Fields Values define state of x2many records.

(0, 0, { values }) link to a new record that needs to be created with the given values dictionary

(1, ID, { values }) update the linked record with id = ID (write values on it)

(2, ID) remove and delete the linked record with id = ID (calls unlink on ID, that will delete the object completely, and the link to it as well)

(3, ID)
cut the link to the linked record with id = ID (delete the relationship between the two objects but does not delete the target object itself)

(4, ID) link to existing record with id = ID (adds a relationship)

(5)
unlink all (like using (3,ID) for all linked records)

(6, 0, [IDs])
replace the list of linked IDs (like using (5) then (4,ID) for each ID in the list of IDs)

For example: [4,5,False] - define existing records in DB with id=5

[0,0,{'name':'new record'} - difine new record with field "name"="new record", that will be created in DB, when holder of x2many will be saved to DB.

16
Avatar
Abbandona
Avatar
Adil Akbar
Risposta migliore

Hi, 

You can watch following video for this:

https://youtu.be/ezH3ql5Dmx4

Thanks

0
Avatar
Abbandona
Avatar
Antonio Buric
Autore Risposta migliore

thanks for the response. however, I must have not been clear enough with my question.

The problem is that I always get something like [4,5,False] as an input to onchange method and it's not possible to find out which ID is being inserted or deleted. for example, we have 3 records in the many2many field with IDs 7,8,9. If we remove record with ID = 9, in onchange method we will get this [4,[7,8],False]. If instead we add a record with ID = 10, we would get [4,[7,8,9,10],False]. From that, there is no way to determine which ID the user added or deleted in an event that trigger the onchange method.

0
Avatar
Abbandona
Vasiliy Birukov

If you have only exist records it will be: [[4,7,False],[4,8,False],[4,9,False]]. If you remove in form ID=9 it will be: [[4,7,False],[4,8,False],[2,9,False]]. If you add in form new record it will be: [[4,7,False],[4,8,False],[2,9,False],[0,0,{values}]]

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à
How to add set domain fields O2M relate to a self define M2M model to avoid duplicate
domain o2m m2m
Avatar
Avatar
1
dic 17
7026
How to onchange m2o and o2m?
o2m onchange m2o
Avatar
0
mar 15
5526
[v12] res_partner multiple Hierarchical relationships
o2m m2m m2o relationships
Avatar
0
feb 19
4743
trying to auto correct a wrong users value
onchange
Avatar
Avatar
1
ott 23
2771
"Wrong value for %s: %r" % (self, value) Risolto
onchange
Avatar
Avatar
2
ott 23
2987
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