Skip to Content
Odoo Menu
  • Sign in
  • 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
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

How to retrive values in Many2one field as selection field?

Subscribe

Get notified when there's activity on this post

This question has been flagged
pythonmany2oneselectiononchangeodoo
2 Replies
17145 Views
Avatar
Mostafa Mohamed Abdel Monaem

How to retrieve values on Many2one field using OnChange ?

When i try to do so it gives me an error

'Expected singleton: fci.standard.groups(3, 4, 5, 6)'

I'm trying that when i change the standard field the group field will be updated to select only groups in this standard

Here is my fields

'standard_id': fields.many2one('fci.standard', string='Standard', required=True),

'group_id': fields.many2one('fci.standard.groups', string='Standard Group'),

Here is my function

def on_change_standard(self, cr, uid, ids, standard_id, context=None):

val = {}

if not standard_id:

return {}

student_obj = self.pool.get('fci.standard')

student_data = student_obj.browse(cr, uid, standard_id, context=context)

val.update({'group_id': student_data.groups_ids.id})

return {'value': val}

and here is my xml

<field name="standard_id" on_change="on_change_standard(standard_id)" widget="selection"/>

<field name="group_id" widget="selection"/>

0
Avatar
Discard
Cyril Gaspard (GEM)

hi, you try to set a list of id in a many2one field which requires just one id, this not possible, you should have same type of field for group_id than groups_ids, if you want that values for group will be always the same in 2 class, use a field function type with type of groups_ids. bye

Avatar
Baiju KS
Best Answer

Hi,

You can't pass more than one 'id' to a many2one field, that’s why you are getting error.

Its seems like you need domain filter , Please Check this :- (and add a proper filter for this field :   <field name="group_id" widget="selection"/>    )


Simple condition in programming:

if field1 = 10

In OpenERP domain filter, it will be written as:

syntax : Each tuple in the domain has three fields -> (‘field_name’, ‘operator’, value)

field_name : a valid name of field of the object model or in the database table

operator : valid operators are =, !=, >, >=, <, <=, like, ilike, in, not in, child_of, parent_left, parent_right (openerp/osv/expression.py)

value : a valid value to compare with the values of field_name, depending on its type.

ie, domain = [(‘field1′,’=’,10)] # where field1 should be a field in the model and 10 will be the value

or domain = [(‘field1′,’=’,field2)] # where field1 and field2 should be the fields in the model

Condition AND

Simple condition in programming:

if field1 = 5 and field2 = 10

In OpenERP domain filter, it will be written as:

ie, domain = [(‘field1′,’=’,5),(‘field2′,’=’,10)]

or domain = [(‘field1′,’=’,field3),(‘field1′,’=’,field3)]

Note : Note that if you don’t specify any condition at the beginning and condition will be applied.

Condition OR

Simple condition in programming:

if field1 = 5 or field2 = 10

In OpenERP domain filter, it will be written as:

ie, domain = [‘|’, (‘field1′,’=’,5),(‘field2′,’=’,10)]

or domain = [‘|’, (‘field1′,’=’,field3),(‘field1′,’=’,field3)]

Multiple Condition

Simple condition in programming:

if field1 = 5 or (field2 ! = 10 and field3 = 12)

In OpenERP domain filter, it will be written as:

domain = [‘|’,(‘field1′,’=’,5),(‘&’,(‘field2′,’!=’,10),(‘field3′,’=’,’12’))]


Hope this helps........

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

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

Sign up
Related Posts Replies Views Activity
How to Use Many2one Field as selection for details?
many2one selection onchange
Avatar
Avatar
1
Jul 19
7793
Filtering Many2one data based on selected status
filter many2one selection onchange
Avatar
Avatar
1
Aug 23
2572
bug sort selection field in one2many(notebook) view
many2one selection sort notebook odoo
Avatar
Avatar
1
Jun 24
1989
How can I create a selection of companies ? Solved
many2one selection res.company odoo v15
Avatar
Avatar
Avatar
2
Nov 22
4027
Can't change custom field value that is on another model
python many2one account.move onchange account.move.line
Avatar
Avatar
1
Apr 22
4150
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