İçereği Atla
Odoo Menü
  • Portal
  • Ücretsiz deneyin
  • Uygulamalar
    Finans
    • Muhasebe
    • Faturalama
    • Masraf Yönetimi
    • Elektronik Çizelge (BI)
    • Belgeler
    • İmza
    Satış
    • Müşteri İlişkileri Yönetimi (CRM)
    • Satış
    • Satış Noktası Mağaza
    • Satış Noktası Restoran
    • Abonelikler
    • Kiralama
    Web Sitesi
    • Web Sitesi Oluşturucu
    • eTicaret
    • Blog
    • Forum
    • Canlı Sohbet
    • eÖğrenme
    Tedarik Zinciri
    • Envanter
    • Üretim
    • Ürün Yaşam Döngüsü Yönetimi
    • Satın Alma
    • Bakım
    • Kalite
    İnsan Kaynakları
    • Çalışanlar
    • İşe Alım
    • İzin
    • Değerlendirme
    • Referans
    • Filo Yönetimi
    Pazarlama
    • Sosyal Medyada Pazarlama
    • E-posta ile Pazarlama
    • SMS ile Pazarlama
    • Etkinlikler
    • Pazarlama Otomasyonu
    • Anket
    Hizmetler
    • Proje Yönetimi
    • Çalışma Çizelgeleri
    • Saha Hizmeti
    • Yardım Masası
    • Planlama
    • Randevular
    Verimlilik
    • Sohbet
    • Onay
    • Nesnelerin İnterneti
    • VoIP
    • Bilgi Bankası
    • WhatsApp
    Üçüncü taraf uygulamalar Odoo Stüdyo Odoo Bulut Platformu
  • Sektörler
    Perakende satış
    • Kitapçı
    • Giyim Mağazası
    • Mobilya Mağazası
    • Gıda Marketi
    • Hırdavat Dükkanı
    • Oyuncak Dükkanı
    Gıda ve Konaklama
    • Bar ve Pub
    • Restoran
    • Fast Food Restoranı
    • Konuk Evi
    • İçecek Distribütörü
    • Otel
    Gayrimenkul
    • Emlak Acentesi
    • Mimarlık Firması
    • İnşaat
    • Emlak Yönetimi
    • Bahçe Tasarımı
    • Mülk Sahipleri Derneği
    Uzmanlık
    • Muhasebe Firması
    • Odoo Partner
    • Pazarlama Ajansı
    • Hukuk Firması
    • Yetenek Kazanımı
    • Denetim ve Belgelendirme
    Üretim
    • Tekstil
    • Metal
    • Mobilyalar
    • Gıda
    • Bira fabrikası
    • Kurumsal Hediye
    Sağlık ve Spor
    • Spor Kulübü
    • Optik Mağazası
    • Fitness Merkezi
    • Sağlıklı Yaşam Merkezi
    • Eczane
    • Kuaför Salonu
    Ticaret
    • Tamirci
    • BT Donanım & Destek
    • Güneş Enerjisi Sistemleri
    • Ayakkabı İmalatçısı
    • Temizlik Hizmetleri
    • HVAC Hizmetleri
    Diğerleri
    • Kar Amacı Gütmeyen Kuruluş
    • Çevre Ajansı
    • Reklam Panosu Kiralama
    • Fotoğrafçılık
    • Bisiklet Kiralama
    • Yazılım Bayisi
    Tüm Sektörlere Göz Atın
  • Topluluk
    Öğrenim
    • Eğitim Araçları
    • Dokümantasyon
    • Sertifikasyonlar
    • Eğitim Etkinlikleri
    • Blog
    • Podcast
    Eğitim ve Gelişim
    • Eğitim Programı
    • Scale Up! İşletme Oyunu
    • Odoo'yu Ziyaret Edin
    Yazılım
    • İndirin
    • Sürümleri Kıyaslayın
    • Sürümler
    İş Birliği
    • Github
    • Forum
    • Etkinlikler
    • Çeviriler
    • Partner Olun
    • Partnerler için Hizmetler
    • Muhasebe Firmanızı Kaydettirin
    Hizmetler
    • Partner Bulun
    • Muhasebeci Bulun
    • Bir danışmanla görüşün
    • Kurulum Hizmetleri
    • Müşteri Referansları
    • Destek
    • Sürüm Yükseltme
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Demo randevusu alın
  • Fiyatlandırma
  • Yardım

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

  • Müşteri İlişkileri Yönetimi
  • e-Commerce
  • Muhasebe
  • Envanter
  • PoS
  • Proje Yönetimi
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiketler (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiketler (View all)
odoo accounting v14 pos v15
About this forum
Yardım

Creating model data with many2many field doesn't work

Abone Ol

Get notified when there's activity on this post

Bu soru işaretlendi
ormmany2manycontroller
1 Cevapla
19306 Görünümler
Avatar
Tobias Wetzel

Hi,

I am trying to create a model entry in my controller, which has a many2many field. The creating works but the values I added to the many2many field are not there. What is wrong?

Model definition:

class Paper(models.Model):
_name = 'paper_submission.paper'

title = fields.Char(string='Title', required='True')
author_ids = fields.Many2many('paper_submission.author', string='Authors', relation="paper_submission_paper_author_relation")

references model:

class Author(models.Model):
_name = 'paper_submission.author'

first_name = fields.Char()
last_name = fields.Char()

Code for creating the model entry:

 orm_paper = registry.get('paper_submission.paper')

paper_info = {"title: title, author_ids": author_ids}
paper_id = orm_paper.create(cr, SUPERUSER_ID, paper_info, context=context)

where author_ids is a list of ids, like [1,2]


0
Avatar
Vazgeç
Tobias Wetzel
Üretici

SOLUTION: orm_paper.create({'title': title, 'author_ids': [(6, 0, author_ids)]}) using: (6, _, ids) triplet from the Odoo docs: "Values marked as _ in the list above are ignored and can be anything, generally 0 or False."

Avatar
Habib
En İyi Yanıt

You need to use tuples to write to many2many records:

In your case if the authors don't exist, and you want to create them, you would use:

orm_paper.create({'title': title, 'author_ids': [(0, 0, {'first_name': first_name, 'last_name': last_name})]

if the author does exist you would use:

orm_paper.create({'title': title, 'author_ids': [(4, author_id)]}) 


The following can be found at /openerp/models.py, and describes how to use the appropriate "triplet" 

:class:`~openerp.fields.One2many` and
:class:`~openerp.fields.Many2many` use a special "commands" format to
manipulate the set of records stored in/associated with the field.

This format is a list of triplets executed sequentially, where each triplet is a command to execute on the set of records. Not all commands apply in all situations. Possible commands are: ``(0, _, values)`` adds a new record created from the provided ``value`` dict. ``(1, id, values)`` updates an existing record of id ``id`` with the values in ``values``. Can not be used in :meth:`~.create`. ``(2, id, _)`` removes the record of id ``id`` from the set, then deletes it (from the database). Can not be used in :meth:`~.create`. ``(3, id, _)`` removes the record of id ``id`` from the set, but does not delete it. Can not be used on :class:`~openerp.fields.One2many`. Can not be used in :meth:`~.create`. ``(4, id, _)`` adds an existing record of id ``id`` to the set. Can not be used on :class:`~openerp.fields.One2many`. ``(5, _, _)`` removes all records from the set, equivalent to using the command ``3`` on every record explicitly. Can not be used on :class:`~openerp.fields.One2many`. Can not be used in :meth:`~.create`. ``(6, _, ids)`` replaces all existing records in the set by the ``ids`` list, equivalent to using the command ``5`` followed by a command ``4`` for each ``id`` in ``ids``. Can not be used on :class:`~openerp.fields.One2many`.
3
Avatar
Vazgeç
Enjoying the discussion? Don't just read, join in!

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

Üye Ol
İlgili Gönderiler Cevaplar Görünümler Aktivite
Get model data in a controller Çözüldü
orm model controller
Avatar
Avatar
Avatar
Avatar
4
Eki 21
38521
How to find out the table name for a many2many relation (Where is the many2many table name stored?) Çözüldü
orm xmlrpc many2many
Avatar
Avatar
Avatar
Avatar
Avatar
4
Eki 21
25194
Many2Many relationship but sorted with 'weighted' values
many2one orm many2many one2one
Avatar
0
Kas 18
6766
ODOO V16 Associate Parts to a Finished Good
many2many
Avatar
Avatar
1
Şub 24
2745
many2many write() - replaces all existing records in the set by the ids Çözüldü
orm write many2many website odoo12
Avatar
Avatar
Avatar
Avatar
3
Eyl 23
61770
Topluluk
  • Eğitim Araçları
  • Dokümantasyon
  • Forum
Açık Kaynak
  • İndirin
  • Github
  • Runbot
  • Çeviriler
Hizmetler
  • Odoo.sh Hosting
  • Destek
  • Sürüm Yükseltme
  • Özel Geliştirmeler
  • Eğitim
  • Muhasebeci Bulun
  • Partner Bulun
  • Partner Olun
Hakkında
  • Şirketimiz
  • Pazarlama Gereçleri
  • İletişim
  • Kariyer
  • Etkinlikler
  • Podcast
  • Blog
  • Müşteriler
  • Hukuki • Gizlilik
  • Güvenlik
الْعَرَبيّة 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, müşteri ilişkileri yönetimi, eTicaret, muhasebe, envanter, satış noktası, proje yönetimi gibi şirketinizin tüm ihtiyaçlarını karşılayan bir açık kaynak işletme uygulamaları paketidir.

Odoo’nun eşsiz değer önermesi, aynı anda hem kullanımının çok kolay olup hem de tamamen entegre olmasıdır.

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