user280960
user280960

Reputation: 721

odoo 8 selection field self always empty

I have to create a selection field based on other column. i mean the data comes from other table but based on current table column value. so i created a selection field as below:

pull_location = fields.Selection(selection='_get_pull_locations',string='Pull Location')

and the function is as below:

@api.multi
def _get_pull_locations(self):
    data=[]
    ** Get the values from other table based on current record ** 
    return [('value1', 'String 1'), ('value2', 'String 2')]

Always when i debug i get self as empty class object ( stock.test()). the scenario is i have a column named zone in stock.test, i have another table called stock.location, so for current record i check the stock.location table where column pull_zone == zone of stock.test and if yes append the selection (pull_location) with that values. But always the object is empty. I tried @api.one, @api.multi, @api.model , Nothing happens.

Please help. Thanks,

Upvotes: 1

Views: 662

Answers (1)

Bhavesh Odedra
Bhavesh Odedra

Reputation: 11143

Replace your code with following:

@api.multi
def _get_pull_locations(self):
    ** Get the values from other table based on current record ** 
    return [
        ('value1', 'String 1'), 
        ('value2', 'String 2')
    ]

pull_location = fields.Selection('_get_pull_locations', string='Pull Location')

Afterwards, Restart Odoo server and upgrade your module.

Upvotes: 1

Related Questions