2016-10-18 2 views
1

Ich muss ein Auswahlfeld basierend auf anderen Spalte erstellen. Ich meine, die Daten stammen aus einer anderen Tabelle, basieren jedoch auf dem aktuellen Tabellenspaltenwert. Also habe ich ein Auswahlfeld, wie unten:odoo 8 selection field self immer leer

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

und die Funktion ist wie folgt:

@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')] 

Immer, wenn ich mich selbst debuggen erhalten als leere Klassenobjekt (stock.test()). das szenario ist ich habe eine spalte namens zone in stock.test, ich habe eine andere tabelle mit dem namen stock.location, also für den aktuellen rekord prüfe ich die stock.location tabelle wo die spalte pull_zone == zone of stock.test und falls ja, hänge die auswahl an (pull_location) mit diesen Werten. Aber immer ist das Objekt leer. Ich habe versucht @ api.one, @ api.multi, @ api.model, nichts passiert.

Bitte helfen. Danke,

+0

Überprüfen Sie die angenommene Antwort https://www.odoo.com/fr_FR/forum/aide-1/question/how-to-create-dynamic-selection-field-fields-selection-99421 – Zety

Antwort

1

Ersetzen Sie Ihren Code mit folgenden:

@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') 

Danach Restart Odoo Server und Ihr Modul aktualisieren.

+0

Hallo ODEDRA, das Selbst Objekt ist noch leer. Ich möchte Datensätze im Self-Objekt erhalten – user280960