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

Remove DefaultContainerType field (stale) from AnalysisRequest #2214

Merged
merged 2 commits into from
Dec 30, 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)
------------------

- #2214 Remove `DefaultContainerType` field (stale) from AnalysisRequest
- #2215 Fix ParseError when search term contains parenthesis in widget search
- #2213 Purge ComputedField fields from AnalysisRequest related with Profiles
- #2212 Improve performance of legacy AT `UIDReferenceField`'s getter
Expand Down
23 changes: 0 additions & 23 deletions src/bika/lims/content/analysisrequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -884,29 +884,6 @@
),
),

# TODO Remove - Is this still necessary?
ReferenceField(
'DefaultContainerType',
allowed_types=('ContainerType',),
relationship='AnalysisRequestContainerType',
referenceClass=HoldingReference,
mode="rw",
read_permission=View,
write_permission=ModifyPortalContent,
widget=ReferenceWidget(
label=_("Default Container"),
description=_("Default container for new sample partitions"),
size=20,
render_own_label=True,
visible=False,
catalog_name='senaite_catalog_setup',
base_query={"is_active": True,
"sort_on": "sortable_title",
"sort_order": "ascending"},
showOn=True,
),
),

BooleanField(
'Composite',
default=False,
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>2406</version>
<version>2407</version>
<dependencies>
<dependency>profile-Products.ATContentTypes:base</dependency>
<dependency>profile-Products.CMFEditions:CMFEditions</dependency>
Expand Down
25 changes: 25 additions & 0 deletions src/senaite/core/upgrade/v02_04_000.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from bika.lims import UDL
from bika.lims.interfaces import IRejected
from bika.lims.interfaces import IRetracted
from Products.Archetypes.config import REFERENCE_CATALOG
from senaite.core import logger
from senaite.core.catalog import ANALYSIS_CATALOG
from senaite.core.catalog import SAMPLE_CATALOG
Expand Down Expand Up @@ -228,3 +229,27 @@ def purge_catalogs(indexes_to_remove, columns_to_remove):
logger.info("Removing '{}' column from '{}'".format(
col_name, catalog_id))
cat.delColumn(col_name)


def remove_default_container_type(tool):
"""Removes references from the old "DefaultContainerType" field
"""
ref_id = "AnalysisRequestContainerType"
ref_tool = api.get_tool(REFERENCE_CATALOG)
cat = api.get_tool(SAMPLE_CATALOG)
brains = cat(portal_type="AnalysisRequest")
total = len(brains)
for num, sample in enumerate(brains):
if num and num % 100 == 0:
logger.info("Processed samples: {}/{}".format(num, total))

if num and num % 1000 == 0:
# reduce memory size of the transaction
transaction.savepoint()

# Remove AnalysisRequestContainerType references
obj = api.get_object(sample)
ref_tool.deleteReferences(obj, relationship=ref_id)

# Flush the object from memory
obj._p_deactivate()
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 @@ -63,4 +63,14 @@
handler="senaite.core.upgrade.v02_04_000.purge_computed_fields_profile"
profile="senaite.core:default"/>

<!-- Remove `DefaultContainerType` field (stale) from AnalysisRequest
https://github.com/senaite/senaite.core/pull/2214 -->
<genericsetup:upgradeStep
title="SENAITE CORE 2.4.0: Remove `DefaultContainerType` field (stale) from AnalysisRequest"
description="Remove `DefaultContainerType` field (stale) from AnalysisRequest"
source="2406"
destination="2407"
handler="senaite.core.upgrade.v02_04_000.remove_default_container_type"
profile="senaite.core:default"/>

</configure>