diff --git a/CHANGES.rst b/CHANGES.rst index 8925b6f1dc..1e4b18809a 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -32,7 +32,7 @@ Changelog - #1466 Support for "readonly" and "hidden" visibility modes in ReferenceWidget **Changed** - +- #1555 List all multi-reports for samples, where the current sample is contained - #1543 Sort navigation child-nodes alphabetically - #1539 Avoid unnecessary Price recalculations in Sample Add Form - #1532 Updated jQuery Barcode to version 2.2.0 diff --git a/bika/lims/browser/analysisrequest/published_results.py b/bika/lims/browser/analysisrequest/published_results.py index 4584be9861..a9e7ca7075 100644 --- a/bika/lims/browser/analysisrequest/published_results.py +++ b/bika/lims/browser/analysisrequest/published_results.py @@ -18,135 +18,48 @@ # Copyright 2018-2020 by it's authors. # Some rights reserved, see README and LICENSE. -from Products.CMFCore.utils import getToolByName from bika.lims import api -from bika.lims import bikaMessageFactory as _ -from bika.lims.browser.bika_listing import BikaListingView -from bika.lims.utils import t +from bika.lims.browser.publish.reports_listing import ReportsListingView -class AnalysisRequestPublishedResults(BikaListingView): +class AnalysisRequestPublishedResults(ReportsListingView): """View of published results - - Prints the list of pdf files with each publication dates, the user - responsible of that publication, the emails of the addressees (and/or) - client contact names with the publication mode used (pdf, email, etc.) """ - # I took IViewView away, because transitions selected in the edit-bar - # cause errors due to wrong context, when invoked from this view, and I - # don't know why. - # implements(IViewView) def __init__(self, context, request): super(AnalysisRequestPublishedResults, self).__init__(context, request) - self.catalog = "portal_catalog" + + # get the client for the catalog query + client = context.getClient() + client_path = api.get_path(client) + + # get the UID of the current context (sample) + sample_uid = api.get_uid(context) + self.contentFilter = { - 'portal_type': 'ARReport', - 'path': { - 'query': api.get_path(self.context), - 'depth': 1, + "portal_type": "ARReport", + "path": { + "query": client_path, + "depth": 2, }, - 'sort_order': 'reverse' + # search all reports, where the current sample UID is included + "sample_uid": [sample_uid], + "sort_on": "created", + "sort_order": "descending", } - self.context_actions = {} - self.show_select_column = True - self.show_workflow_action_buttons = False - self.form_id = 'published_results' - self.icon = self.portal_url + "/++resource++bika.lims.images/report_big.png" - self.title = self.context.translate(_("Published results")) - self.columns = { - 'Title': {'title': _('File')}, - 'FileSize': {'title': _('Size')}, - 'Date': {'title': _('Published Date')}, - 'PublishedBy': {'title': _('Published By')}, - 'DatePrinted': {'title': _('Printed Date')}, - 'Recipients': {'title': _('Recipients')}, - } + # disable the searchbox in this listing + self.show_search = False + + # only allow the email transition at this level self.review_states = [ - {'id': 'default', - 'title': 'All', - 'contentFilter': {}, - 'columns': ['Title', - 'FileSize', - 'Date', - 'PublishedBy', - 'DatePrinted', - 'Recipients']}, + { + "id": "default", + "title": "All", + "contentFilter": {}, + "columns": self.columns.keys(), + "custom_transitions": [ + self.send_email_transition, + ] + }, ] - - def __call__(self): - # Printing workflow enabled? - # If not, remove the Column - self.printwfenabled = self.context.bika_setup.getPrintingWorkflowEnabled() - printed_colname = 'DatePrinted' - if not self.printwfenabled and printed_colname in self.columns: - # Remove "Printed" columns - del self.columns[printed_colname] - tmprvs = [] - for rs in self.review_states: - tmprs = rs - tmprs['columns'] = [c for c in rs.get('columns', []) if - c != printed_colname] - tmprvs.append(tmprs) - self.review_states = tmprvs - - template = BikaListingView.__call__(self) - return template - - def contentsMethod(self, contentFilter): - """ - ARReport objects associated to the current Analysis request. - If the user is not a Manager or LabManager or Client, no items are - displayed. - """ - allowedroles = ['Manager', 'LabManager', 'Client', 'LabClerk'] - pm = getToolByName(self.context, "portal_membership") - member = pm.getAuthenticatedMember() - roles = member.getRoles() - allowed = [a for a in allowedroles if a in roles] - return self.context.objectValues('ARReport') if allowed else [] - - def folderitem(self, obj, item, index): - obj_url = obj.absolute_url() - pdf = obj.getPdf() - filesize = 0 - title = _('Download') - anchor = "%s" % \ - (obj_url, _("Download")) - try: - filesize = pdf.get_size() - filesize = filesize / 1024 if filesize > 0 else 0 - except: - # POSKeyError: 'No blob file' - # Show the record, but not the link - title = _('Not available') - anchor = title - - item['Title'] = title - item['FileSize'] = '%sKb' % filesize - fmt_date = self.ulocalized_time(obj.created(), long_format=1) - item['Date'] = fmt_date - item['PublishedBy'] = self.user_fullname(obj.Creator()) - - if self.printwfenabled: - # The date when the Results Report was printed (if so) - item['DatePrinted'] = '' - fmt_date = obj.getDatePrinted() if hasattr(obj, 'getDatePrinted') else '' - if (fmt_date): - fmt_date = self.ulocalized_time(fmt_date, long_format=1) - item['DatePrinted'] = fmt_date - if obj.getDatePrinted() is None: - item['after']['DatePrinted'] = ("" % - (t(_("Has not been Printed.")))) - - recip = [] - for recipient in obj.getRecipients(): - email = recipient['EmailAddress'] - val = recipient['Fullname'] - if email: - val = "%s" % (email, val) - recip.append(val) - item['replace']['Recipients'] = ', '.join(recip) - item['replace']['Title'] = anchor - return item diff --git a/bika/lims/browser/publish/configure.zcml b/bika/lims/browser/publish/configure.zcml index 4809fcb919..26c6e55958 100644 --- a/bika/lims/browser/publish/configure.zcml +++ b/bika/lims/browser/publish/configure.zcml @@ -22,7 +22,7 @@ layer="bika.lims.interfaces.IBikaLIMS" /> - + + + + + + + diff --git a/bika/lims/setuphandlers.py b/bika/lims/setuphandlers.py index 0b2f95908d..6cc8aa358a 100644 --- a/bika/lims/setuphandlers.py +++ b/bika/lims/setuphandlers.py @@ -192,6 +192,7 @@ ("bika_setup_catalog", "title", "", "FieldIndex"), ("portal_catalog", "Analyst", "", "FieldIndex"), + ("portal_catalog", "sample_uid", "", "KeywordIndex"), ) COLUMNS = ( diff --git a/bika/lims/upgrade/v01_03_003.py b/bika/lims/upgrade/v01_03_003.py index b096016c4b..ab547dcd95 100644 --- a/bika/lims/upgrade/v01_03_003.py +++ b/bika/lims/upgrade/v01_03_003.py @@ -133,6 +133,9 @@ # Default listing_searchable_text index adapter for setup_catalog ("bika_setup_catalog", "category_uid", "KeywordIndex"), + + # Allows to search ARReports where the current Sample UID is included + ("portal_catalog", "sample_uid", "KeywordIndex"), ] INDEXES_TO_REMOVE = [