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
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):
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()):