İç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

Displaying data from another model in a form

Abone Ol

Get notified when there's activity on this post

Bu soru işaretlendi
2 Cevaplar
6951 Görünümler
Avatar
Linton Rooms

I dont know what is the most recommended way to display data from a model (A) in the form of a model (B) [Odoo 11].


So far I've used One2many relations, but in this case I cant (or I dont know how to do it).

I have three models:

class School(models.Model):
_name = 'abby.school'
...

class Agreement(models.Model):
_name = 'abby.agreement'
...
agreement_school = fields.Many2one(comodel_name='abby.school', string='School')
...

class Student(models.Model):
_name = 'abby.student'
...
school = fields.Many2one(comodel_name='abby.school', string='School')
...


Graphically: Agreement > School < Student


I want to display a list of Students in the Agreements form.

 
Could I use an One2many relation? Or a SELECT in any place? (I'm a beginner in Odoo)

Thank you in advance!!

0
Avatar
Vazgeç
Linton Rooms
Üretici

--- I want to display all the students (could be one or eleven or zero) who belongs to a school with an agreement ---

Avatar
Sudhir Arya (ERP Harbor Consulting Services)
En İyi Yanıt

If each student will always have one agreement, then you can use One2many field

class Student(models.Model):
_name = 'abby.student'

agreement_id = fields.Many2one('abby.aggrement', 'Agreement')

class Agreement(models.Model):
_name = 'abby.agreement'

student_ids = fields.One2Many('abby.student', 'agreement_id', string="Students")
If the student can have multiple agreements, then you should use the Many2many field:

class Agreement(models.Model):
_name = 'abby.agreement'

student_ids = fields.Many2many('abby.student', string="Students")

Update:

Since you want to display all the students belonging to the school, you should use the auto-compute Many2many field:


class Agreement(...):

student_ids = fields.Many2many('abby.student', compute='_compute_students')

@api.depends('agreement_school')
def _compute_students(self):
        stud_obj = self.env['abby.student']
for agreement in self:
# Search students belongs to the school of the agreement
stud_ids = stud_obj.search([('school', '=', agreement.agreement_school.id)]).ids
agreement.student_ids = [(6, 0, stud_ids)]




1
Avatar
Vazgeç
Linton Rooms
Üretici

Thanks for answering, Sudhir.

I think that solution does not work because there isnt direct relationship between Student and Agreemet. They both point to School:

Agreement > School < Student

Sudhir Arya (ERP Harbor Consulting Services)

Still, with the m2m field, you can select your students in the agreement. Do you want to auto-select all the students belongs to the school of the agreement?

Linton Rooms
Üretici

Thanks, Sudhir.

### Still, with the m2m field, you can select your students in the agreement.
### Do you want to auto-select all the students belongs to the school of the agreement?

Yes, I want to display (only display, not add or delete) the students who belong to a school with an agreement.

Using this:
student_ids = fields.Many2many('abby.student', string="Students") (In Agreement)

How can I specify the model School?

Thanks a lot

Sudhir Arya (ERP Harbor Consulting Services)

Please check my updated answer.

Linton Rooms
Üretici

Thank you a lot, Sudhir, for beeing so patient.
It's working... almost!
No errors, but list is empty.
So, I've write these "prints":
class Agreement(...):

student_ids = fields.Many2many(compute='_compute_students')

@api.depends('agreement_school')
def _compute_students(self):

stud_obj = self.env['abby.student']
print ("FooAAA ---")
for agreement in self:
print ("FooBBB agreement:")
print (agreement)
# Search students belongs to the school of the agreement
stud_ids = stud_obj.search([('school', '=', agreement.agreement_school.id)])
print ("FooCCC stud_ids")
print (stud_ids)
print ("FooEEE stud_ids[0]")
print (stud_ids[0])
agreement.student_ids = [(6, 0, stud_ids)]

When I go to an agreement, I get:
FooAAA ---
FooBBB agreement:
abby.agreement(10,)
FooCCC stud_ids
abby.student(1369, 905)
FooEEE stud_ids[0]
abby.student(1369,)

The list in trace "FooCCC" is OK. These are the correct ids to display... but they are not loaded in the list... any idea?

Thanks again!!

Sudhir Arya (ERP Harbor Consulting Services)

Please update bellow code:
agreement.student_ids = [(6, 0, stud_ids)]

Replace (stud_ids.ids):
agreement.student_ids = [(6, 0, stud_ids.ids)]

Linton Rooms
Üretici

Hi again, and thanks for keep helping!!

Adding "ids", I get this error:
psycopg2.ProgrammingError: relation "_unknown" does not exist
LINE 1: SELECT "_unknown"."id" as "id" FROM "_unknown" WHERE "_unkno...

Looking for that, I have found two posible causes/solutions. The first one recommends to restart both odoo and postgresql. I did it, but the error continues.
In the second comment, they talk about define relationships between models, but in my case, both models are defined in the same module.

Do you know what the problem could be?
Thanks in advance again!

Sudhir Arya (ERP Harbor Consulting Services)

Sorry, I missed to pass on the object name in the m2m field:

student_ids = fields.Many2many('abby.student', compute='_compute_students')

Linton Rooms
Üretici

It is working.
Sudhir, thank you very very much for your time and sharing your knowledge.

Avatar
Cybrosys Techno Solutions Pvt.Ltd
En İyi Yanıt

Hi,

To get the data from modelA to modelB we can use Many2one relation here.For example you need to get the list of students list in agreement form,

ie,

class Agreement(models.Model):
_name = 'abby.agreement'
student_list_id = fields.Many2one('abby.student', string="Student list")

Regards

0
Avatar
Vazgeç
Linton Rooms
Üretici

Thanks for your answer.

But, if I use a Many2one, I will have a list for choose a student...

I want to display all the students (could be one or eleven or zero) who belongs to a school with an agreement.

Regards

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