Pular para o conteúdo
Menu
Esta pergunta foi sinalizada
1 Responder
6776 Visualizações

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
Cancelar
Melhor resposta

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
Cancelar
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']

Publicações relacionadas Respostas Visualizações Atividade
1
ago. 23
1922
1
mar. 21
4127
0
out. 20
3243
0
dez. 18
13
1
ago. 17
3697