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

OnChange event of o2m and m2m

Subscriure's

Get notified when there's activity on this post

This question has been flagged
o2monchangem2m
3 Respostes
28733 Vistes
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
Descartar
Avatar
Vasiliy Birukov
Best Answer

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
Descartar
Avatar
Adil Akbar
Best Answer

Hi, 

You can watch following video for this:

https://youtu.be/ezH3ql5Dmx4

Thanks

0
Avatar
Descartar
Avatar
Antonio Buric
Autor Best Answer

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
Descartar
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}]]

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
How to add set domain fields O2M relate to a self define M2M model to avoid duplicate
domain o2m m2m
Avatar
Avatar
1
de des. 17
7024
How to onchange m2o and o2m?
o2m onchange m2o
Avatar
0
de març 15
5525
[v12] res_partner multiple Hierarchical relationships
o2m m2m m2o relationships
Avatar
0
de febr. 19
4743
trying to auto correct a wrong users value
onchange
Avatar
Avatar
1
d’oct. 23
2771
"Wrong value for %s: %r" % (self, value) Solved
onchange
Avatar
Avatar
2
d’oct. 23
2985
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