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č

Functionnal field type selection issue openerp v7

Naroči se

Get notified when there's activity on this post

This question has been flagged
3 Odgovori
3728 Prikazi
Avatar
TEIMI Yassine

I want to display dynamically a list of values on a field, so I choosed a functionnal field, type = selection, like this : 

'Numeros_bl': fields.function(_get_selection, string ='Numeros Bls', type = 'selection'),

The function is like this : 

def _get_selection(self, cr, uid, ids, Numeros_bl, arg, context = None):

        default = {
            'value': {'Numeros_bl': {} }
        }
        DO = self.pool.get('stock.picking.out')
        rec = self.browse(cr, uid, ids[0])
        partner_id = rec.partner_id
        do2pay_ids = DO.search(cr, uid, [('partner_id','=',partner_id),('state','=','done'),('invoice_state','=','2binvoiced')])
        for do2pay in do2pay_ids :
            do_rec= DO.browse(cr, uid, do2pay)
            rs = {
                'Numeros_bl': do_rec.num_bl,
            }
            default = default.append(rs)
        return default

The problem is that this function return nothing, and I don't have any server errors, so maybe it return an empty return.

I know there is something wrong maybe with :   default = {
            'value': {'Numeros_bl': {} }
        }

or :             rs = {
                'Numeros_bl': do_rec.num_bl,
            }
            default = default.append(rs)

or the return type, because the the function should return a selection type, because I made type = selection on the decalaration of the field, can you please tell me where I did it wrong ?

1
Avatar
Opusti
Avatar
Emipro Technologies Pvt. Ltd.
Best Answer

Hi,

According to the following ex. you can make the dynamic selection values.

Field as like below.

'extension': fields.selection(_extension_get, 'Document Type', required=True, size=4),

Function is as like below.

    def _extension_get(self, cr, uid, context=None):
        cr.execute('select code,name from document_directory_content_type where active')
        res = cr.fetchall()
        return res

Note : This is available on the document module.

 

1
Avatar
Opusti
Avatar
TEIMI Yassine
Avtor Best Answer

Hi,

Thank you for your anwser, I did exactly the same thing, here is my code : 

from openerp.osv import fields, orm, osv

class AccountVoucher(orm.Model):

    def _get_selection(self, cr, uid, context):

        active_id = context.get('active',[])
        voucher_rec = self.browse(cr, uid, active_id)
        partner = voucher_rec.partner_id.id
        cr.execute("SELECT num_bl,num_bl FROM stock_picking WHERE state='done' and invoice_state='2binvoiced' and partner_id=%s",(partner,))

        return cr.fetchall()

    _inherit = 'account.voucher'
    _name = 'account.voucher'
    _columns = {
        'bls_to_pay': fields.one2many('stock.picking.out','bl_id','BLS to pay', readonly = True),
        'Numeros_bl': fields.selection(_get_selection, 'Numeros Bls', size=32),
    }

I want to pass the partner_id into the function _get_selection for that I think there is two solutions ( wich I wish to be corrected if wrong )  :

Passing directly the partner_id on the context via XML.

Passing the id of the current recored via ids[0] or active_id and browse on the current record id, then get the field partner_id.

I used selection field ( not functionnal field ) it doesn't take ids as a parameter, and I tried to pass the partner_id by XML context like this :  <field name="Numeros_bl" context="{'active': active_id}"/>

Nothing of these solutions is working.

The problem now is how to get the partner_id so as to use it on the where condition ? Should I use a functionnal field instead of dynamic selection ? 

0
Avatar
Opusti
Avatar
Bruno PLANCHER
Best Answer

Hello yassine TEIMI,

I don't understand want you want to do, you wish to display a list of values coming for a one2many field ?

Do you want the user be able to modify this value ?

If yes for the 2 questions, you have another way to do that (as the _get_selection() method is called  before having the current record on context, this is not the correct way to do that): 

You can define your field Numeros_bl as a many2one (related to stock.picking.out) instead of a selection, and then in your view, you use the widget "selection" to display each element of this model as a selection field.

Finally, to filter your model with partner_id, you can do that too in the view adding the correct domain, which results in : 

<field name="Numeros_bl" widget=selection" domain="[('partner_id.id', '=', partner_id)]" />

 

This will work if your model stock.picking.out has a "name" field, or at least a "nam_get()" method defined, it uses those values to display each record on a many2one / selection widget.

Does it helps you ?

Regards

0
Avatar
Opusti
Enjoying the discussion? Don't just read, join in!

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

Prijavi
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