Skip to Content
Menu
This question has been flagged
1 Reply
2544 Views

when the user select the "Aérrienne" option i just want to add new options to the type_transport select


```python

mode_transport = fields.Selection([ ('Routière\Maritime','Routière\Maritime'), ('Routière','Routière'),('Aérrienne','Aérrienne') ],string="Mode de Transport") type_transport = fields.Selection([('test1','test1')],string="responsible"

@api.onchange("mode_transport")

def _set_type_transport(self):

 if self.mode_trasport == False

  pass

 elif self.mode_transport == 'Aérrienne'

  self.type_transport = fields.Selection(add_selection=[("new option","new option")])

```


Avatar
Discard
Best Answer
_type_transport = [('test1','test1')]

mode_transport = fields.Selection([('Routière\Maritime', 'Routière\Maritime'), ('Routière', 'Routière'), ('Aérrienne', 'Aérrienne')],string="Mode de Transport")
type_transport = fields.Selection(lambda self: self._type_transport,string="responsible")

@api.onchange("mode_transport")
def _set_type_transport(self):
if self.mode_trasport == False :
return
elif
self.mode_transport == 'Aérrienne' :
self.type_transport =self._type_transport.append(("new option","new option"))

Avatar
Discard

You need to check to see if the option has already been added, such case may happen when you select the same option more than once.
And also you page need to be reloaded for the added options to show.

Related Posts Replies Views Activity
2
Dec 24
3122
1
Dec 24
350
4
Nov 24
1364
1
Sep 24
1134
1
Sep 24
1200