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

Cleanup Batch content type and remove getBatchUID index and column #2210

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
6cbadbd
Migrate CCContacts
xispa Dec 29, 2022
98d2d67
Merge branch '2.x' of github.com:senaite/senaite.core into migrate-re…
xispa Dec 29, 2022
999b2c3
Migrate Client
xispa Dec 29, 2022
e1f293a
Migrate PrimaryAnalysisRequest
xispa Dec 29, 2022
4aa062f
Migrate Batch
xispa Dec 29, 2022
72755bf
Optimize functions for the retrieval of Samples from a Batch
xispa Dec 29, 2022
6669c57
Make getProgress to rely on Sample brains instead of objects
xispa Dec 29, 2022
1753636
Remove unnecessary functions
xispa Dec 29, 2022
79b79e1
Remove unnecessary indexes and columns
xispa Dec 29, 2022
c4282cf
Changelog
xispa Dec 29, 2022
d003378
F401 'bika.lims.api' imported but unused
xispa Dec 29, 2022
9c2bd5a
Changelog
xispa Dec 29, 2022
c730ef5
Fix tests
xispa Dec 29, 2022
e7cea62
Migrate SubGroup
xispa Dec 29, 2022
3aac886
Migrate Template
xispa Dec 29, 2022
84aa459
Be sure no searches with empty UIDs are done
xispa Dec 29, 2022
194758e
Merge branch '2.x' of github.com:senaite/senaite.core into migrate-re…
xispa Dec 29, 2022
d97d625
Migrate Profile
xispa Dec 29, 2022
19da4f3
Merge remote-tracking branch 'origin/migrate-reference-fields' into c…
xispa Dec 29, 2022
1b96c3c
Merge branch '2.x' of github.com:senaite/senaite.core into cleanup-ba…
xispa Dec 30, 2022
867eb53
Duplicate changelog line
xispa Dec 30, 2022
0031caf
Remove unnecessary check
xispa Dec 30, 2022
9b625b7
Do not remove functions but label as deprecated
xispa Dec 30, 2022
06d922a
Restore stale functions and label them as deprecated
xispa Dec 30, 2022
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)
------------------

- #2210 Cleanup Batch content type and remove `getBatchUID` index and column
- #2209 Migrate AnalysisRequest's ReferenceField fields to UIDReferenceField
- #2218 Improve performance of legacy AT `UIDReferenceField`'s setter
- #2214 Remove `DefaultContainerType` field (stale) from AnalysisRequest
Expand Down
2 changes: 1 addition & 1 deletion src/bika/lims/adapters/widgetvisibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def isVisible(self, field, mode="view", default="visible"):
if mode == "edit":
# This batch does not have a client assigned, but allow the client
# field to be editable only if does not contain any sample
if self.context.getAnalysisRequestsBrains():
if self.context.getRawAnalysisRequests():
return "invisible"

return default
Expand Down
4 changes: 2 additions & 2 deletions src/bika/lims/browser/batch/analysisrequests.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
# Copyright 2018-2021 by it's authors.
# Some rights reserved, see README and LICENSE.

from bika.lims import api
from bika.lims.browser.analysisrequest import AnalysisRequestsView as BaseView


class AnalysisRequestsView(BaseView):

def __init__(self, context, request):
super(AnalysisRequestsView, self).__init__(context, request)
sample_uids = self.context.getRawAnalysisRequests()
self.contentFilter = {"portal_type": "AnalysisRequest",
"getBatchUID": api.get_uid(self.context),
"UID": sample_uids,
"sort_on": "created",
"sort_order": "reverse"}
11 changes: 7 additions & 4 deletions src/bika/lims/content/analysisrequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1515,11 +1515,14 @@ def getBatch(self):
else:
return self.Schema()['Batch'].get(self)

@security.public
@deprecated("Use getRawBatch instead. Will be removed in SENAITE 3.0")
def getBatchUID(self):
batch = self.getBatch()
if batch:
return batch.UID()
"""Returns the UID of the Batch assigned to this sample

Backwards compatibility for removed getBatchUID indexes/columns:
https://github.com/senaite/senaite.core/pull/2210
"""
return self.getRawBatch()

@security.public
def setBatch(self, value=None):
Expand Down
32 changes: 24 additions & 8 deletions src/bika/lims/content/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from bika.lims import bikaMessageFactory as _
from bika.lims import deprecated
from bika.lims.browser.fields.remarksfield import RemarksField
from bika.lims.browser.fields.uidreferencefield import get_backreferences
from bika.lims.browser.widgets import DateTimeWidget
from bika.lims.browser.widgets import ReferenceWidget
from bika.lims.browser.widgets import RemarksWidget
Expand Down Expand Up @@ -168,12 +169,15 @@ def getClient(self):
return client
return None

@deprecated("Will be removed in SENAITE 3.0")
def getContactTitle(self):
return ""

@deprecated("Will be removed in SENAITE 3.0")
def getProfilesTitle(self):
return ""

@deprecated("Will be removed in SENAITE 3.0")
def getAnalysisService(self):
analyses = set()
for ar in self.getAnalysisRequests():
Expand All @@ -186,6 +190,7 @@ def getAnalysisService(self):
value.append(val)
return list(value)

@deprecated("Will be removed in SENAITE 3.0")
def getAnalysts(self):
analyses = []
for ar in self.getAnalysisRequests():
Expand Down Expand Up @@ -220,21 +225,32 @@ def BatchLabelVocabulary(self):
ret.append((p.UID, p.Title))
return DisplayList(ret)

@deprecated("Use getAnalysisRequests(full_objects=False, **kwargs) instead. Will be removed in SENAITE 3.0")
def getAnalysisRequestsBrains(self, **kwargs):
"""Return all the Analysis Requests brains linked to the Batch
kargs are passed directly to the catalog.

Backwards compatibility for removed getBatchUID indexes/columns:
https://github.com/senaite/senaite.core/pull/2210
"""
kwargs.update({"full_objects": False})
return self.getAnalysisRequests(**kwargs)

def getRawAnalysisRequests(self):
"""Returns the UIDs of all AnalysisRequests assigned to this Batch
"""
kwargs['getBatchUID'] = self.UID()
catalog = getToolByName(self, SAMPLE_CATALOG)
brains = catalog(kwargs)
return brains
return get_backreferences(self, "AnalysisRequestBatch")

def getAnalysisRequests(self, **kwargs):
"""Return all the Analysis Requests objects linked to the Batch kargs
are passed directly to the catalog.
"""
brains = self.getAnalysisRequestsBrains(**kwargs)
return [b.getObject() for b in brains]
full_objects = kwargs.pop("full_objects", True)
kwargs.update({"UID": self.getRawAnalysisRequests()})
brains = api.search(kwargs, SAMPLE_CATALOG)
if not full_objects:
return brains
return [api.get_object(brain) for brain in brains]

def isOpen(self):
"""Returns true if the Batch is in 'open' state
Expand All @@ -251,10 +267,10 @@ def getProgress(self):
"""Returns the progress in percent of all samples
"""
total_progress = 0
samples = self.getAnalysisRequests()
samples = self.getAnalysisRequests(full_objects=False)
total = len(samples)
if total > 0:
sample_progresses = map(lambda s: s.getProgress(), samples)
sample_progresses = map(lambda s: s.getProgress, samples)
total_progress = sum(sample_progresses) / total
return total_progress

Expand Down
2 changes: 0 additions & 2 deletions src/senaite/core/catalog/sample_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
INDEXES = BASE_INDEXES + [
# id, indexed attribute, type
("assigned_state", "", "FieldIndex"),
("getBatchUID", "", "FieldIndex"),
("getClientID", "", "FieldIndex"),
("getClientSampleID", "", "FieldIndex"),
("getClientTitle", "", "FieldIndex"),
Expand Down Expand Up @@ -43,7 +42,6 @@
"assigned_state",
"getAnalysesNum",
"getBatchID",
"getBatchUID",
"getBatchURL",
"getClientID",
"getClientOrderNumber",
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>2408</version>
<version>2409</version>
<dependencies>
<dependency>profile-Products.ATContentTypes:base</dependency>
<dependency>profile-Products.CMFEditions:CMFEditions</dependency>
Expand Down
18 changes: 18 additions & 0 deletions src/senaite/core/upgrade/v02_04_000.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,3 +323,21 @@ def migrate_reference_fields(obj, field_names):

# Remove this relationship from reference catalog
ref_tool.deleteReferences(obj, relationship=ref_id)


def cleanup_batch_type(tool):
"""Cleanup of functions of Batch type, that entails the removal of some
catalog indexes and metadata
"""
logger.info("Cleanup batch content type ...")
indexes_to_remove = [
("getBatchUID", SAMPLE_CATALOG),
]
columns_to_remove = [
("getBatchUID", SAMPLE_CATALOG),
]

# Purge the catalogs
purge_catalogs(indexes_to_remove, columns_to_remove)

logger.info("Cleanup batch content type [DONE]")
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 @@ -83,4 +83,14 @@
handler="senaite.core.upgrade.v02_04_000.migrate_analysisrequest_referencefields"
profile="senaite.core:default"/>

<!-- Cleanup Batch content type
https://github.com/senaite/senaite.core/pull/2210 -->
<genericsetup:upgradeStep
title="SENAITE CORE 2.4.0: Cleanup Batch content type"
description="Optimizes functions from Batch type and removes indexes and columns that are no longer required"
source="2408"
destination="2409"
handler="senaite.core.upgrade.v02_04_000.cleanup_batch_type"
profile="senaite.core:default"/>

</configure>