Commit ddc1fd16 authored by Georgios Dagkakis's avatar Georgios Dagkakis

erp5_core: Make two queries in Base_getRelatedDocumentList

See merge request nexedi/erp5!1373
parents 42c2a915 aba2d822
......@@ -2896,6 +2896,44 @@ return 1
self.assertEqual('TEST-001-en.dummy', document.getStandardFilename(
document_format))
def test_Base_getRelatedDocumentList(self):
"""
Checks Base_getRelatedDocumentList works correctly with both
related (follow_up) Documents and with sub-object Embedded Files
"""
uploaded_file = makeFileUpload('TEST-001-en.dummy')
document_value = self.portal.Base_contribute(
file=uploaded_file,
synchronous_metadata_discovery=True,
portal_type='File'
)
person_value = self.portal.person_module.newContent(portal_type='Person')
getRelatedDocumentList = person_value.Base_getRelatedDocumentList
self.tic()
# No related document
self.assertEqual(len(getRelatedDocumentList()), 0)
document_value.setFollowUpValue(person_value)
self.tic()
# Only related follow_up File
self.assertEqual(
[brain.getObject() for brain in getRelatedDocumentList()],
[document_value]
)
sub_document_value = person_value.newContent(portal_type='Embedded File')
self.tic()
# Related follow_up File and Embedded File
self.assertEqual(
sorted([brain.getObject() for brain in getRelatedDocumentList()]),
sorted([sub_document_value, document_value])
)
document_value.setFollowUpValue(None)
self.tic()
# Only related Embedded File
self.assertEqual(
[brain.getObject() for brain in getRelatedDocumentList()],
[sub_document_value]
)
class TestDocumentWithSecurity(TestDocumentMixin):
username = 'yusei'
......
......@@ -7,12 +7,20 @@ portal_catalog = portal.portal_catalog
if portal_type is None:
portal_type = portal.getPortalDocumentTypeList() + portal.getPortalEmbeddedDocumentTypeList()
document_query = ComplexQuery(
Query(follow_up_uid=context.getUid()),
Query(relative_url='%s/%%' % context.getRelativeUrl().replace('_', r'\_')),
logical_operator='or'
limit = kw.pop('limit', None)
follow_up_related_document_list = portal_catalog(
portal_type=portal_type,
follow_up_uid=context.getUid(),
**kw
)
if follow_up_related_document_list:
document_query = ComplexQuery(
Query(relative_url='%s/%%' % context.getRelativeUrl().replace('_', r'\_')),
Query(uid=[x.getUid() for x in follow_up_related_document_list]),
logical_operator='or'
)
else:
document_query = Query(relative_url='%s/%%' % context.getRelativeUrl().replace('_', r'\_'))
if query is None:
query = document_query
else:
......@@ -25,4 +33,5 @@ else:
return portal_catalog(
portal_type=portal_type,
query=query,
limit=limit,
**kw)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment