Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Purge ComputedField fields from AnalysisRequest related with Profiles #2213

Merged
merged 8 commits into from
Dec 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Changelog
2.4.0 (unreleased)
------------------

- #2213 Purge ComputedField fields from AnalysisRequest related with Profiles
- #2212 Improve performance of legacy AT `UIDReferenceField`'s getter
- #2211 Remove `Profile` field (stale) from AnalysisRequest
- #2207 Support for file upload on analysis (pre) conditions
Expand Down
35 changes: 6 additions & 29 deletions src/bika/lims/content/analysisrequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1098,15 +1098,6 @@
),
),

ComputedField(
'ProfilesUID',
expression="[p.UID() for p in here.getProfiles()] " \
"if here.getProfiles() else []",
widget=ComputedWidget(
visible=False,
),
),

ComputedField(
'Invoiced',
expression='here.getInvoice() and True or False',
Expand Down Expand Up @@ -1188,24 +1179,6 @@
"if here.getStorageLocation() else ''",
widget=ComputedWidget(visible=False),
),
ComputedField(
'ProfilesURL',
expression="[p.absolute_url_path() for p in here.getProfiles()] " \
"if here.getProfiles() else []",
widget=ComputedWidget(visible=False),
),
ComputedField(
'ProfilesTitle',
expression="[p.Title() for p in here.getProfiles()] " \
"if here.getProfiles() else []",
widget=ComputedWidget(visible=False),
),
ComputedField(
'ProfilesTitleStr',
expression="', '.join([p.Title() for p in here.getProfiles()]) " \
"if here.getProfiles() else ''",
widget=ComputedWidget(visible=False),
),
ComputedField(
'TemplateUID',
expression="here.getTemplate().UID() if here.getTemplate() else ''",
Expand Down Expand Up @@ -1509,8 +1482,12 @@ def getClient(self):
return self.aq_parent.getClient()
return None

def getProfilesTitle(self):
return [profile.Title() for profile in self.getProfiles()]
def getProfilesTitleStr(self):
"""Returns a comma-separated string withg the titles of the profiles
assigned to this Sample. Used to populate a metadata field
"""
profiles = [profile.Title() for profile in self.getProfiles()]
return ", ".join(profiles)

def getAnalysisService(self):
proxies = self.getAnalyses(full_objects=False)
Expand Down
3 changes: 1 addition & 2 deletions src/senaite/core/browser/samples/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,7 @@ def __init__(self, context, request):
"toggle": False}),
("getProfilesTitle", {
"title": _("Profile"),
"sortable": True,
"index": "getProfilesTitle",
"sortable": False,
"toggle": False}),
("getAnalysesNum", {
"title": _("Number of Analyses"),
Expand Down
3 changes: 0 additions & 3 deletions src/senaite/core/catalog/sample_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,7 @@
"getPhysicalPath",
"getPrinted",
"getPrioritySortkey",
"getProfilesTitle",
"getProfilesTitleStr",
"getProfilesUID",
"getProfilesURL",
"getProgress",
"getProvince",
"getRawParentAnalysisRequest",
Expand Down
2 changes: 1 addition & 1 deletion src/senaite/core/profiles/default/metadata.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<metadata>
<version>2405</version>
<version>2406</version>
<dependencies>
<dependency>profile-Products.ATContentTypes:base</dependency>
<dependency>profile-Products.CMFEditions:CMFEditions</dependency>
Expand Down
40 changes: 40 additions & 0 deletions src/senaite/core/upgrade/v02_04_000.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from bika.lims.interfaces import IRetracted
from senaite.core import logger
from senaite.core.catalog import ANALYSIS_CATALOG
from senaite.core.catalog import SAMPLE_CATALOG
from senaite.core.config import PROJECTNAME as product
from senaite.core.upgrade import upgradestep
from senaite.core.upgrade.utils import UpgradeUtils
Expand Down Expand Up @@ -188,3 +189,42 @@ def fix_traceback_retract_dl(tool):
obj._p_deactivate()

logger.info("Migrate LDL, UDL and result fields to string [DONE]")


def purge_computed_fields_profile(self):
"""Cleanup of computed fields related with Profiles field and removal of
indexes and columns that are no longer required
"""
logger.info("Purge ComputedField from Sample related with Profiles ...")
indexes_to_remove = [
]
columns_to_remove = [
("getProfilesUID", SAMPLE_CATALOG),
("getProfilesURL", SAMPLE_CATALOG),
("getProfilesTitle", SAMPLE_CATALOG),
]

# Purge the catalogs
purge_catalogs(indexes_to_remove, columns_to_remove)

logger.info("Purge ComputedField from Sample related with Profiles [DONE]")


def purge_catalogs(indexes_to_remove, columns_to_remove):
"""Removes the indexes and columns from catalogs
"""
# remove indexes
for index_name, catalog_id in indexes_to_remove:
cat = api.get_tool(catalog_id)
if index_name in cat.indexes():
logger.info("Removing '{}' index from '{}'".format(
index_name, catalog_id))
cat.delIndex(index_name)

# remove columns
for col_name, catalog_id in columns_to_remove:
cat = api.get_tool(catalog_id)
if col_name in cat.schema():
logger.info("Removing '{}' column from '{}'".format(
col_name, catalog_id))
cat.delColumn(col_name)
10 changes: 10 additions & 0 deletions src/senaite/core/upgrade/v02_04_000.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,14 @@
handler="senaite.core.upgrade.v02_04_000.fix_traceback_retract_dl"
profile="senaite.core:default"/>

<!-- Purge ComputedField from AnalysisRequest related with Profiles
https://github.com/senaite/senaite.core/pull/2213 -->
<genericsetup:upgradeStep
title="SENAITE CORE 2.4.0: Purge ComputedField from AnalysisRequest related with Profiles"
description="Purge ComputedField from AnalysisRequest related with Profiles"
source="2405"
destination="2406"
handler="senaite.core.upgrade.v02_04_000.purge_computed_fields_profile"
profile="senaite.core:default"/>

</configure>