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 create dynamic selection field (fields.selection)?

Subscribe

Get notified when there's activity on this post

This question has been flagged
developmentselectionopenerpodooV8odoo8.0
5 Replies
73883 Views
Avatar
ALI ABDELMONEIM AMER

i face a problem with filling the (fields.selection) with dynamic data comes from database 

so for example if i change the customer value i want to fill the selection field with the coming data from database dynamically

i just need to do this with the selection field

 

from openerp.osv import osv,fields 

PACKAGE_TYPE_SELECTION = []

class test(osv.osv) :
_name = "Test"
_columns ={ 
'selection': fields.selection(PACKAGE_TYPE_SELECTION, string='Selection'),
}
0
Avatar
Discard
Avatar
Sudhir Arya (ERP Harbor Consulting Services)
Best Answer

Hello Ali,

You can call a function for your selection field.

Ex:

class ...
def get_journals(cr, uid, context=None):
journal_obj = self.pool.get('account.journal')
journal_ids = journal_obj.search(cr, uid, [], context=context)
lst = []
for journal in journal_obj.browse(cr, uid, journal_ids, context=context):
lst.append((journal.id, journal.name))
return lst
    _columns ={ 
        'selection': fields.selection(_get_journals, string='Selection'),
    }

Hope this will help you.

8
Avatar
Discard
ALI ABDELMONEIM AMER
Author

Thanks A lot for your reply but if i want to do it via onchange method ?

Sudhir Arya (ERP Harbor Consulting Services)

No, you cannot do it with onchange.

Ưng Tú

but function get_journals only run when i update module, pls confirm?

Avatar
Ankit H Gandhi(AHG)
Best Answer

Hi,

You can see this type of custom dropdownlist (selection) into pricelist file of product module. It looks like below.

def _price_field_get(self, cr, uid, context=None):

mf = self.pool.get('ir.model.fields')

ids = mf.search(cr, uid, [('model','in', (('product.product'),('product.template'))), ('ttype','=','float')], context=context)

res = []

for field in mf.browse(cr, uid, ids, context=context):

res.append((field.name, field.field_description))

return res

_columns = {

"field" : fields.selection(_price_field_get, "Product Field", size=32, required=True, help="Associated field in the product form."),

}

Here 'field' is selection and its data is comes dynamic from the method "_price_field_get".

Hope you will get custom dropdownlist.

Best Regards,

Ankit H Gandhi.

3
Avatar
Discard
Avatar
Martin Salcedo Pacheco
Best Answer

This post has years but I had the same question. May this way can help for new implementations


type_tax_use = fields.Selection(
[
('sale', 'Sale'),
​ ​ ​('purchase', 'Purchase'),
​ ​], default='purchase', string="Tax Type")

move_type = fields.Selection(
[
('in_invoice', 'Purchase Invoice'),
('in_refund', 'Purchase Credit Note'),
('out_invoice', 'Sale Invoice'),
('out_refund', 'Sale Credit Note'),
], default='in_invoice', string="Invoice Type"
)

sale_move_type = fields.Selection(
[
('out_invoice', 'Sale Invoice'),
('out_refund', 'Sale Credit Note'),
], default='out_invoice', string="Sale Invoice Type"
)
purchase_move_type = fields.Selection(
[
('in_invoice', 'Purchase Invoice'),
('in_refund', 'Purchase Credit Note'),
], default='in_invoice', string="Purchase Invoice Type"
)

@api.onchange('sale_move_type','purchase_move_type')
def _onchange_ref_move_type(self):
if self.type_tax_use == 'sale':
self.move_type = self.sale_move_type
elif self.type_tax_use == 'purchase':
self.move_type = self.purchase_move_type

In the xml you show the desired field according to type_tax_use with domain scope

0
Avatar
Discard
Avatar
Khaled Said
Best Answer

there are 3 pattern for that to be approached

https://dev.to/kerbrose/dynamic-selection-list-in-odoo-for-selection-fields-16h8

0
Avatar
Discard
Avatar
Tarek Mohamed Ibrahim
Best Answer

Make your field a many2one field

'my_field': fields.many2one('my.table', ... ),

put the 'selection' widget

<field name="my_field" widget="selection" ...>

in an 'on_change' method set the appropriate domain for your selection field and return this domain , this will change the values appearing in your dropdown selection list

def onchange_for_my_field(self, cr, uid, ids, param1, param2, ... , context=None):
     ...
       return {'domain' : 
             {'my_field':
             [('field1','=',val1),('field2','=',val2),... ] }
     }

where field1 and field2 , ... are fields in the table 'my.table' that could be used to filter the result.

Hope this solution is useful



0
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
TransactionRollbackError: could not serialize access due to concurrent update
openerp odoo odooV8 odoo8.0
Avatar
0
Dec 15
7814
How to upgrade openerp 7 database to odoo 8?
openerp odoo odooV8 odoo8.0
Avatar
Avatar
5
Nov 15
6728
How to override the create function with the new api
openerp odoo odooV8 odoo8.0
Avatar
Avatar
1
Jul 15
8430
How to calculate total amount sub total in Purchase Order and Invoice based on a new field..
inheritance openerp odoo odooV8 odoo8.0
Avatar
0
Oct 17
10818
How to place pie chart on form view? (Odoo V8.0)
development form odoo odooV8 odoo8.0
Avatar
Avatar
1
Jan 17
6150
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