Odoo Help


This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Functionnal field type selection issue openerp v7

Yassine TEIMI
on 12/11/14, 10:10 AM 865 views

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 ?


Emipro Technologies Pvt. Ltd.

--Emipro Technologies Pvt. Ltd.--
Tiny ERP Pvt Ltd
| 6 7 8
Rajkot, India
--Emipro Technologies Pvt. Ltd.--

Being an emerging leader in IT market since 2011, Emipro Technologies Pvt. Ltd. has been providing a wide range of business solutions in Odoo & Magento. We are pleased to have a large pool of contented customers with our meticulous work in the domain of ERP & e-Commerce. A ray of relief & satisfaction to  our customers heart by our successful deployment in their organization, purely represents our success in Odoo platform. Hence, we take pride for being an Odoo partner with a vision of expanding our strategic alliances with our customers to offer them high value-added, trustworthy & cost effective solutions.


Since establishment, our business has span across 11 countries of the world. Our customers are companies of all sizes ranging from start-ups to large enterprises, who realize that they need a professional business solutions to generate revenue streams, establish proper communication channels or streamline business operations. Standing with strong determination of customer satisfaction, observing each minute detail of their business processes, providing proper guidance and moving forth to develop product accordingly adds our value and reliability among our customers. 


We are blessed with efficient, passionate & eclectic young developers who have come across almost all kinds of business profiles, working with full dedication, applying creativity & new features in existing modules and completing customer's projects successfully on predefined target. Our in-depth knowledge while giving business solutions in Odoo allows us to offer following services to our customers :


  • Consulting
  • Installation, Configuration & Customization
  • Training & Support
  • Maintenance
  • Upgradation
  • Documentation
  • Crafting community modules
  • Drafting videos on demand
  • Smart Apps development

We will be :) to welcome you @ www.emiprotechnologies.com to solve any kind of your business needs around Odoo. However we are just an inch away from you by email info@emiprotechnologies.com or a tweet to @EmiproTech

Emipro Technologies Pvt. Ltd.
On 12/12/14, 1:21 AM


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.


On 1/3/15, 10:47 AM

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 ?


Yassine TEIMI
On 12/12/14, 3:44 AM


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 ? 

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)


Asked: 12/11/14, 10:10 AM
Seen: 865 times
Last updated: 7/30/15, 5:17 AM