Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
1 Balas
6775 Tampilan

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
Buang
Jawaban Terbai

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
Buang
Penulis

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

Post Terkait Replies Tampilan Aktivitas
1
Agu 23
1922
1
Mar 21
4125
0
Okt 20
3243
0
Des 18
13
1
Agu 17
3696