Aide

0

How to Use Many2one Field as selection for details?

Avatar
vx2008

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
Annuler
1 Réponse
0
Avatar
Anu
Meilleure réponse

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}

1 Commentaires
Avatar
Annuler
Avatar
vx2008
-

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