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

I want to filter the results based on the given criteria. I have a one2many field, in that field, I want to display the data based on the criteria. It is working fine at first but when I change the age range the workers who are not in the age range are getting deleted. My original worker details are getting deleted. When I change the age range again as previously, the workers who are in the given age range are also getting deleted. Please guide me on what I am doing wrong and how to fix this.


Thank you

@api.onchange('age_from', 'age_to', 'nationality')

    def _onchange_available_maids(self):

        age_from = self.age_from

        age_to = self.age_to

        nationality = self.nationality.id if self.nationality else False

        criteria = [('id', '!=', False)] 


        if age_from:

            criteria.append(('age', '>=', age_from))

        if age_to:

            criteria.append(('age', '

        if nationality:

            criteria.append(('nationality', '=', nationality))


        maid_model = self.env['my.model']

        new_maid_ids = maid_model.search(criteria).ids

        self.maid_ids = [(6, 0, new_maid_ids)]

 

Avatar
Buang
Jawaban Terbai

Hi,

just replace your last line of code and see if it works

self.maid_ids = [(6, 0, new_maid_ids)]

to

self.maid_ids = [(4, maid_id) for maid_id in new_maid_ids]

Thanks


Avatar
Buang
Penulis

It's still not working.

Btw, Thanks.

Penulis

It's kind of working but it is deleting my original worker details when I change the age range.
How can I fix this