diff --git a/request-management-api/request_api/models/FOIMinistryRequests.py b/request-management-api/request_api/models/FOIMinistryRequests.py index 12a1c2fdc..6f3d22a90 100644 --- a/request-management-api/request_api/models/FOIMinistryRequests.py +++ b/request-management-api/request_api/models/FOIMinistryRequests.py @@ -438,16 +438,19 @@ def getrequestssubquery(cls, groups, filterfields, keyword, additionalfilter, us if(len(filterfields) > 0 and keyword is not None): filtercondition = [] for _keyword in _keywords: + onekeywordfiltercondition = [] if(_keyword != "restricted"): for field in filterfields: - filtercondition.append(FOIMinistryRequest.findfield(field, iaoassignee, ministryassignee).ilike('%'+_keyword+'%')) + onekeywordfiltercondition.append(FOIMinistryRequest.findfield(field, iaoassignee, ministryassignee).ilike('%'+_keyword+'%')) else: if(requestby == 'IAO'): - filtercondition.append(FOIRestrictedMinistryRequest.isrestricted == True) + onekeywordfiltercondition.append(FOIRestrictedMinistryRequest.isrestricted == True) else: - filtercondition.append(ministry_restricted_requests.isrestricted == True) + onekeywordfiltercondition.append(ministry_restricted_requests.isrestricted == True) if (_keyword == "oipc"): - filtercondition.append(FOIMinistryRequest.isoipcreview == True) + onekeywordfiltercondition.append(FOIMinistryRequest.isoipcreview == True) + + filtercondition.append(or_(*onekeywordfiltercondition)) intakesorting = case([ (and_(FOIMinistryRequest.assignedto == None, FOIMinistryRequest.assignedgroup == 'Intake Team'), # Unassigned requests first @@ -708,7 +711,7 @@ def getrequestssubquery(cls, groups, filterfields, keyword, additionalfilter, us if(keyword is None): return dbquery else: - return dbquery.filter(or_(*filtercondition)) + return dbquery.filter(and_(*filtercondition)) @classmethod def getrequestspagination(cls, group, page, size, sortingitems, sortingorders, filterfields, keyword, additionalfilter, userid, isiaorestrictedfilemanager, isministryrestrictedfilemanager): diff --git a/request-management-api/request_api/models/FOIRawRequests.py b/request-management-api/request_api/models/FOIRawRequests.py index 027e6ee86..ab9e6ee43 100644 --- a/request-management-api/request_api/models/FOIRawRequests.py +++ b/request-management-api/request_api/models/FOIRawRequests.py @@ -696,22 +696,25 @@ def getfilterforrequestssubquery(cls, filterfields, keyword): #filter/search filtercondition = [] for _keyword in _keywords: + onekeywordfiltercondition = [] if(_keyword != 'restricted'): for field in filterfields: if(field == 'idNumber'): _keyword = _keyword.replace('u-00', '') - filtercondition.append(FOIRawRequest.findfield(field).ilike('%'+_keyword+'%')) + onekeywordfiltercondition.append(FOIRawRequest.findfield(field).ilike('%'+_keyword+'%')) if(field == 'firstName'): - filtercondition.append(FOIRawRequest.findfield('contactFirstName').ilike('%'+_keyword+'%')) + onekeywordfiltercondition.append(FOIRawRequest.findfield('contactFirstName').ilike('%'+_keyword+'%')) if(field == 'lastName'): - filtercondition.append(FOIRawRequest.findfield('contactLastName').ilike('%'+_keyword+'%')) + onekeywordfiltercondition.append(FOIRawRequest.findfield('contactLastName').ilike('%'+_keyword+'%')) if(field == 'requestType'): - filtercondition.append(FOIRawRequest.findfield('requestTypeRequestType').ilike('%'+_keyword+'%')) + onekeywordfiltercondition.append(FOIRawRequest.findfield('requestTypeRequestType').ilike('%'+_keyword+'%')) else: - filtercondition.append(FOIRawRequest.isiaorestricted == True) + onekeywordfiltercondition.append(FOIRawRequest.isiaorestricted == True) + + filtercondition.append(or_(*onekeywordfiltercondition)) - return or_(*filtercondition) + return and_(*filtercondition) @classmethod