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

Analyses sorted by priority in Add Analyses view and preserve AR order when adding into Worksheet #338

Merged
merged 3 commits into from
Oct 31, 2017
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
2 changes: 2 additions & 0 deletions bika/lims/browser/worksheet/views/add_analyses.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ def __init__(self, context, request):
self.context_actions = {}
# initial review state for first form display of the worksheet
# add_analyses search view - first batch of analyses, latest first.
self.sort_on = 'Priority'
self.contentFilter = {'portal_type': 'Analysis',
'review_state':'sample_received',
'worksheetanalysis_review_state':'unassigned',
'sort_on': 'getPrioritySortkey',
'cancellation_state':'active'}
self.base_url = self.context.absolute_url()
self.view_url = self.base_url + "/add_analyses"
Expand Down
23 changes: 13 additions & 10 deletions bika/lims/browser/worksheet/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
from AccessControl import getSecurityManager
from bika.lims import bikaMessageFactory as _
from bika.lims import PMF
from bika.lims.api import get_tool
from bika.lims.browser.bika_listing import WorkflowAction
from bika.lims.browser.referenceanalysis import AnalysesRetractedListReport
from bika.lims.catalog.analysis_catalog import CATALOG_ANALYSIS_LISTING
from bika.lims.permissions import EditResults, EditWorksheet, ManageWorksheets
from bika.lims.subscribers import doActionFor
from bika.lims.subscribers import skip
Expand Down Expand Up @@ -105,16 +107,17 @@ def __call__(self):
self.request.response.redirect(self.context.absolute_url())
return

selected_analyses = WorkflowAction._get_selected_items(self)
selected_analysis_uids = selected_analyses.keys()
if selected_analyses:
for uid in selected_analysis_uids:
analysis = rc.lookupObject(uid)
# Double-check the state first
if (workflow.getInfoFor(analysis, 'worksheetanalysis_review_state') == 'unassigned'
and workflow.getInfoFor(analysis, 'review_state') == 'sample_received'
and workflow.getInfoFor(analysis, 'cancellation_state') == 'active'):
self.context.addAnalysis(analysis)
analysis_uids = form.get("uids", [])
if analysis_uids:
# We retrieve the analyses from the database sorted by AR ID
# ascending, so the positions of the ARs inside the WS are
# consistent with the order of the ARs
catalog = get_tool(CATALOG_ANALYSIS_LISTING)
brains = catalog({'UID': analysis_uids,
'sort_on': 'getRequestID'})
for brain in brains:
analysis = brain.getObject()
self.context.addAnalysis(analysis)

self.destination_url = self.context.absolute_url()
self.request.response.redirect(self.destination_url)
Expand Down
16 changes: 12 additions & 4 deletions bika/lims/content/abstractroutineanalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from bika.lims.browser.fields import HistoryAwareReferenceField, \
InterimFieldsField, UIDReferenceField
from bika.lims.browser.widgets import DecimalWidget, RecordsWidget
from bika.lims.catalog.indexers.baseanalysis import sortable_title
from bika.lims.content.abstractanalysis import AbstractAnalysis
from bika.lims.content.abstractanalysis import schema
from bika.lims.content.reflexrule import doReflexRuleAction
Expand Down Expand Up @@ -477,13 +478,20 @@ def getDependencies(self):
@security.public
def getPrioritySortkey(self):
"""
Returns the key that will be used to sort the current Analysis
Delegates to getPrioritySortKey function from the AnalysisRequest
Returns the key that will be used to sort the current Analysis, from
most prioritary to less prioritary.
:return: string used for sorting
"""
analysis_request = self.getRequest()
if analysis_request:
return analysis_request.getPrioritySortkey()
if analysis_request is None:
return None
ar_sort_key = analysis_request.getPrioritySortkey()
ar_id = analysis_request.getId().lower()
title = sortable_title(self)
if callable(title):
title = title()
return '{}.{}.{}'.format(ar_sort_key, ar_id, title)


@security.public
def getHidden(self):
Expand Down
7 changes: 7 additions & 0 deletions bika/lims/upgrade/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,11 @@
handler="bika.lims.upgrade.v01_01_000.upgrade"
profile="bika.lims:default"/>

<genericsetup:upgradeStep
title="Upgrade to Bika LIMS Evo 1.1.1"
source="1.1.0"
destination="1.1.1"
handler="bika.lims.upgrade.v01_01_001.upgrade"
profile="bika.lims:default"/>

</configure>
10 changes: 10 additions & 0 deletions bika/lims/upgrade/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,16 @@ def addColumn(self, catalog, column):
self.refreshcatalog.append(cat.id)
transaction.commit()

def reindexIndex(self, catalog, index):
cat = self._getCatalog(catalog)
if index not in cat.indexes():
logger.warn("Index {} not found in {}".format(index, catalog))
return
indexes = self.reindexcatalog.get(cat.id, [])
if index not in indexes:
indexes.append(index)
self.reindexcatalog[cat.id] = indexes

def refreshCatalogs(self):
"""
It reindexes the modified catalogs but, while cleanAndRebuildCatalogs
Expand Down
37 changes: 37 additions & 0 deletions bika/lims/upgrade/v01_01_001.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from Acquisition import aq_inner
from Acquisition import aq_parent
from bika.lims import logger
from bika.lims.catalog import CATALOG_ANALYSIS_LISTING
from bika.lims.config import PROJECTNAME as product
from bika.lims.upgrade import upgradestep
from bika.lims.upgrade.utils import UpgradeUtils

version = '1.1.1'
profile = 'profile-{0}:default'.format(product)


@upgradestep(product, version)
def upgrade(tool):
portal = aq_parent(aq_inner(tool))
setup = portal.portal_setup
ut = UpgradeUtils(portal)
ver_from = ut.getInstalledVersion(product)

if ut.isOlderVersion(product, version):
logger.info("Skipping upgrade of {0}: {1} > {2}".format(
product, ver_from, version))
# The currently installed version is more recent than the target
# version of this upgradestep
return True

logger.info("Upgrading {0}: {1} -> {2}".format(product, ver_from, version))

# Reindex getPrioritySortkey index. The priority sort key from analyses
# takes also into account analyses have to be sorted by their sortkey, so
# two analyses with same priority, same AR, but different sort key values
# don't get mixed.
ut.reindexIndex(CATALOG_ANALYSIS_LISTING, 'getPrioritySortkey')
ut.refreshCatalogs()

logger.info("{0} upgraded to version {1}".format(product, version))
return True