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í
    Jídlo a pohostinství
    • Bar a Pub
    • Restaurace
    • Fast Food
    • Penzion
    • Distributor nápojů
    • Hotel
    Nemovitost
    • Realitní kancelář
    • Architektonická firma
    • Stavba
    • Správa nemovitostí
    • Zahradnictví
    • Asociace vlastníků nemovitosti
    Poradenství
    • Účetní firma
    • Odoo Partner
    • Marketingová agentura
    • Právník
    • Akvizice talentů
    • Audit a certifikace
    Výroba
    • Textile
    • Kov
    • Nábytek
    • Jídlo
    • Brewery
    • Korporátní dárky
    Zdraví a fitness
    • Sportovní klub
    • Prodejna brýli
    • Fitness Centrum
    • Wellness praktikové
    • Lékárna
    • Kadeřnictví
    Transakce
    • Údržbář
    • IT hardware a podpora
    • Systémy solární energie
    • Výrobce obuvi
    • Úklidové služby
    • Služby HVAC
    Ostatní
    • Nezisková organizace
    • 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

[solved] domain restriction and clear the previously selected value of a many2one field

Odebírat

Get notified when there's activity on this post

This question has been flagged
domainmany2one
2 Odpovědi
13374 Zobrazení
Avatar
Romuald Franck

Hi to everyone!

I have two many2one fields (list1 and list2) in the same class and view. I want when a user select a value from list1, the list2 to automatically update with a restriction domain value. this is done

But I also want the 'previously' selected value of list2 to be drop so that the user is force to reselect it, in the case he has previously selected a value in list2 and then reselect in list1. Because domain restriction only update the list2 but leave the previously (now not pertinant) value of list2 and the user can pass. Thx to any help!

0
Avatar
Zrušit
Avatar
Brett Lehrer
Nejlepší odpověď

You need to add an onchange event to list1. Would look something like this in the XML:

<field name="list1" on_change="my_onchange_function(list1)"/>

Then you'd need a function in that object with the name listed in on_change, which is hopefully a better name than my example:

def my_onchange_function(self, cr, uid, ids, list1, context=None):
    if context is None: context = {}
    # If there's a value in list1 now, empty list2.
    res = {}
    if list1:
        res['list2'] = False
        res['list3'] = False
        res['some_number'] = 0
    return {'value': res}

You could add in a few more features to make the onchange function a bit smarter, but that will basically do the job.

1
Avatar
Zrušit
Romuald Franck
Autor

Thank you it works. I have put another on_change action on list2 and it was that which gave me errors. I have fixed it. Please How to return many value for several fields at a time. Thx

Brett Lehrer

Just keep adding dictionary entries to res. I'll edit the answer to change multiple values at once.

Avatar
Romuald Franck
Autor Nejlepší odpověď

I tried it but got and error. Please look . Here is my onchange def :

def on_change_salle_de_classe_id(self,cr,uid,ids,salle_de_classe_id,context=None):
    salle_de_classe = self.pool.get('schoolem.salle_de_classe').browse(cr,uid,salle_de_classe_id)

    cours_obj = self.pool.get('schoolem.cours')
    ids1 = cours_obj.search(cr, uid, [('niveau_id.id', '=', salle_de_classe.classe_id.niveau_id.id)])
    ids2 = cours_obj.search(cr, uid, [('niveau_id.id', '=', salle_de_classe.classe_id.niveau_id.id),('specialite_id.id', '=', salle_de_classe.classe_id.specialite_id.id)])
    if context is None: context = {}
    # If there's a value in list1 now, empty list2.
    res = {}        
    if salle_de_classe_id:
        res['cours_id'] = False
    return {'value': res}
    #return {'domain':{'cours_id':[('id','in',ids1+ids2)]}}
    #return {'value':{'cours_id':False},'domain':{'cours_id':[('id','in',ids1+ids2)]}}

but I got this error :

ProgrammingError: ERREUR: l'opérateur n'existe pas : integer = boolean LINE 1: ....id FROM "schoolem_cours" WHERE schoolem_cours.id IN (false)...
^ HINT: Aucun opérateur ne correspond au nom donné et aux types d'arguments. Vous devez ajouter des conversions explicites de type.

0
Avatar
Zrušit
Brett Lehrer

This is a type casting error due to the fact that one of the IDs you're filtering on is actually not set at all. Make sure you're checking that ids1 and ids2 both have values in them first before returning them into the domain. Both are currently returning empty lists, which translates to False, generating an error down the road. Also, since ids2 is a subset of ids1, there will be duplicate ids in the combined list, and a quick way to fix that before passing it along is to use list(set(ids1+ids2)). Convert to a set to remove duplicates, then back to a list.

Romuald Franck
Autor

I tried this :return {'domain':{'cours_id':[('id','in',list(set(ids1+ids2)))]},'value':{'cours_id':False}} but still have the same error. Even without using domain

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
Related Posts Odpovědi Zobrazení Aktivita
Domain with inherited field Vyřešeno
domain many2one
Avatar
1
říj 22
4511
Error in Creating Dynamic Domain for many2one field from onchange method in OpernErp v7 ???
domain many2one
Avatar
Avatar
Avatar
8
úno 17
9116
Domain One2many filter
domain many2one
Avatar
0
led 17
6397
Set dynamic domain on fields based on other fields value Vyřešeno
domain many2one edit
Avatar
Avatar
Avatar
Avatar
4
kvě 24
19448
domain in many2one that in One2many field Vyřešeno
domain many2one one2many
Avatar
1
říj 22
4053
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