Skip to content

Commit

Permalink
Merge pull request #4855 from bcgov/dev-rook-ST-4783
Browse files Browse the repository at this point in the history
Changes to fix the duplicates in advanced search.
  • Loading branch information
milosdes authored Dec 11, 2023
2 parents d98b520 + 41eaaec commit f65a8ba
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
26 changes: 14 additions & 12 deletions request-management-api/request_api/models/FOIMinistryRequests.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ def getrequestssubquery(cls, groups, filterfields, keyword, additionalfilter, us
ministry_restricted_requests.isrestricted.label('isministryrestricted'),
SubjectCode.name.label('subjectcode'),
FOIMinistryRequest.isoipcreview.label('isoipcreview'),
FOIRequestOIPC.oipcno.label('oipc_number')
literal(None).label('oipc_number'),
]

basequery = _session.query(
Expand Down Expand Up @@ -564,11 +564,9 @@ def getrequestssubquery(cls, groups, filterfields, keyword, additionalfilter, us
SubjectCode,
SubjectCode.subjectcodeid == FOIMinistryRequestSubjectCode.subjectcodeid,
isouter=True
).join(
FOIRequestOIPC,
and_(FOIRequestOIPC.foiministryrequest_id == FOIMinistryRequest.foiministryrequestid, FOIRequestOIPC.foiministryrequestversion_id == FOIMinistryRequest.version),
isouter=True
).filter(or_(FOIMinistryRequest.requeststatusid != 3, and_(FOIMinistryRequest.isoipcreview == True, FOIMinistryRequest.requeststatusid == 3)))



if(additionalfilter == 'watchingRequests'):
#watchby
Expand Down Expand Up @@ -675,8 +673,7 @@ def findfield(cls, x, iaoassignee, ministryassignee):
'requestPageCount': FOIMinistryRequest.requestpagecount,
'closedate': FOIMinistryRequest.closedate,
'subjectcode': SubjectCode.name,
'isoipcreview': FOIMinistryRequest.isoipcreview,
'oipc_number': FOIRequestOIPC.oipcno
'isoipcreview': FOIMinistryRequest.isoipcreview
}.get(x, FOIMinistryRequest.axisrequestid)

@classmethod
Expand Down Expand Up @@ -1047,7 +1044,7 @@ def getbasequery(cls, iaoassignee, ministryassignee, userid=None, requestby='IAO
ministry_restricted_requests.isrestricted.label('isministryrestricted'),
SubjectCode.name.label('subjectcode'),
FOIMinistryRequest.isoipcreview.label('isoipcreview'),
FOIRequestOIPC.oipcno.label('oipc_number')
literal(None).label('oipc_number')
]

basequery = _session.query(
Expand Down Expand Up @@ -1118,11 +1115,8 @@ def getbasequery(cls, iaoassignee, ministryassignee, userid=None, requestby='IAO
SubjectCode,
SubjectCode.subjectcodeid == FOIMinistryRequestSubjectCode.subjectcodeid,
isouter=True
).join(
FOIRequestOIPC,
and_(FOIRequestOIPC.foiministryrequest_id == FOIMinistryRequest.foiministryrequestid, FOIRequestOIPC.foiministryrequestversion_id == FOIMinistryRequest.version),
isouter=True
)


if(isiaorestrictedfilemanager == True or isministryrestrictedfilemanager == True):
dbquery = basequery.filter(ministryfilter)
Expand Down Expand Up @@ -1319,6 +1313,14 @@ def getfilterforsearch(cls, params, iaoassignee, ministryassignee):
searchcondition1.append(FOIMinistryRequest.findfield('assignedministrypersonFirstName', iaoassignee, ministryassignee).ilike('%'+keyword+'%'))
searchcondition2.append(FOIMinistryRequest.findfield('assignedministrypersonLastName', iaoassignee, ministryassignee).ilike('%'+keyword+'%'))
return or_(and_(*searchcondition1), and_(*searchcondition2))
elif(params['search'] == 'oipc_number'):
searchcondition1 = []
searchcondition2 = []
for keyword in params['keywords']:
oipccondition = FOIRequestOIPC.getrequestidsbyoipcno(keyword)
searchcondition1.append(oipccondition.c.foiministryrequest_id == FOIMinistryRequest.foiministryrequestid)
searchcondition2.append(oipccondition.c.foiministryrequestversion_id == FOIMinistryRequest.version)
return and_(and_(*searchcondition1), and_(*searchcondition2))
else:
searchcondition = []
for keyword in params['keywords']:
Expand Down
8 changes: 8 additions & 0 deletions request-management-api/request_api/models/FOIRequestOIPC.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ def getoipc(cls,ministryrequestid,ministryrequestversion):
divisioninfos = oipc_schema.dump(_oipclist)
return divisioninfos


@classmethod
def getrequestidsbyoipcno(cls, oipcno):
return db.session.query(
FOIRequestOIPC.foiministryrequest_id,
FOIRequestOIPC.foiministryrequestversion_id
).filter(FOIRequestOIPC.oipcno.ilike('%'+oipcno+'%')).group_by(FOIRequestOIPC.foiministryrequest_id, FOIRequestOIPC.foiministryrequestversion_id).subquery()


class FOIRequestOIPCSchema(ma.Schema):
class Meta:
Expand Down

0 comments on commit f65a8ba

Please sign in to comment.