Odoo Help

Welcome!

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.

0

Change Selection field with onchange api ?

By
Azzedine
on 5/24/16, 5:58 AM 796 views

Hello,

I have an issue when updating selection field in an onchange function, here is my python code :


class Billard(models.Model):
_name = 'billard'
name = fields.Char()
value = fields.Integer()
value2 = fields.Float(compute="_value_pc", store=True)
value3 = fields.Selection(string="Selection",selection=[('pair','Pair'),('impair','Impair')],default = 'impair')
value4 = fields.Selection(string="Selection dependante",selection = [('1','1'),('3','3'),('5','5')])
description = fields.Text()
   boule_id = fields.One2many('boules','billard_id')

@api.onchange('value3')
def get_selection(self) :
if self.value3 :
if self.value3 == "impair" :
self.value4 = [('1','1'),('3','3'),('5','5')]
else :
self.value4 = [('2','2'),('4','4'),('6','6')]
else :
self.value4 = [('1','Select Value 3')]

I get this error on forme view : ValueError: Wrong value for billard.value4: [('1', '1'), ('3', '3'), ('5', '5')]

Did i anything wrong ?

thank you :)


0
Ruchir Shukla
On 5/24/16, 8:56 AM

Hello !

You can not change the Selection field selection property from onchange . you can only change the Value of the selection field (Selected Value from the already selection keys and values).

To achieve what you want  you have to create the Object . use many2one to that object instead of the selection field .

And return the domain in the Onchange . that will work properly .

You can also use the widget="selection" in the xml file for m2o  or use no_create option that will give look and feel for selection field.

 

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

1 follower(s)

Stats

Asked: 5/24/16, 5:58 AM
Seen: 796 times
Last updated: 5/24/16, 8:56 AM