Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
6626 Vistas

I code part as below :

class Selection(models.Model):
    _name = 'selection.model' 
    _rec_name = 'select'
    select = fields.Char(string='selections', required=True)

class Checks(models.Model):
    _name = 'buy.goods' 
    strs = fields.Char()
    results = fields.Many2one('selection.model', string='Selections')

    @api.onchange('strs')
    def _get_results(self): 
        goods = self.strs.split(',')
        ...

I want to show all items of 'goods' as selections of 'results' field; and when 'strs' field is changed, the selections of 'results' field should be updated at once. so how shall I code for this?


Avatar
Descartar
Mejor respuesta

Hi,  

if you want to display the many2one field like selection  you can use  widget="selection" and you can  write a method on onchange of many2one field and return domain in that method based on condition.

@api.onchange('result')
def onchange_result_ids(self):
if self.strs:
domain = {'result': [(condition)]}
return {'domain': domain}

Avatar
Descartar
Autor

thanks for your reply;

but i think the effect of your code is select some items but what i means is that the select items of 'result' are from 'strs'; for example, 'strs' = 'this is good'; then the select items list of 'result' should be ['this','is','good']

Publicaciones relacionadas Respuestas Vistas Actividad
1
ago 23
1782
1
mar 21
3990
0
oct 20
3086
0
dic 18
13
1
ago 17
3552