Skip to Content
Odoo Menu
  • Prijavi
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

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

  • CRM
  • e-Commerce
  • Knjigovodstvo
  • Zaloga
  • PoS
  • Projekt
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
Pomoč

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

Naroči se

Get notified when there's activity on this post

This question has been flagged
domainmany2one
2 Odgovori
13322 Prikazi
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
Opusti
Avatar
Brett Lehrer
Best Answer

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
Opusti
Romuald Franck
Avtor

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
Avtor Best Answer

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

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!

Prijavi
Related Posts Odgovori Prikazi Aktivnost
Domain with inherited field Solved
domain many2one
Avatar
1
okt. 22
4483
Error in Creating Dynamic Domain for many2one field from onchange method in OpernErp v7 ???
domain many2one
Avatar
Avatar
Avatar
8
feb. 17
9072
Domain One2many filter
domain many2one
Avatar
0
jan. 17
6372
Set dynamic domain on fields based on other fields value Solved
domain many2one edit
Avatar
Avatar
Avatar
Avatar
4
maj 24
19390
domain in many2one that in One2many field Solved
domain many2one one2many
Avatar
1
okt. 22
4002
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة 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 is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

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