i have created a wizard which is transient model and i have written a function for searching records as:
def key(self, priority):
priority_dict = {
1: 'name',
2: 'membership_id',
3: 'tracking_id',
}
return priority_dict[priority]
def value(self, priority):
priority_dict = {
1: self.file_id.name,
2: self.membership_id.ref,
3: self.tracking_id,
}
return priority_dict[priority].strip()
def search_related_file(self):
self.return_line.unlink()
priority_list = [self.file_id, self.membership_id, self.tracking_id, self.member_id]
priority = 0
record = []
if not any(priority_list):
raise ValidationError(_('Must populate one of the above field for search.'))
for rec in priority_list:
if not rec:
priority = priority + 1
elif rec:
priority = priority + 1
break
if priority == 4:
member_id = self.env['res.partner'].search([('cnic', '=', self.member_id)])
if member_id:
record = self.env['file'].search([('membership_id', '=', member_id.id)])
else:
record = self.env['file'].search([(self.key(priority), '=', self.value(priority))])
# record = self.env['file'].search([('membership_id','=',self.membership_id.ref)])
if record:
for rec in record:
self.return_line.create({
'file_id': rec.id,
'return_id': self.id
})
return {
'type': 'ir.actions.do_nothing'
}
it is giving me the result of previous search. For example if i search from a file_id field and select 1st file it doesn't return anything but then if i search again with 2nd file option from list then it gives the result of 1st file in one2many field i tried to debug the code it gives the correct records but doesn't return correct records in the wizard. I couldn't understand this behavior because the exact same function is working correctly in version 11. any idea???