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