This question has been flagged
3 Replies
7441 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 ? 

Avatar
Discard
Best Answer

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.

Avatar
Discard
Best Answer

Hi, 

You can follow following link for this:

https://youtu.be/GPhgxxwprA4

Hope it helps,

Thanks

Avatar
Discard
Author Best Answer

Ivan, 

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 ?

Avatar
Discard

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.

Author

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

Pleasure to help.