Skip to content

Commit 29276a8

Browse files
authored
Fix "No object found for UID: <laboratory_uid>" in report preview (senaite#2146)
* Fix laboratory content type is not properly indexed * Move setup_catalogs_order to setuphandlers
1 parent 11b3967 commit 29276a8

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

CHANGES.rst

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Changelog
55
2.3.0 (unreleased)
66
------------------
77

8+
- #2146 Fix "No object found for UID: <laboratory_uid>" in report preview
89
- #2145 Crop page navigation for DX reference widget
910
- #2143 Fix Traceback when using readonly decorator for objects w/o __name__
1011
- #2140 Allow to enable/disable analysis categories for samples

src/senaite/core/setuphandlers.py

+38
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ def install(context):
226226
setup_other_catalogs(portal)
227227
setup_catalog_mappings(portal)
228228
setup_auditlog_catalog_mappings(portal)
229+
setup_catalogs_order(portal)
229230
setup_content_structure(portal)
230231
add_senaite_setup(portal)
231232
add_dexterity_portal_items(portal)
@@ -480,6 +481,43 @@ def setup_auditlog_catalog_mappings(portal):
480481
AUDITLOG_CATALOG, portal_type))
481482

482483

484+
def setup_catalogs_order(portal):
485+
"""Ensures the order of catalogs portal types are bound to is correct
486+
This is required because senaite.app.supermodel uses the first catalog
487+
the portal type is associated with when retrieving brains
488+
"""
489+
logger.info("Setup Catalogs order ...")
490+
491+
def sort_catalogs(id1, id2):
492+
if id1 == id2:
493+
return 0
494+
495+
# Audit-log catalog is always the last!
496+
if id1 == AUDITLOG_CATALOG:
497+
return 1
498+
if id2 == AUDITLOG_CATALOG:
499+
return -1
500+
501+
# Catalogs sorted, senaite_* always first
502+
senaite = map(lambda cat_id: cat_id.startswith("senaite_"), [id1, id2])
503+
if not all(senaite) and any(senaite):
504+
# Item starting with senaite always gets max priority
505+
if id1.startswith("senaite_"):
506+
return -1
507+
return 1
508+
509+
if id1 < id2:
510+
return -1
511+
return 1
512+
513+
at = api.get_tool("archetype_tool")
514+
for portal_type, catalogs in at.listCatalogs().items():
515+
sorted_catalogs = sorted(catalogs, cmp=sort_catalogs)
516+
at.setCatalogsByType(portal_type, sorted_catalogs)
517+
518+
logger.info("Setup Catalogs order [DONE]")
519+
520+
483521
def remove_default_content(portal):
484522
"""Remove default Plone contents
485523
"""

src/senaite/core/upgrade/v02_03_000.py

+15
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from senaite.core.setuphandlers import add_senaite_setup
3333
from senaite.core.setuphandlers import setup_auditlog_catalog_mappings
3434
from senaite.core.setuphandlers import setup_catalog_mappings
35+
from senaite.core.setuphandlers import setup_catalogs_order
3536
from senaite.core.setuphandlers import setup_core_catalogs
3637
from senaite.core.upgrade import upgradestep
3738
from senaite.core.upgrade.utils import UpgradeUtils
@@ -76,9 +77,13 @@ def upgrade(tool):
7677
# Ensure the catalog mappings for Analyses and Samples is correct
7778
# https://github.com/senaite/senaite.core/pull/2130
7879
setup_catalog_mappings(portal, catalog_mappings=CATALOG_MAPPINGS)
80+
7981
# remap auditlog catalog
8082
setup_auditlog_catalog_mappings(portal)
8183

84+
# ensure the catalogs assigned to types are sorted correctly
85+
setup_catalogs_order(portal)
86+
8287
# Add new setup folder to portal
8388
add_senaite_setup(portal)
8489

@@ -91,6 +96,7 @@ def upgrade(tool):
9196
move_arreports_to_report_catalog(portal)
9297
migrate_analysis_services_fields(portal)
9398
migrate_analyses_fields(portal)
99+
reindex_laboratory(portal)
94100

95101
logger.info("{0} upgraded to version {1}".format(product, version))
96102
return True
@@ -420,3 +426,12 @@ def fixed_point_value_to_string(value, precision):
420426
str_value = template % (sign, front, fra)
421427
# strip off trailing zeros and possible dot
422428
return str_value.rstrip("0").rstrip(".")
429+
430+
431+
def reindex_laboratory(portal):
432+
"""Forces the reindex of laboratory content type
433+
"""
434+
logger.info("Reindexing laboratory content type ...")
435+
setup = api.get_setup()
436+
setup.laboratory.reindexObject()
437+
logger.info("Reindexing laboratory content type [DONE]")

0 commit comments

Comments
 (0)