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 Requests w/o submitted results always appear as not late #1051

Merged
merged 6 commits into from Oct 8, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.rst
Expand Up @@ -6,6 +6,7 @@ Changelog

**Added**

- #1051 Show the Due date in late's image tooltip in Analysis Requests listings
- #1048 Allow to set the pagesize in listings and show total number of results
- #1031 Added profiling and timing decorators
- #1001 Option to show Interim fields on results reports
Expand Down Expand Up @@ -35,6 +36,7 @@ Changelog

**Fixed**

- #1051 Analyses Requests w/o submitted results always appear as not late
- #1047 Fix translate utility function
- #1049 Secondary Analysis Request changes received date of Sample
- #1041 Reject transition is available to Client once AR/Sample is received
Expand Down
10 changes: 7 additions & 3 deletions bika/lims/browser/analysisrequest/analysisrequests.py
Expand Up @@ -751,9 +751,13 @@ def folderitem(self, obj, item, index):
if states_dict.get('review_state', '') == 'invalid':
after_icons += get_image("delete.png",
title=t(_("Results have been withdrawn")))
if obj.getLate:
after_icons += get_image("late.png",
title=t(_("Late Analyses")))

due_date = obj.getDueDate
if due_date and due_date < (obj.getDatePublished or DateTime()):
due_date_str = self.ulocalized_time(due_date)
img_title = "{}: {}".format(t(_("Late Analyses")), due_date_str)
after_icons += get_image("late.png", title=img_title)

if obj.getSamplingDate and obj.getSamplingDate > DateTime():
after_icons += get_image("calendar.png",
title=t(_("Future dated sample")))
Expand Down
4 changes: 2 additions & 2 deletions bika/lims/catalog/analysisrequest_catalog.py
Expand Up @@ -28,6 +28,7 @@
'getDateReceived': 'DateIndex',
'getDateVerified': 'DateIndex',
'getDatePublished': 'DateIndex',
'getDueDate': 'DateIndex',
'getSampler': 'FieldIndex',
'getReceivedBy': 'FieldIndex',
'getDepartmentUIDs': 'KeywordIndex',
Expand Down Expand Up @@ -97,8 +98,7 @@
'getPrinted',
'getSamplingDeviationTitle',
'getPrioritySortkey',
# TODO: This should be updated through a clock
'getLate',
'getDueDate',
'getInvoiceExclude',
'getHazardous',
'getSamplingWorkflowEnabled',
Expand Down
6 changes: 6 additions & 0 deletions bika/lims/content/analysisrequest.py
Expand Up @@ -1982,6 +1982,12 @@ def getManagers(self):
manager_list.append(manager)
return manager_list

def getDueDate(self):
"""Returns the earliest due date of the analyses this Analysis Request
contains."""
due_dates = map(lambda an: an.getDueDate, self.getAnalyses())
return due_dates and min(due_dates) or None

security.declareProtected(View, 'getLate')

def getLate(self):
Expand Down
29 changes: 29 additions & 0 deletions bika/lims/upgrade/v01_02_009.py
Expand Up @@ -63,6 +63,9 @@ def upgrade(tool):
# Update workflow states and permissions for AR/Sample rejection
update_rejection_permissions(portal)

# Remove getLate and add getDueDate metadata in ar_catalog
update_analaysisrequests_due_date(portal)

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

Expand Down Expand Up @@ -309,3 +312,29 @@ def update_rolemappings_for(brains, workflow_id):
logger.info("Updating role mappings: {0}/{1}"
.format(num, total))
logger.info("{} objects updated".format(num))


def update_analaysisrequests_due_date(portal):
"""Removes the metadata getLate from ar-catalog and adds the column
getDueDate"""
logger.info("Updating getLate -> getDueDate metadata columns ...")
catalog = api.get_tool(CATALOG_ANALYSIS_REQUEST_LISTING)
if "getLate" in catalog.schema():
catalog.delColumn("getLate")

if "getDueDate" in catalog.schema():
logger.info("getDueDate already in catalog [SKIP]")
return

logger.info("Adding Column 'getDueDate' to catalog '{}' ..."
.format(catalog.id))
catalog.addColumn("getDueDate")
catalog.addIndex("getDueDate", "DateIndex")
catalog.manage_reindexIndex("getDueDate")

query = dict(portal_type="AnalysisRequest")
for analysis_request in api.search(query, CATALOG_ANALYSIS_REQUEST_LISTING):
analysis_request = api.get_object(analysis_request)
analysis_request.reindexObject(idxs=['getDueDate'])

logger.info("Updating getLate -> getDueDate metadata columns [DONE]")