Skip to Content
Odoo Menu
  • Prisijungti
  • Išbandykite nemokamai
  • Programėlės
    Finansai
    • Apskaita
    • Pateikimas apmokėjimui
    • Sąnaudos
    • Skaičiuoklė (BI)
    • Dokumentai
    • Pasirašymas
    Pardavimai
    • CRM
    • Pardavimai
    • Kasų sistema - Parduotuvė
    • Kasų sistema - Restoranas
    • Prenumeratos
    • Nuoma
    Svetainės
    • Svetainių kūrėjimo įrankis
    • El. Prekyba
    • Internetinis Tinklaraštis
    • Forumas
    • Tiesioginis pokalbis
    • eMokymasis
    Tiekimo grandinė
    • Atsarga
    • Gamyba
    • PLM
    • Įsigijimai
    • Priežiūra
    • Kokybė
    Žmogaus ištekliai
    • Darbuotojai
    • Įdarbinimas
    • Atostogos
    • Įvertinimai
    • Rekomendacijos
    • Transporto priemonės
    Rinkodara
    • Socialinė rinkodara
    • Rinkodara el. paštu
    • SMS rinkodara
    • Renginiai
    • Rinkodaros automatizavimas
    • Apklausos
    Paslaugos
    • Projektas
    • Darbo laiko žiniaraščiai
    • Priežiūros tarnyba
    • Pagalbos tarnyba
    • Planavimas
    • Rezervacijos
    Produktyvumas
    • Diskucija
    • Patvirtinimai
    • IoT
    • VoIP
    • Žinių biblioteka
    • WhatsApp
    Trečiųjų šalių programos Odoo Studija Odoo debesijos platforma
  • Pramonės šakos
    Mažmeninė prekyba
    • Knygynas
    • Drabužių parduotuvė
    • Baldų parduotuvė
    • Maisto prekių parduotuvė
    • Techninės įrangos parduotuvė
    • Žaislų parduotuvė
    Food & Hospitality
    • Barai ir pub'ai
    • Restoranas
    • Greitasis maistas
    • Guest House
    • Gėrimų platintojas
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architektūros įmonė
    • Konstrukcija
    • Estate Managament
    • Sodininkauti
    • Turto savininkų asociacija
    Consulting
    • Accounting Firm
    • Odoo Partneris
    • Marketing Agency
    • Teisinė firma
    • Talentų paieška
    • Auditai & sertifikavimas
    Gamyba
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Įmonių dovanos
    Sveikata & Fitnesas
    • Sporto klubas
    • Akinių parduotuvė
    • Fitneso Centras
    • Sveikatos praktikai
    • Vaistinė
    • Kirpėjas
    Trades
    • Handyman
    • IT įranga ir palaikymas
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Aplinkos agentūra
    • Reklaminių stendų nuoma
    • Fotografavimas
    • Dviračių nuoma
    • Programinės įrangos perpardavėjas
    Browse all Industries
  • Bendrija
    Mokykitės
    • Mokomosios medžiagos
    • Dokumentacija
    • Sertifikatai
    • Mokymai
    • Internetinis Tinklaraštis
    • Tinklalaidės
    Skatinkite švietinimą
    • Švietimo programa
    • Scale Up! Verslo žaidimas
    • Aplankykite Odoo
    Gaukite programinę įrangą
    • Atsisiųsti
    • Palyginkite versijas
    • Leidimai
    Bendradarbiauti
    • Github
    • Forumas
    • Renginiai
    • Vertimai
    • Tapkite partneriu
    • Services for Partners
    • Registruokite jūsų apskaitos įmonę
    Gaukite paslaugas
    • Susiraskite partnerį
    • Susirask buhalterį
    • Susitikti su konsultantu
    • Diegimo paslaugos
    • Klientų rekomendavimas
    • Palaikymas
    • Atnaujinimai
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Gaukite demo
  • Kainodara
  • Pagalba

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

  • CRM
  • e-Commerce
  • Apskaita
  • Atsarga
  • PoS
  • Projektas
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Žymos (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Žymos (View all)
odoo accounting v14 pos v15
About this forum
Pagalba

odoo 16 One2many insert value doesnt work

Prenumeruoti

Get notified when there's activity on this post

This question has been flagged
one2manyvalueaddodoo16features
2 Replies
3547 Rodiniai
Portretas
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
Portretas
Atmesti
Portretas
Sayed Mohammed Aqeel Ebrahim
Best Answer

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
Portretas
Atmesti
Klaus
Autorius

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
Autorius

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 :-)

Portretas
Klaus
Autorius Best Answer

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
Portretas
Atmesti
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Registracija
Related Posts Replies Rodiniai Veikla
one2many fields, advise/guidance needed... Solved
one2many odoo16features
Portretas
Portretas
1
rugs. 23
2557
Filter One2many field in res.partner Solved
filter one2many odoo16features
Portretas
Portretas
1
saus. 24
2562
Many2one not filled until One2many is saved Odoo 16
many2one one2many odoo16features
Portretas
Portretas
1
gruod. 22
3301
Pull and Display a One2Many Field from a relation through a One2Many Field Solved
one2many odoostudio odoo16features odoo-online
Portretas
1
birž. 23
4444
how to display one2many field on form view, as list of form views, not tree view.
one2many display formview odoo16features
Portretas
Portretas
Portretas
2
birž. 23
8606
Bendrija
  • Mokomosios medžiagos
  • Dokumentacija
  • Forumas
Atvirasis kodas
  • Atsisiųsti
  • Github
  • Runbot
  • Vertimai
Paslaugos
  • Odoo.sh talpinimas
  • Palaikymas
  • Atnaujinti
  • Pritaikytas programavimo kūrimas
  • Švietimas
  • Susirask buhalterį
  • Susiraskite partnerį
  • Tapkite partneriu
Apie mus
  • Mūsų įmonė
  • Prekės ženklo turtas
  • Susisiekite su mumis
  • Darbo pasiūlymai
  • Renginiai
  • Tinklalaidės
  • Internetinis Tinklaraštis
  • Klientai
  • Teisinis • Privatumas
  • Saugumas
الْعَرَبيّة 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 yra atvirojo kodo verslo programų rinkinys, kuris apima visas įmonės poreikius: CRM, El. Prekybą, Apskaitą, Atsargų, Kasų sistemą, Projektų valdymą ir kt.

Unikali Odoo vertės pasiūla – būti tuo pačiu metu labai lengvai naudojama ir visiškai integruota sistema.

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