Zum Inhalt springen
Odoo Menü
  • Anmelden
  • Jetzt gratis testen
  • Apps
    Finanzen
    • Buchhaltung
    • Rechnungsstellung
    • Spesenabrechnung
    • Tabellenkalkulation (BI)
    • Dokumente
    • E-Signatur
    Vertrieb
    • CRM
    • Vertrieb
    • Kassensystem – Shop
    • Kassensystem – Restaurant
    • Abonnements
    • Vermietung
    Websites
    • Website-Builder
    • E-Commerce
    • Blog
    • Forum
    • Livechat
    • E-Learning
    Lieferkette
    • Lager
    • Fertigung
    • PLM
    • Einkauf
    • Wartung
    • Qualität
    Personalwesen
    • Mitarbeiter
    • Personalbeschaffung
    • Abwesenheiten
    • Mitarbeiterbeurteilung
    • Personalempfehlungen
    • Fuhrpark
    Marketing
    • Social Marketing
    • E-Mail-Marketing
    • SMS-Marketing
    • Veranstaltungen
    • Marketing-Automatisierung
    • Umfragen
    Dienstleistungen
    • Projekte
    • Zeiterfassung
    • Außendienst
    • Kundendienst
    • Planung
    • Termine
    Produktivität
    • Dialog
    • Genehmigungen
    • IoT
    • VoIP
    • Wissensdatenbank
    • WhatsApp
    Apps von Drittanbietern Odoo Studio Odoo Cloud-Plattform
  • Branchen
    Einzelhandel
    • Buchladen
    • Kleidergeschäft
    • Möbelhaus
    • Lebensmittelgeschäft
    • Baumarkt
    • Spielwarengeschäft
    Essen & Gastgewerbe
    • Bar und Kneipe
    • Restaurant
    • Fast Food
    • Gästehaus
    • Getränkehändler
    • Hotel
    Immobilien
    • Immobilienagentur
    • Architekturbüro
    • Baugewerbe
    • Immobilienverwaltung
    • Gartenarbeit
    • Eigentümervereinigung
    Beratung
    • Buchhaltungsfirma
    • Odoo-Partner
    • Marketingagentur
    • Anwaltskanzlei
    • Talentakquise
    • Prüfung & Zertifizierung
    Fertigung
    • Textil
    • Metall
    • Möbel
    • Speisen
    • Brauerei
    • Firmengeschenke
    Gesundheit & Fitness
    • Sportklub
    • Brillengeschäft
    • Fitnessstudio
    • Therapeut
    • Apotheke
    • Friseursalon
    Handel
    • Handyman
    • IT-Hardware & -Support
    • Solarenergiesysteme
    • Schuster
    • Reinigungsdienstleistungen
    • HLK-Dienstleistungen
    Sonstiges
    • Gemeinnützige Organisation
    • Umweltschutzagentur
    • Plakatwandvermietung
    • Fotostudio
    • Fahrrad-Leasing
    • Software-Händler
    Alle Branchen ansehen
  • Community
    Lernen
    • Tutorials
    • Dokumentation
    • Zertifizierungen
    • Schulung
    • Blog
    • Podcast
    Bildung fördern
    • Bildungsprogramm
    • Scale-Up! Planspiel
    • Odoo besuchen
    Software anfragen
    • Herunterladen
    • Editionen vergleichen
    • Releases
    Zusammenarbeiten
    • Github
    • Forum
    • Veranstaltungen
    • Übersetzungen
    • Partner werden
    • Dienstleistungen für Partner
    • Buchhaltungsfirma registrieren
    Services anfragen
    • Partner finden
    • Buchhalter finden
    • Einen Experten treffen
    • Implementierungsservices
    • Kundenreferenzen
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Eine Demo erhalten
  • Preiskalkulation
  • Hilfe

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

  • CRM
  • e-Commerce
  • Buchhaltung
  • Lager
  • PoS
  • Projekte
  • MRP
All apps
Sie müssen registriert sein, um mit der Community zu interagieren.
Alle Beiträge Personen Abzeichen
Stichwörter (Alle anzeigen)
odoo accounting v14 pos v15
Über dieses Forum
Sie müssen registriert sein, um mit der Community zu interagieren.
Alle Beiträge Personen Abzeichen
Stichwörter (Alle anzeigen)
odoo accounting v14 pos v15
Über dieses Forum
Hilfe

odoo 16 One2many insert value doesnt work

Abonnieren

Erhalten Sie eine Benachrichtigung, wenn es eine Aktivität zu diesem Beitrag gibt

Diese Frage wurde gekennzeichnet
one2manyvalueaddodoo16features
2 Antworten
3524 Ansichten
Avatar
Klaus

hi all,

i created a One2many relation like this

line_ids = fields.One2many('comodel', 'relation_id', string = "something")


in the past e.g. odoo 10 i could add a value from code in the One2many field by doing:

value = [(0,0, {'fieldname': something})]

self.update({

    'line_ids' : value,

})

the updated line_ids shows the value imidiately. 

in Odoo 16 i only see in the form that it has to be saved, nothing else.
I can add a value from the form itself, but not from code

in Odo 16 it doesnt seem possible anymore. did they change the way adding values in One2many fields?

hope you understand what i mean. 

thx for any help

0
Avatar
Verwerfen
Avatar
Sayed Mohammed Aqeel Ebrahim
Beste Antwort

In Odoo 16 and onwards, the mechanism for adding records to One2many fields via code has indeed changed slightly. Instead of directly using `self.update()` to modify One2many fields, you can use the recordset methods like `create` or `write`.


Here's how you can add records to a One2many field in Odoo 16+:


# Assuming self is a record of the main model where line_ids is a One2many field

# Create a recordset for the related model 'comodel'
comodel_obj = self.env['comodel']

# Prepare the values to be added to the One2many field
values_to_add = {
    'fieldname': something,  # Replace 'fieldname' and something with your actual field and value
    # Add other fields and values as needed
}

# Create a new record in 'comodel' and link it to the main record
new_record = comodel_obj.create(values_to_add)

# Add the newly created record to the One2many field 'line_ids'
self.write({
    'line_ids': [(4, new_record.id)]
})



This snippet demonstrates how to create a new record in the related model ('comodel') and then link it to the main record by appending its ID to the One2many field 'line_ids' using the `(4, id)` syntax.


Ensure to replace `'fieldname'` and `something` with your actual field name and value that you want to set in the 'comodel'.


This should enable you to add records to the One2many field programmatically in Odoo 16 and newer versions.

0
Avatar
Verwerfen
Klaus
Autor

wow, thx so much Sayed Mohammed Aqeel Ebrahim for your answer. thats what i thought and found nothing in internet, or possible i searched not enough. :-)

I was looking for a resolution for days now. in the odoo versions lower then 15 it always worked.
thx a lot i will try this tomorrow

Klaus
Autor

hello Sayed Mohammed Aqeel Ebrahim,
i tried it and it works partially.
it works on an already saved object, but not in an unsaved new object.
when i create a one2many line manually in the form ii appears immediately, and when i save the object the relation id is automatically written in the one2many object.

what i try to achieve is creating a new object and add some one2many line from code without the need of saving the object.
when i do it like you have written, the lines in one2many are written in database without the id of the parent object of the one2many. after saving the parent the id of the parent
is not in the one2many lines.

when i add some new one2many lines in an saved parent the parent id is available an can be written in the one2many line.

in odoo versions lower then 15 it was possible to add lines to a one2many field like
lines_ids = [(0,0, {'value': something})]
and the line was visible immediately.
hope it is understanable what i have written, my english is not the best :-)

Avatar
Klaus
Autor Beste Antwort

wow, thx so much for your answer. thats what i thought and found nothing in internet, or possible i searched not enough. :-) 

I was looking for a resolution for days now. in the odoo versions lower then 15 it always worked.

thx a lot i will try this tomorrow 


0
Avatar
Verwerfen
Diskutieren Sie gerne? Treten Sie bei, statt nur zu lesen!

Erstellen Sie heute ein Konto, um exklusive Funktionen zu nutzen und mit unserer tollen Community zu interagieren!

Registrieren
Verknüpfte Beiträge Antworten Ansichten Aktivität
one2many fields, advise/guidance needed... Gelöst
one2many odoo16features
Avatar
Avatar
1
Sept. 23
2528
Filter One2many field in res.partner Gelöst
filter one2many odoo16features
Avatar
Avatar
1
Jan. 24
2539
Many2one not filled until One2many is saved Odoo 16
many2one one2many odoo16features
Avatar
Avatar
1
Dez. 22
3293
Pull and Display a One2Many Field from a relation through a One2Many Field Gelöst
one2many odoostudio odoo16features odoo-online
Avatar
1
Juni 23
4419
how to display one2many field on form view, as list of form views, not tree view.
one2many display formview odoo16features
Avatar
Avatar
Avatar
2
Juni 23
8571
Community
  • Tutorials
  • Dokumentation
  • Forum
Open Source
  • Herunterladen
  • Github
  • Runbot
  • Übersetzungen
Dienstleistungen
  • Odoo.sh-Hosting
  • Support
  • Upgrade
  • Individuelle Entwicklungen
  • Ausbildung
  • Buchhalter finden
  • Partner finden
  • Partner werden
Über uns
  • Unsere Firma
  • Markenwerte
  • Kontakt
  • Karriere
  • Veranstaltungen
  • Podcast
  • Blog
  • Kunden
  • Rechtliches • Datenschutz
  • Sicherheit
الْعَرَبيّة 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 ist eine Suite von Open-Source-Betriebsanwendungen, die alle Bedürfnisse Ihres Unternehmens abdecken: CRM, E-Commerce, Buchhaltung, Lager, Kassensystem, Projektmanagement etc.

Das einzigartige Wertversprechen von Odoo ist, dass es gleichzeitig sehr einfach zu bedienen und voll integriert ist.

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