Odoo Help


How to pass Context to Dynamic selection field method, openerpv7

Yassine TEIMI
on 12/12/14, 5:12 AM 2,067 views

I am on account_voucher module, on voucher_payment_receipt_view.xml , I customized the view by a custom module, as follows :

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=%d"%(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),

The field that interests us in this question is 'Numeros_bl' , I made it a dynamic selection, but I want to filter on the partner_id just selected, i em unable to get this partner_id selected on the current active record.

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 ? 




| 5 3 6
Jakarta, Indonesia
On 12/12/14, 5:35 AM

Yassine, you won't get active_id in the context because _get_selection will be called before the active record is read.  Your best bet is to use many2one field to stock.picking, apply domain to this field via on_change and if you need the num_bl to be shown, inherit the name_get method.

Yassine TEIMI
On 12/12/14, 5:52 AM


I made a many2one field into stock.picking, with a domain on xml : 

It works, but I want to override name_get, to show num_bl data as you said, I didn't find name_get on stock.picking, should I search for it on account.voucher ?

You should inherit name_get for stock.picking, not for account.voucher. name_get is a standard method available to all orm models. If the no module had inherited for stock.picking yet then it will run the one in odoo/openerp/osv/orm.py. You can look into addons/account_voucher/account_voucher.py to get the idea of how to inherit, though.

on 12/12/14, 6:57 AM

Thanks Ivan I overrided succefully the name_get, I marked the topic as solved.

Yassine TEIMI
on 12/12/14, 9:05 AM

Pleasure to help.

on 12/14/14, 8:54 PM

About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 12/12/14, 5:12 AM
Seen: 2067 times
Last updated: 3/16/15, 8:10 AM