Přejít na obsah
Odoo Menu
  • Přihlásit se
  • Vyzkoušejte zdarma
  • Aplikace
    Finance
    • Účetnictví
    • Fakturace
    • Výdaje
    • Spreadsheet (BI)
    • Dokumenty
    • Podpisy
    Prodej
    • CRM
    • Prodej
    • POS Obchod
    • POS Restaurace
    • Předplatné
    • Pronájem
    Webové stránky
    • Webové stránky
    • E-shop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Dodavatelský řetězec
    • Sklad
    • Výroba
    • PLM
    • Nákup
    • Údržba
    • Kvalita
    Lidské zdroje
    • Zaměstnanci
    • Nábor
    • Volno
    • Hodnocení zaměstnanců
    • Doporučení
    • Vozový park
    Marketing
    • Marketing sociálních sítí
    • Emailový marketing
    • SMS Marketing
    • Události
    • Marketingová automatizace
    • Dotazníky
    Služby
    • Projekt
    • Časové výkazy
    • Práce v terénu
    • Helpdesk
    • Plánování
    • Schůzky
    Produktivita
    • Diskuze
    • Schvalování
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Aplikace třetích stran Odoo Studio Odoo cloudová platforma
  • Branže
    Maloobchod
    • Knihkupectví
    • Obchod s oblečením
    • Obchod s nábytkem
    • Potraviny
    • Obchod s hardwarem
    • Hračkářství
    Food & Hospitality
    • Bar a Pub
    • Restaurace
    • Fast Food
    • Guest House
    • Distributor nápojů
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architektonická firma
    • Stavba
    • Správa nemovitostí
    • Zahradnictví
    • Asociace vlastníků nemovitosti
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketingová agentura
    • Právník
    • Akvizice talentů
    • Audit a certifikace
    Výroba
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Korporátní dárky
    Zdraví a fitness
    • Sportovní klub
    • Prodejna brýli
    • Fitness Centrum
    • Wellness praktikové
    • Lékárna
    • Kadeřnictví
    Trades
    • Údržbář
    • IT hardware a podpora
    • Solar Energy Systems
    • Výrobce obuvi
    • Úklidové služby
    • HVAC Services
    Others
    • Nonprofit Organization
    • Agentura pro životní prostředí
    • Pronájem billboardů
    • Fotografování
    • Leasing jízdních kol
    • Prodejce softwaru
    Browse all Industries
  • Komunita
    Edukační program
    • Tutoriály
    • Dokumentace
    • Certifikace
    • Vzdělávání
    • Blog
    • Podcast
    Podpora vzdělávání
    • Vzdělávací program
    • Scale Up! Hra na firmu
    • Navštivte Odoo
    Získat software
    • Stáhnout
    • Porovnejte edice
    • Verze
    Spolupráce
    • Github
    • Fórum
    • Události
    • Překlady
    • Stát se partnerem
    • Services for Partners
    • Registrujte svou účetní firmu
    Získat služby
    • Najít partnera
    • Najít účetní
    • Setkejte se s poradcem
    • Implementační služby
    • Zákaznické reference
    • Podpora
    • Upgrady
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Dohodnout demo
  • Ceník
  • Pomoc

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

  • CRM
  • e-Commerce
  • Účetnictví
  • Sklad
  • PoS
  • Projekty
  • MRP
All apps
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
Pomoc

Count on2many records

Odebírat

Get notified when there's activity on this post

This question has been flagged
2 Odpovědi
15736 Zobrazení
Avatar
Abdullah Sofan

Is there a way to count the number of records in a one2many field? 
 

1
Avatar
Zrušit
Emipro Technologies Pvt. Ltd.

@abdullah What exactly you want to achieve by knowing the count of one2many fields?

Abdullah Sofan
Autor

I have two classes : (batches) & (batches.registrations) In (batches), I have a one2many field called "student_registrations" pointing to (batches.registrations) and showing the student registrations for this batch. However, I can only register 18 to 20 students as per the capacity of the classroom. I need to know how to limit the number of student registrations per batch in the one2many field once the registrations reach 18 or 20.

Prakash

Related topic link https://www.odoo.com/forum/help-1/question/how-set-limit-for-number-records-of-x2many-6627 https://www.odoo.com/forum/help-1/question/how-to-limit-the-total-number-values-for-a-one2many-field-49700

Avatar
Bole
Nejlepší odpověď

use len like.. 
 

so = self.pool.get('sale.order').browse(cr, uid, id)
count = len(so.order_line)

 

hope it helps

edit after comment:

also need to check if there is an object like:
count = so.order_line and len(so.order_line) or 0

1
Avatar
Zrušit
Abdullah Sofan
Autor

I tried this but I get this error: object of type 'bool' has no len()

Avatar
Atchuthan - Technical Consultant, Sodexis Inc
Nejlepší odpověď

Try using _constraints.

    def _check_batch_limit(self, cursor, user, ids, context=None):
        for record in self.browse(cursor, user, ids, context=context):
            //limit is set as 18 or 20
            if len(record.student_registrations) > record.limit:
                return False
        return True

    _constraints = [
        (_check_batch_limit, 'Error:Limit reached.', ['student_registrations']),
    ]

3
Avatar
Zrušit
Abdullah Sofan
Autor

I am sorry for my question... but does this code get the limit value from a field in the form?

Abdullah Sofan
Autor

This code does not work. Why did you accept the answer?

Atchuthan - Technical Consultant, Sodexis Inc

@Abdullah, No one will provide you exact code changes for your problem. We can only provide how this can be achieved. and VOTE is different from ACCEPT.

Atchuthan - Technical Consultant, Sodexis Inc

yes. I obtained the limit value from "LIMIT" field at FORM view.

Abdullah Sofan
Autor

Sorry for my previous comments. You were absolutely right from the start. Thanks you Atchuthan.

Enjoying the discussion? Don't just read, join in!

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

Přihlásit se
Komunita
  • Tutoriály
  • Dokumentace
  • Fórum
Open Source
  • Stáhnout
  • Github
  • Runbot
  • Překlady
Služby
  • Odoo.sh hostování
  • Podpora
  • Upgrade
  • Nestandardní vývoj
  • Edukační program
  • Najít účetní
  • Najít partnera
  • Stát se partnerem
O nás
  • Naše společnost
  • Podklady značky
  • Kontakujte nás
  • Práce
  • Události
  • Podcast
  • Blog
  • Zákazníci
  • Právní dokumenty • Soukromí
  • Zabezpečení
الْعَرَبيّة 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 je balíček open-source aplikací, které pokrývají všechny potřeby vaší společnosti: CRM, e-shop, účetnictví, sklady, kasy, projektové řízení a další.

Unikátní nabídka od Odoo poskytuje velmi jednoduché uživatelské rozhraní a vše je integrované na jednom místě.

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