Skip to Content
Odoo Menu
  • Log ind
  • Prøv gratis
  • Apps
    Økonomi
    • Bogføring
    • Fakturering
    • Udgifter
    • Regneark (BI)
    • Dokumenter
    • e-Signatur
    Salg
    • CRM
    • Salg
    • POS Butik
    • POS Restaurant
    • Abonnementer
    • Udlejning
    Hjemmeside
    • Hjemmesidebygger
    • e-Handel
    • Blog
    • Forum
    • LiveChat
    • e-Læring
    Forsyningskæde
    • Lagerbeholdning
    • Produktion
    • PLM
    • Indkøb
    • Vedligeholdelse
    • Kvalitet
    HR
    • Medarbejdere
    • Rekruttering
    • Fravær
    • Medarbejdersamtaler
    • Anbefalinger
    • Flåde
    Marketing
    • Markedsføring på sociale medier
    • E-mailmarketing
    • SMS-marketing
    • Arrangementer
    • Automatiseret marketing
    • Spørgeundersøgelser
    Tjenester
    • Projekt
    • Timesedler
    • Udkørende Service
    • Kundeservice
    • Planlægning
    • Aftaler
    Produktivitet
    • Dialog
    • Godkendelser
    • IoT
    • VoIP
    • Vidensdeling
    • WhatsApp
    Tredjepartsapps Odoo Studio Odoo Cloud-platform
  • Brancher
    Detailhandel
    • Boghandel
    • Tøjforretning
    • Møbelforretning
    • Dagligvarebutik
    • Byggemarked
    • Legetøjsforretning
    Mad og værtsskab
    • Bar og pub
    • Restaurant
    • Fastfood
    • Gæstehus
    • Drikkevareforhandler
    • Hotel
    Ejendom
    • Ejendomsmægler
    • Arkitektfirma
    • Byggeri
    • Ejendomsadministration
    • Havearbejde
    • Boligejerforening
    Rådgivning
    • Regnskabsfirma
    • Odoo-partner
    • Marketingbureau
    • Advokatfirma
    • Rekruttering
    • Audit & certificering
    Produktion
    • Tekstil
    • Metal
    • Møbler
    • Fødevareproduktion
    • Bryggeri
    • Firmagave
    Heldbred & Fitness
    • Sportsklub
    • Optiker
    • Fitnesscenter
    • Kosmetolog
    • Apotek
    • Frisør
    Håndværk
    • Handyman
    • IT-hardware og support
    • Solenergisystemer
    • Skomager
    • Rengøringsservicer
    • VVS- og ventilationsservice
    Andet
    • Nonprofitorganisation
    • Miljøagentur
    • Udlejning af billboards
    • Fotografi
    • Cykeludlejning
    • Softwareforhandler
    Gennemse alle brancher
  • Community
    Få mere at vide
    • Tutorials
    • Dokumentation
    • Certificeringer
    • Oplæring
    • Blog
    • Podcast
    Bliv klogere
    • Udannelselsesprogram
    • Scale Up!-virksomhedsspillet
    • Besøg Odoo
    Få softwaren
    • Download
    • Sammenlign versioner
    • Udgaver
    Samarbejde
    • Github
    • Forum
    • Arrangementer
    • Oversættelser
    • Bliv partner
    • Tjenester til partnere
    • Registrér dit regnskabsfirma
    Modtag tjenester
    • Find en partner
    • Find en bogholder
    • Kontakt en rådgiver
    • Implementeringstjenester
    • Kundereferencer
    • Support
    • Opgraderinger
    Github Youtube Twitter LinkedIn Instagram Facebook Spotify
    +1 (650) 691-3277
    Få en demo
  • Prissætning
  • Hjælp

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

  • CRM
  • e-Commerce
  • Bogføring
  • Lager
  • PoS
  • Projekt
  • MRP
All apps
Du skal være registreret for at interagere med fællesskabet.
All Posts People Emblemer
Tags (View all)
odoo accounting v14 pos v15
Om dette forum
Du skal være registreret for at interagere med fællesskabet.
All Posts People Emblemer
Tags (View all)
odoo accounting v14 pos v15
Om dette forum
Hjælp

how to limit the total number values for a one2many field?

Tilmeld

Få besked, når der er aktivitet på dette indlæg

Dette spørgsmål er blevet anmeldt
one2manylimitvaluefor
5 Besvarelser
13686 Visninger
Avatar
Vivekrajan Rayappan

Hi,

I would like to have a feature on the one2many field. Usually we can add any number of values to a one2many field. But I want restrict the user to enter only the first three values and not more than three. Three is just an example count. I should be able to define it to any number.

To be more clear, I want the user to enter only 3 line items in the sales order. After entering 3 line items, the create/add option should disappear.

Is there any way already existing? or is it to be implemented yet?

Thanks in advance.

0
Avatar
Kassér
Avatar
Prakash
Bedste svar

I have solution but without disappear Create/add option. To override create and write method and allow to user enter only 3 lines item.

Example:-

def create(self, cr, uid, vals, context=None):
       if vals.get('order_line'):
            count = len(vals.get('order_line'))
            if count > 3:
                raise osv.except_osv(_('Warning!'), _('Limit to create 3 Lines'))
        return super(sale_order, self).create(cr, uid, vals, context=context)

def write(self, cr, uid, id, vals, context=None):
    if vals.get('order_line'):
        count = len(vals.get('order_line'))
        if count > 3:
            raise osv.except_osv(_('Warning!'), _('Limit to create 3 Lines'))
    return super(sale_order, self).write(cr, uid, id, vals, context=context)
3
Avatar
Kassér
Vivekrajan Rayappan
Forfatter

Prakash, that works but a little late while saving the form. But It should work instantly as we try to add the fourth one. Because, i will be able to add more than 3 upto any number with your solution and it is going to warn me only at the moment of saving the form. my time of entering more than 3 should be saved right upfront. I think it is only possible if we make changes in the x2many widget java scripts

Avatar
Ameen Rabea
Bedste svar

I posted similar question of yours, but I need when user add more than , let's say, 5 items I warn him and delete the extra elements.

I was able to do onchange method, but I am not able to delete the extra items he added. Also I don't need to wait until the user click the parent "Save" button, but I need once he added the extra child element I delete it before waiting until save.

I tried to delete the extra item from child_ids list, or to use the unlink function but of Parent and Child, but no luck =(

How to delete the extra elements?


here is my post: 

https://www.odoo.com/fr_FR/forum/aide-1/question/how-to-prevent-adding-more-than-x-items-into-one2many-98375



0
Avatar
Kassér
Avatar
Vivekrajan Rayappan
Forfatter Bedste svar

Hi,

I have found a solution that best suits my requirement. That is to have a on_change method for the x2many field and check the count using len() python function. If it is more than 3 or x number, then popup a error message.

Apart from these, there are two other solutions. they have been mentioned already by Yug Faa and Prakash. i.e

1) Customize the x2many widget using js

2) Inherit the create and write method

Thanks to Prakash and Yug for their contribution.

0
Avatar
Kassér
Avatar
Yug Faa
Bedste svar

You will find a addons here :

bzr branch lp:~sylvain-legal/web-addons/web_field_float_compute

Module named : web_m2x_options

Make it resolved !

0
Avatar
Kassér
Enjoying the discussion? Don't just read, join in!

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

Tilmeld dig
Related Posts Besvarelser Visninger Aktivitet
How to set limit row in tree view one2many in form view?
one2many limit
Avatar
Avatar
Avatar
Avatar
4
dec. 16
16358
How to go through a one2many field that contains text and the information obtained put it in another field
one2many for v15
Avatar
Avatar
1
okt. 23
2087
How To prevent adding more than X items into One2Many Løst
one2many limit prevent
Avatar
Avatar
1
feb. 16
9432
How to set limit of items for one2many list view?
one2many limit pagination
Avatar
1
mar. 15
7770
Set max limit of rows one2many may contain
one2many v7 limit records
Avatar
Avatar
1
apr. 24
7167
Community
  • Tutorials
  • Dokumentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Oversættelser
Tjenester
  • Odoo.sh-hosting
  • Support
  • Opgradere
  • Individuelt tilpasset udvikling
  • Uddannelse
  • Find en bogholder
  • Find en partner
  • Bliv partner
Om os
  • Vores virksomhed
  • Brandaktiver
  • Kontakt os
  • Stillinger
  • Arrangementer
  • Podcast
  • Blog
  • Kunder
  • Juridiske dokumenter • Privatlivspolitik
  • Sikkerhedspolitik
الْعَرَبيّة 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 er en samling open source-forretningsapps, der dækker alle dine virksomhedsbehov – lige fra CRM, e-handel og bogføring til lagerstyring, POS, projektledelse og meget mere.

Det unikke ved Odoo er, at systemet både er brugervenligt og fuldt integreret.

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