From 44720b86a010e58fce2be3ef2e72c6cd48fb151d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jordi=20Puiggen=C3=A9?= Date: Thu, 11 Jan 2018 13:02:36 +0100 Subject: [PATCH 1/3] Batches are not listed inside Client --- bika/lims/browser/batchfolder.py | 81 ++++++++++++++++++-------------- 1 file changed, 45 insertions(+), 36 deletions(-) diff --git a/bika/lims/browser/batchfolder.py b/bika/lims/browser/batchfolder.py index 748fb36d46..dcdab3dc04 100644 --- a/bika/lims/browser/batchfolder.py +++ b/bika/lims/browser/batchfolder.py @@ -5,17 +5,17 @@ # Copyright 2018 by it's authors. # Some rights reserved. See LICENSE.rst, CONTRIBUTORS.rst. -from bika.lims.permissions import AddBatch -from bika.lims.browser.bika_listing import BikaListingView -from bika.lims import bikaMessageFactory as _ -from bika.lims.config import ManageInvoices -from bika.lims.utils import t +import json from operator import itemgetter -from plone.app.content.browser.interfaces import IFolderContentsView + +import plone +from bika.lims import api +from bika.lims import bikaMessageFactory as _ from bika.lims.browser import BrowserView +from bika.lims.browser.bika_listing import BikaListingView +from bika.lims.permissions import AddBatch +from plone.app.content.browser.interfaces import IFolderContentsView from zope.interface import implements -import plone -import json class BatchFolderContentsView(BikaListingView): @@ -138,34 +138,43 @@ def isItemAllowed(self, obj): return True return False - def folderitems(self): - items = BikaListingView.folderitems(self) - for x in range(len(items)): - if 'obj' not in items[x]: - continue - obj = items[x]['obj'] - - bid = obj.getBatchID() - items[x]['BatchID'] = bid - items[x]['replace']['BatchID'] = "%s" % (items[x]['url'], 'analysisrequests', bid) - - title = obj.Title() - items[x]['Title'] = title - items[x]['replace']['Title'] = "%s" % (items[x]['url'], 'analysisrequests', title) - - if obj.getClient(): - items[x]['Client'] = obj.getClient().Title() - items[x]['replace']['Client'] = "%s" % ( obj.getClient().absolute_url(), obj.getClient().Title()) - else: - items[x]['Client'] = '' - - date = obj.Schema().getField('BatchDate').get(obj) - if callable(date): - date = date() - items[x]['BatchDate'] = date - items[x]['replace']['BatchDate'] = self.ulocalized_time(date) - - return items + def folderitem(self, obj, item, index): + """Applies new properties to the item (Batch) that is currently being + rendered as a row in the list + :param obj: client to be rendered as a row in the list + :param item: dict representation of the batch, suitable for the list + :param index: current position of the item within the list + :type obj: ATContentType/DexterityContentType + :type item: dict + :type index: int + :return: the dict representation of the item + :rtype: dict + """ + # TODO This can be done entirely by using brains + full_obj = api.get_object(obj) + bid = full_obj.getId() + item['BatchID'] = bid + item['replace']['BatchID'] = "%s" % ( + item['url'], 'analysisrequests', bid) + + title = full_obj.Title() + item['Title'] = title + item['replace']['Title'] = "%s" % ( + item['url'], 'analysisrequests', title) + item['Client'] = '' + client = full_obj.getClient() + if client: + item['Client'] = client.Title() + item['replace']['Client'] = "%s" % ( + client.absolute_url(), client.Title()) + + # TODO This workaround is necessary? + date = full_obj.Schema().getField('BatchDate').get(obj) + if callable(date): + date = date() + item['BatchDate'] = date + item['replace']['BatchDate'] = self.ulocalized_time(date) + return item class ajaxGetBatches(BrowserView): From ff4a2a55e5314475fd6bf1d607efeb58e9638981 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jordi=20Puiggen=C3=A9?= Date: Thu, 11 Jan 2018 13:02:54 +0100 Subject: [PATCH 2/3] Refactor batches' folderitems to folderitem --- bika/lims/browser/client/views/batches.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bika/lims/browser/client/views/batches.py b/bika/lims/browser/client/views/batches.py index 52702f8c38..fe771b041f 100644 --- a/bika/lims/browser/client/views/batches.py +++ b/bika/lims/browser/client/views/batches.py @@ -7,6 +7,8 @@ from bika.lims.browser.batchfolder import BatchFolderContentsView from Products.CMFCore.utils import getToolByName +from bika.lims.catalog.analysisrequest_catalog import \ + CATALOG_ANALYSIS_REQUEST_LISTING class ClientBatchesView(BatchFolderContentsView): @@ -18,7 +20,7 @@ def __call__(self): return BatchFolderContentsView.__call__(self) def contentsMethod(self, contentFilter): - bc = getToolByName(self.context, "bika_catalog") + bc = getToolByName(self.context, CATALOG_ANALYSIS_REQUEST_LISTING) batches = {} for ar in bc(portal_type='AnalysisRequest', getClientUID=self.context.UID()): From d305136ec461ccd67c1fbd2a790c36ebd3216764 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jordi=20Puiggen=C3=A9?= Date: Thu, 11 Jan 2018 13:04:52 +0100 Subject: [PATCH 3/3] Changelog --- CHANGES.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.rst b/CHANGES.rst index 6760bffdaf..68f20aae4f 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -17,6 +17,7 @@ Changelog **Fixed** +- #562 Client Batch lists are empty - #561 Sampler field is not displayed in Analysis Request Add form - #559 Fix numeric field event handler in bika.lims.site.js - #553 Fixed that images and barcodes were not printed in reports