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

Client Batch lists are empty #562

Merged
merged 3 commits into from
Jan 11, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
81 changes: 45 additions & 36 deletions bika/lims/browser/batchfolder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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'] = "<a href='%s/%s'>%s</a>" % (items[x]['url'], 'analysisrequests', bid)

title = obj.Title()
items[x]['Title'] = title
items[x]['replace']['Title'] = "<a href='%s/%s'>%s</a>" % (items[x]['url'], 'analysisrequests', title)

if obj.getClient():
items[x]['Client'] = obj.getClient().Title()
items[x]['replace']['Client'] = "<a href='%s'>%s</a>" % ( 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'] = "<a href='%s/%s'>%s</a>" % (
item['url'], 'analysisrequests', bid)

title = full_obj.Title()
item['Title'] = title
item['replace']['Title'] = "<a href='%s/%s'>%s</a>" % (
item['url'], 'analysisrequests', title)
item['Client'] = ''
client = full_obj.getClient()
if client:
item['Client'] = client.Title()
item['replace']['Client'] = "<a href='%s'>%s</a>" % (
client.absolute_url(), client.Title())

# TODO This workaround is necessary?
date = full_obj.Schema().getField('BatchDate').get(obj)
if callable(date):
date = date()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just inspected the code and BatchDate is a normal DateTimeField which should have the common Archetypes getters/setters:

    DateTimeField(
        'BatchDate',
        required=False,
        widget=DateTimeWidget(
            label=_('Date'),
        ),
    ),

🤔

item['BatchDate'] = date
item['replace']['BatchDate'] = self.ulocalized_time(date)
return item


class ajaxGetBatches(BrowserView):
Expand Down
4 changes: 3 additions & 1 deletion bika/lims/browser/client/views/batches.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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()):
Expand Down