Skip ke Konten
Odoo Menu
  • Login
  • Uji coba gratis
  • Aplikasi
    Keuangan
    • Akuntansi
    • Faktur
    • Pengeluaran
    • Spreadsheet (BI)
    • Dokumen
    • Tanda Tangan
    Sales
    • CRM
    • Sales
    • POS Toko
    • POS Restoran
    • Langganan
    • Rental
    Website
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Rantai Pasokan
    • Inventaris
    • Manufaktur
    • PLM
    • Purchase
    • Maintenance
    • Kualitas
    Sumber Daya Manusia
    • Karyawan
    • Rekrutmen
    • Cuti
    • Appraisal
    • Referensi
    • Armada
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Acara
    • Otomatisasi Marketing
    • Survei
    Layanan
    • Project
    • Timesheet
    • Layanan Lapangan
    • Meja Bantuan
    • Planning
    • Appointment
    Produktivitas
    • Diskusi
    • Approval
    • IoT
    • VoIP
    • Pengetahuan
    • WhatsApp
    Aplikasi pihak ketiga Odoo Studio Platform Odoo Cloud
  • Industri-Industri
    Retail
    • Toko Buku
    • Toko Baju
    • Toko Furnitur
    • Toko Kelontong
    • Toko Hardware
    • Toko Mainan
    Makanan & Hospitality
    • Bar dan Pub
    • Restoran
    • Fast Food
    • Rumah Tamu
    • Distributor Minuman
    • Hotel
    Real Estate
    • Agensi Real Estate
    • Firma Arsitektur
    • Konstruksi
    • Estate Management
    • Perkebunan
    • Asosiasi Pemilik Properti
    Konsultansi
    • Firma Akuntansi
    • Mitra Odoo
    • Agensi Marketing
    • Firma huku
    • Talent Acquisition
    • Audit & Sertifikasi
    Manufaktur
    • Tekstil
    • Logam
    • Perabotan
    • Makanan
    • Brewery
    • Corporate Gift
    Kesehatan & Fitness
    • Sports Club
    • Toko Kacamata
    • Fitness Center
    • Wellness Practitioners
    • Farmasi
    • Salon Rambut
    Perdagangan
    • Handyman
    • IT Hardware & Support
    • Sistem-Sistem Energi Surya
    • Pembuat Sepatu
    • Cleaning Service
    • Layanan HVAC
    Lainnya
    • Organisasi Nirlaba
    • Agen Lingkungan
    • Rental Billboard
    • Fotografi
    • Penyewaan Sepeda
    • Reseller Software
    Browse semua Industri
  • Komunitas
    Belajar
    • Tutorial-tutorial
    • Dokumentasi
    • Sertifikasi
    • Pelatihan
    • Blog
    • Podcast
    Empower Education
    • Program Edukasi
    • Game Bisnis 'Scale Up!'
    • Kunjungi Odoo
    Dapatkan Softwarenya
    • Download
    • Bandingkan Edisi
    • Daftar Rilis
    Kolaborasi
    • Github
    • Forum
    • Acara
    • Terjemahan
    • Menjadi Partner
    • Layanan untuk Partner
    • Daftarkan perusahaan Akuntansi Anda.
    Dapatkan Layanan
    • Temukan Mitra
    • Temukan Akuntan
    • Temui penasihat
    • Layanan Implementasi
    • Referensi Pelanggan
    • Bantuan
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Dapatkan demo
  • Harga
  • Bantuan

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

  • CRM
  • e-Commerce
  • Akuntansi
  • Inventaris
  • PoS
  • Project
  • MRP
All apps
Anda harus terdaftar untuk dapat berinteraksi di komunitas.
Semua Post Orang Lencana-Lencana
Label (Lihat semua)
odoo accounting v14 pos v15
Mengenai forum ini
Anda harus terdaftar untuk dapat berinteraksi di komunitas.
Semua Post Orang Lencana-Lencana
Label (Lihat semua)
odoo accounting v14 pos v15
Mengenai forum ini
Help

Defining a count function based on a Many2many field

Langganan

Dapatkan notifikasi saat terdapat aktivitas pada post ini

Pertanyaan ini telah diberikan tanda
pythonmany2manyodootables
2 Replies
7212 Tampilan
Avatar
Raib

Hi, I've created a custom module in which I added these three models named "dipendenti.py" (just consider it such as "students" to simplify things), "corso.py" and "edizione.py" (in Italian, "corso" is a word used to refer to a course in general, such as it would be literature, and "edizione" is a word used to refer to a specific course that has been holded, such as it would be literature in XX-HighSchool in 9th grade in the 2020-21 academic year). I'll write down the important code lines to contextualize:


DIPENDENTE.PY
class Dipendente(models.Model):
_name="piani_formazione.dipendente"
[...]codice_fiscale = fields.Char(string="Codice Fiscale", size=16, required=True)
dipendente_edizioni = fields.Many2many("piani_formazione.edizione","tabella_dipendenti_edizioni","codice_fiscale","numero",string="Edizioni frequentate")
CORSO.PY
class Corso(models.Model):
_name ="piani_formazione.corso"
[...]codice = fields.Char(string="Codice", required=True)
edizioni_corso = fields.One2many("piani_formazione.edizione","edizione_corso", string="Edizioni erogate")
EDIZIONE.PY
class EdizioneCorso(models.Model):
_name="piani_formazione.edizione"
[...]numero=fields.Text(string="Numero",required=True)
edizione_corso = fields.Many2one("piani_formazione.corso",string="Edizione del corso",required=True)
edizione_dipendenti = fields.Many2many("piani_formazione.dipendente","tabella_dipendenti_edizioni","numero","codice_fiscale",string="Frequentanti")

Now I would like to add to the "edizione.py" a computed field, that for each record ("for each edizione") registers how many dipendenti ("students") have attended that edizione ("specific course"). But I don't know how to count such quantity from tables, since the Many2many relation generates tables  instead of lists. 

0
Avatar
Buang
Raib
Penulis

@samuel I tried, but, since the relation creates a table and not a list, "len()" seems to not work on it

Avatar
Raib
Penulis Jawaban Terbai

@samuel I found out that len() was not the problem, I just indented wrong the method! Thank you :)

0
Avatar
Buang
Samuel RAMAROSELY

You're welcome

Avatar
Samuel RAMAROSELY
Jawaban Terbai

Hello Raib,

Try this:

Let's assume that you created your computed field like this:

dipendenti_number = fields.Integer(compute='_compute_dipendenti_number')

Now in your compute function

@api.depends('edizione_dipendenti')
def _compute_dipendenti_number(self):
    for rec in self:
        rec.dipendenti_number = len(rec.edizione_dipendenti)



-1
Avatar
Buang
Menikmati diskusi? Jangan hanya membaca, ikuti!

Buat akun sekarang untuk menikmati fitur eksklufi dan agar terlibat dengan komunitas kami!

Daftar
Post Terkait Replies Tampilan Aktivitas
Save filtered tree view to load as it is at another time Diselesaikan
python odoo
Avatar
Avatar
Avatar
2
Agu 25
3402
Private functions and public functions in odoo python Diselesaikan
python odoo
Avatar
Avatar
Avatar
Avatar
3
Feb 25
4810
odoo ghost module
python odoo
Avatar
0
Mei 24
46
Call python method from inherit_id attribute
python odoo
Avatar
Avatar
1
Apr 24
4189
how to get last inserted value from One2many or many2many field Diselesaikan
python one2many many2many odoo v15
Avatar
Avatar
Avatar
2
Des 23
2820
Komunitas
  • Tutorial-tutorial
  • Dokumentasi
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Terjemahan
Layanan
  • Odoo.sh Hosting
  • Bantuan
  • Peningkatan
  • Custom Development
  • Pendidikan
  • Temukan Akuntan
  • Temukan Mitra
  • Menjadi Partner
Tentang Kami
  • Perusahaan kami
  • Aset Merek
  • Hubungi kami
  • Tugas
  • Acara
  • Podcast
  • Blog
  • Pelanggan
  • Hukum • Privasi
  • Keamanan
الْعَرَبيّة 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 adalah rangkaian aplikasi bisnis open source yang mencakup semua kebutuhan perusahaan Anda: CRM, eCommerce, akuntansi, inventaris, point of sale, manajemen project, dan seterusnya.

Mudah digunakan dan terintegrasi penuh pada saat yang sama adalah value proposition unik Odoo.

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